private async Task SetOperationMode() { var orchestrator = OrchestratorCollection.GetOrchestratorForDevice(_device); if (_activeTriggersPriorities.Any()) { var lowestPriority = _activeTriggersPriorities.Min(); if (ActiveTrigger == null || ActiveTrigger.Priority != lowestPriority) { //Event operation mode is already active or we try to activate it (can fail if the user has manual enabled) var eventOperationModeActive = orchestrator.Device.OperationMode == OperationMode.Event || await orchestrator.TrySetOperationMode(OperationMode.Event); if (eventOperationModeActive) { //A trigger has been activated or deactivated and the current active trigger is no longer the trigger with the highest priority (priority 1 is highest) ActiveTrigger = _eventTriggers.FirstOrDefault(eventTrigger => eventTrigger.Priority == lowestPriority); await orchestrator.ActivateEffect(ActiveTrigger.EffectName, ActiveTrigger.Brightness); _logger.Info($"Process event started with effect {ActiveTrigger.EffectName} with brightness {ActiveTrigger.Brightness} for device {_device.IPAddress}"); } } } else if (orchestrator.Device.OperationMode == OperationMode.Event) //Only go back to schedule if the current devices operation mode is event { //Let orchestrator know that all events have stopped so it can continue with normal program, will not fail since an event can only be activated when no override is active //Always return to schedule since only 1 event can be active at a time ActiveTrigger = null; await orchestrator.TrySetOperationMode(OperationMode.Schedule); _logger.Info($"Stopped all process events for device {_device.IPAddress}"); } }
public void StopAllEvents() { ActiveTrigger = null; _activeTriggersPriorities.Clear(); //Stop all events such that the timers get disposed correctly foreach (var eventTrigger in _eventTriggers) { eventTrigger.Stop(); } }