public async Task SetColor(string color, string?activity = null) { if (!string.IsNullOrEmpty(Config.LightSettings.Hue.HueApiKey) && !string.IsNullOrEmpty(Config.LightSettings.Hue.HueIpAddress) && !string.IsNullOrEmpty(Config.LightSettings.Hue.SelectedHueLightId)) { await _hueService.SetColor(color, Config.LightSettings.Hue.SelectedHueLightId); } if (Config.LightSettings.LIFX.IsLIFXEnabled && !string.IsNullOrEmpty(Config.LightSettings.LIFX.LIFXApiKey)) { await _lifxService.SetColor(color, (Selector)Config.LightSettings.LIFX.SelectedLIFXItemId); } if (Config.LightSettings.Yeelight.IsYeelightEnabled && !string.IsNullOrEmpty(Config.LightSettings.Yeelight.SelectedYeelightId)) { await _yeelightService.SetColor(color, Config.LightSettings.Yeelight.SelectedYeelightId); } if (Config.LightSettings.Custom.IsCustomApiEnabled) { string response = await _customApiService.SetColor(color, activity); customApiLastResponse.Content = response; if (response.Contains("Error:")) { customApiLastResponse.Foreground = new SolidColorBrush(Colors.Red); } else { customApiLastResponse.Foreground = new SolidColorBrush(Colors.Green); } } }
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; } }
private async Task GetData() { var token = await _userAuthService.GetAccessToken(); var user = await GetUserInformation(token); var photo = await GetPhotoAsBase64Async(token); var presence = await GetPresence(token); _appState.SetUserInfo(user, photo, presence); if (!string.IsNullOrEmpty(Config.LightSettings.Hue.HueApiKey) && !string.IsNullOrEmpty(Config.LightSettings.Hue.HueIpAddress) && !string.IsNullOrEmpty(Config.LightSettings.Hue.SelectedHueLightId)) { await _hueService.SetColor(presence.Availability, Config.LightSettings.Hue.SelectedHueLightId); } if (Config.LightSettings.LIFX.IsLIFXEnabled && !string.IsNullOrEmpty(Config.LightSettings.LIFX.LIFXApiKey)) { await _lifxService.SetColor(presence.Availability, (Selector)Config.LightSettings.LIFX.SelectedLIFXItemId); } string availability = string.Empty; while (await _userAuthService.IsUserAuthenticated()) { if (_appState.LightMode == "Graph") { token = await _userAuthService.GetAccessToken(); presence = await GetPresence(token); if (presence.Availability != availability) { _appState.SetPresence(presence); _logger.LogInformation($"Presence is {presence.Availability}"); if (!string.IsNullOrEmpty(Config.LightSettings.Hue.HueApiKey) && !string.IsNullOrEmpty(Config.LightSettings.Hue.HueIpAddress) && !string.IsNullOrEmpty(Config.LightSettings.Hue.SelectedHueLightId)) { await _hueService.SetColor(presence.Availability, Config.LightSettings.Hue.SelectedHueLightId); } if (Config.LightSettings.LIFX.IsLIFXEnabled && !string.IsNullOrEmpty(Config.LightSettings.LIFX.LIFXApiKey)) { await _lifxService.SetColor(presence.Availability, (Selector)Config.LightSettings.LIFX.SelectedLIFXItemId); } } if (Config.LightSettings.Custom.IsCustomApiEnabled) { // passing the data on only when it changed is handled within the custom api service await _customApiService.SetColor(presence.Availability, presence.Activity); } } availability = presence.Availability; Thread.Sleep(Convert.ToInt32(Config.LightSettings.PollingInterval * 1000)); } _logger.LogInformation("User logged out, no longer polling for presence."); }
public async Task <string> Handle(SetColorCommand command, CancellationToken cancellationToken) { return(await _service.SetColor(command.Availability, command.Activity, cancellationToken)); }