Exemple #1
0
        public async Task SetColor(string color, string?activity = null)
        {
            try
            {
                if (!string.IsNullOrEmpty(Config.LightSettings.Hue.HueApiKey) && !string.IsNullOrEmpty(Config.LightSettings.Hue.HueIpAddress) && !string.IsNullOrEmpty(Config.LightSettings.Hue.SelectedHueLightId))
                {
                    if (Config.LightSettings.Hue.UseRemoteApi)
                    {
                        if (!string.IsNullOrEmpty(Config.LightSettings.Hue.RemoteBridgeId))
                        {
                            await _remoteHueService.SetColor(color, Config.LightSettings.Hue.SelectedHueLightId, Config.LightSettings.Hue.RemoteBridgeId).ConfigureAwait(true);
                        }
                    }
                    else
                    {
                        await _hueService.SetColor(color, Config.LightSettings.Hue.SelectedHueLightId).ConfigureAwait(true);
                    }
                }

                if (Config.LightSettings.LIFX.IsLIFXEnabled && !string.IsNullOrEmpty(Config.LightSettings.LIFX.LIFXApiKey))
                {
                    await _lifxService.SetColor(color, Config.LightSettings.LIFX.SelectedLIFXItemId).ConfigureAwait(true);
                }

                if (Config.LightSettings.Yeelight.IsYeelightEnabled && !string.IsNullOrEmpty(Config.LightSettings.Yeelight.SelectedYeelightId))
                {
                    await _yeelightService.SetColor(color, Config.LightSettings.Yeelight.SelectedYeelightId).ConfigureAwait(true);
                }

                if (Config.LightSettings.Custom.IsCustomApiEnabled)
                {
                    string response = await _customApiService.SetColor(color, activity).ConfigureAwait(true);

                    customApiLastResponse.Content = response;
                    if (response.Contains("Error:", StringComparison.OrdinalIgnoreCase))
                    {
                        customApiLastResponse.Foreground = new SolidColorBrush(Colors.Red);
                    }
                    else
                    {
                        customApiLastResponse.Foreground = new SolidColorBrush(Colors.Green);
                    }
                }
            }
            catch (Exception e)
            {
                _logger.LogError(e, "Error Occured in SetColor MainWindow");
                _diagClient.TrackException(e);
                throw;
            }
        }
Exemple #2
0
        public async Task <Unit> Handle(SetColorCommand command, CancellationToken cancellationToken)
        {
            await _service.SetColor(command.Availability, command.LightId, command.BridgeId);

            return(default);