Пример #1
0
        /// <summary>
        /// Activates an effect by name and brightness. This can be a custom effect (e.g. screen mirror) or a effect available on the Nanoleaf device
        /// First deactivates any custom effects before enabling the new effect
        /// </summary>
        public async Task ActivateEffect(string effectName, int brightness)
        {
            try
            {
                var client = NanoleafClient.GetClientForDevice(Device);

                //DO NOT change the order of disabling effects, then setting brightness and then enabling effects
                if (_customEffects.HasActiveEffects(effectName))
                {
                    await _customEffects.DeactivateAllEffects();
                }

                await client.StateEndpoint.SetBrightnessAsync(brightness);

                if (_customEffects.EffectIsCustomEffect(effectName))
                {
                    var customEffect = _customEffects.GetCustomEffect(effectName);

                    if (!customEffect.IsActive())
                    {
                        await customEffect.Activate();
                    }
                }
                else
                {
                    await client.EffectsEndpoint.SetSelectedEffectAsync(effectName);
                }
            }
            catch (Exception e)
            {
                _logger.Error(e, $"Enabling effect failed for device {Device.Name} with trigger effect {effectName}");
            }
        }
Пример #2
0
        /// <summary>
        /// Activates an effect by name and brightness. This can be a custom effect (e.g. screen mirror) or a effect available on the Nanoleaf device
        /// First deactivates any custom effects before enabling the new effect
        /// </summary>
        public async Task ActivateEffect(string effectName, int brightness)
        {
            _logger.Info($"Orchestrator is activating effect {effectName} with brightness {brightness} for device {Device.IPAddress}");

            try
            {
                var client = NanoleafClient.GetClientForDevice(Device);

                //DO NOT change the order of disabling effects, then setting brightness and then enabling effects
                if (_customEffects.HasActiveEffects(effectName))
                {
                    await _customEffects.DeactivateAllEffects();
                }


                if (_customEffects.EffectIsCustomEffect(effectName))
                {
                    var customEffect = _customEffects.GetCustomEffect(effectName);

                    //Special case: no need to set the brightness if we are turning off the device
                    if (customEffect.GetType() != _turnOffEffectType)
                    {
                        await client.StateEndpoint.SetBrightnessAsync(brightness);
                    }

                    if (!customEffect.IsActive())
                    {
                        await customEffect.Activate();
                    }
                }
                else
                {
                    await client.StateEndpoint.SetBrightnessAsync(brightness);

                    await client.EffectsEndpoint.SetSelectedEffectAsync(effectName);
                }

                //Finally, trigger effect changed callback
                TriggerEffectChangedCallbacks();
            }
            catch (Exception e)
            {
                _logger.Error(e, $"Enabling effect failed for device {Device.Name} with trigger effect {effectName}");
            }
        }