private void HandleIsEnabledStateChanged() { _autoEnableAction?.Cancel(); if (!Settings.IsEnabled) { _autoEnableAction = ScheduledAction.Schedule(Settings.AutoEnableAfter, () => _settingsService.SetComponentEnabledState(this, true)); } }
public void Schedule(IScheduledAction action) { if (ChatClients is null) { throw new InvalidDataException("Chat clients property is not set!");; } switch (action) { case DelayedMessage delayedMsg: var msg = delayedMsg.Message; var chnl = delayedMsg.Channel; foreach (var chatClient in ChatClients) { if (!string.IsNullOrWhiteSpace(chnl)) { BackgroundJob.Schedule(() => chatClient.PostMessage(chnl, msg), delayedMsg.Delay); } else { BackgroundJob.Schedule(() => chatClient.PostMessage(chatClient.DefaultChannel, msg), delayedMsg.Delay); } } break; case RepeatingMessage repeatingMsg: var message = repeatingMsg.Message; var channel = repeatingMsg.Channel; var i = 0; foreach (var chatClient in ChatClients) { if (!string.IsNullOrWhiteSpace(channel)) { RecurringJob.AddOrUpdate( repeatingMsg.Name + $"-{i}", () => chatClient.PostMessage(channel, message), Cron.MinuteInterval(repeatingMsg.IntervalInMinutes)); } else { RecurringJob.AddOrUpdate( repeatingMsg.Name + $"-{i}", () => chatClient.PostMessage(chatClient.DefaultChannel, message), Cron.MinuteInterval(repeatingMsg.IntervalInMinutes)); } i++; } break; } }
private void StartTimeout() { lock (_syncRoot) { if (!GetConditionsAreFulfilled()) { return; } _turnOffTimeout?.Cancel(); _turnOffTimeout = ScheduledAction.Schedule(Settings.Duration, TurnOff); } }
private void StartTimeout() { _delayedAction?.Cancel(); _delayedAction = ScheduledAction.Schedule(Settings.SlowDuration, () => { if (_fan.GetFeatures().Extract <LevelFeature>().MaxLevel > 1) { _fan.TrySetLevel(2); _delayedAction = ScheduledAction.Schedule(Settings.FastDuration, () => _fan.TryTurnOff()); } else { _fan.TryTurnOff(); } }); }
private void StartBathode(IArea bathroom) { var motionDetector = bathroom.GetMotionDetector(LowerBathroom.MotionDetector); _settingsService.SetComponentEnabledState(motionDetector, false); bathroom.GetLamp(LowerBathroom.LightCeilingDoor).TryTurnOn(); bathroom.GetLamp(LowerBathroom.LightCeilingMiddle).TryTurnOff(); bathroom.GetLamp(LowerBathroom.LightCeilingWindow).TryTurnOff(); bathroom.GetLamp(LowerBathroom.LampMirror).TryTurnOff(); _bathmodeResetDelayedAction?.Cancel(); _bathmodeResetDelayedAction = ScheduledAction.Schedule(TimeSpan.FromHours(1), () => { bathroom.GetLamp(LowerBathroom.LightCeilingDoor).TryTurnOff(); _settingsService.SetComponentEnabledState(motionDetector, true); }); }