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); } } }
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 SetColor(string color) { if (!string.IsNullOrEmpty(Config.HueApiKey) && !string.IsNullOrEmpty(Config.HueIpAddress) && !string.IsNullOrEmpty(Config.SelectedHueLightId)) { await _hueService.SetColor(color, Config.SelectedHueLightId); } if (Config.IsLIFXEnabled && !string.IsNullOrEmpty(Config.LIFXApiKey)) { await _lifxService.SetColor(color, (Selector)Config.SelectedLIFXItemId); } }
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.HueApiKey) && !string.IsNullOrEmpty(Config.HueIpAddress) && !string.IsNullOrEmpty(Config.SelectedHueLightId)) { await _hueService.SetColor(presence.Availability, Config.SelectedHueLightId); } if (Config.IsLIFXEnabled && !string.IsNullOrEmpty(Config.LIFXApiKey)) { await _lifxService.SetColor(presence.Availability, (Selector)Config.SelectedLIFXItemId); } while (await _userAuthService.IsUserAuthenticated()) { if (_appState.LightMode == "Graph") { token = await _userAuthService.GetAccessToken(); presence = await GetPresence(token); _appState.SetPresence(presence); _logger.LogInformation($"Presence is {presence.Availability}"); if (!string.IsNullOrEmpty(Config.HueApiKey) && !string.IsNullOrEmpty(Config.HueIpAddress) && !string.IsNullOrEmpty(Config.SelectedHueLightId)) { await _hueService.SetColor(presence.Availability, Config.SelectedHueLightId); } if (Config.IsLIFXEnabled && !string.IsNullOrEmpty(Config.LIFXApiKey)) { await _lifxService.SetColor(presence.Availability, (Selector)Config.SelectedLIFXItemId); } } Thread.Sleep(Convert.ToInt32(Config.PollingInterval * 1000)); } _logger.LogInformation("User logged out, no longer polling for presence."); }
public async void UpdateLight(string command) { if (command == "Teams") { _appState.SetLightMode("Graph"); } else { _appState.SetLightMode("Custom"); _appState.SetCustomColor("Offline"); } if (_appState.LightMode == "Custom") { if (!string.IsNullOrEmpty(Config.LightSettings.Hue.HueApiKey) && !string.IsNullOrEmpty(Config.LightSettings.Hue.HueIpAddress) && !string.IsNullOrEmpty(Config.LightSettings.Hue.SelectedHueLightId)) { await _hueService.SetColor(_appState.CustomColor, Config.LightSettings.Hue.SelectedHueLightId); } if (Config.LightSettings.LIFX.IsLIFXEnabled && !string.IsNullOrEmpty(Config.LightSettings.LIFX.LIFXApiKey)) { await _lifxService.SetColor(_appState.CustomColor, (Selector)Config.LightSettings.LIFX.SelectedLIFXItemId); } } }
private async Task <bool> UpdateLights(Schedule schedule) { var _lifxService = new LIFXService(schedule.LIFXApiKey); try { var lights = await _lifxService.GetAllLightsAsync(); var groups = await _lifxService.GetAllGroupsAsync(); if ((groups == null || groups.Count == 0) && (lights == null || lights.Count == 0)) { _logger.LogInformation($"No lights configured for LIFX"); return(true); } foreach (var light in lights) { if ($"id:{light.Id}" == schedule.SelectedLIFXItemId) { _logger.LogInformation($"Ok to Wake {schedule.ScheduleName} Linked to {light.Label}"); } } foreach (var group in groups) { if ($"group_id:{group.Id}" == schedule.SelectedLIFXItemId) { _logger.LogInformation($"Ok to Wake Linked to {group.Label} Group"); } } } catch (Exception e) { _logger.LogError(e.Message); } try { foreach (TimeInterval interval in schedule.TimeIntervals) { if (IsInRange(interval.TimeIntervalStartAsDate.TimeOfDay.ToString(), interval.TimeIntervalEndAsDate.TimeOfDay.ToString())) { await _lifxService.SetColor(interval.TimeColor, schedule.Brightness, (Selector)schedule.SelectedLIFXItemId); _logger.LogInformation($"Scedule: {schedule.ScheduleName} Current time is : {DateTime.Now.ToShortDateString()} {DateTime.Now.ToShortTimeString()}, interval: {interval.TimeIntervalName}, range: {interval.TimeIntervalStartAsDate.TimeOfDay.ToString()} - {interval.TimeIntervalEndAsDate.TimeOfDay.ToString()}, light updated to {interval.TimeColor}"); return(true); } } } catch (Exception e) { _logger.LogError(e.Message); } return(true); }
public async Task <ActionResult> ProcessAlexaRequest([FromBody] SkillRequest request) { var requestType = request.GetRequestType(); SkillResponse response = null; if (requestType == typeof(LaunchRequest)) { response = ResponseBuilder.Tell("Welcome to Presence Light!"); response.Response.ShouldEndSession = false; } else if (requestType == typeof(IntentRequest)) { var intentRequest = request.Request as IntentRequest; if (intentRequest.Intent.Name == "Teams") { _appState.SetLightMode("Graph"); response = ResponseBuilder.Tell("Presence Light set to Teams!"); } else if (intentRequest.Intent.Name == "Custom") { _appState.SetLightMode("Custom"); _appState.SetCustomColor("#FFFFFF"); response = ResponseBuilder.Tell("Presence Light set to custom!"); } if (_appState.LightMode == "Custom") { if (!string.IsNullOrEmpty(Config.LightSettings.Hue.HueApiKey) && !string.IsNullOrEmpty(Config.LightSettings.Hue.HueIpAddress) && !string.IsNullOrEmpty(Config.LightSettings.Hue.SelectedHueLightId)) { await _hueService.SetColor(_appState.CustomColor, Config.LightSettings.Hue.SelectedHueLightId); } if (Config.LightSettings.LIFX.IsLIFXEnabled && !string.IsNullOrEmpty(Config.LightSettings.LIFX.LIFXApiKey)) { await _lifxService.SetColor(_appState.CustomColor, Config.LightSettings.LIFX.SelectedLIFXItemId); } } } return(new OkObjectResult(response)); }
private async Task CallGraph() { if (_graphServiceClient == null) { _graphServiceClient = _graphservice.GetAuthenticatedGraphClient(typeof(WPFAuthorizationProvider)); } stopThemePolling = true; stopGraphPolling = false; signInPanel.Visibility = Visibility.Collapsed; lblTheme.Visibility = Visibility.Collapsed; loadingPanel.Visibility = Visibility.Visible; var(profile, presence) = await System.Threading.Tasks.Task.Run(() => GetBatchContent()); var photo = await System.Threading.Tasks.Task.Run(() => GetPhoto()); if (photo == null) { MapUI(presence, profile, new BitmapImage(new Uri("pack://application:,,,/PresenceLight;component/images/UnknownProfile.png"))); } else { MapUI(presence, profile, LoadImage(photo)); } if (!string.IsNullOrEmpty(Config.HueApiKey) && !string.IsNullOrEmpty(Config.HueIpAddress) && !string.IsNullOrEmpty(Config.SelectedHueLightId)) { await _hueService.SetColor(presence.Availability, Config.SelectedHueLightId); } if (Config.IsLIFXEnabled && !string.IsNullOrEmpty(Config.LIFXApiKey)) { await _lifxService.SetColor(presence.Availability, (Selector)Config.SelectedLIFXItemId); } loadingPanel.Visibility = Visibility.Collapsed; this.signInPanel.Visibility = Visibility.Collapsed; hueIpAddress.IsEnabled = false; dataPanel.Visibility = Visibility.Visible; await SettingsService.SaveSettings(Config); while (true) { if (stopGraphPolling) { stopGraphPolling = false; notificationIcon.Text = PresenceConstants.Inactive; notificationIcon.Icon = new BitmapImage(new Uri(IconConstants.GetIcon(String.Empty, IconConstants.Inactive))); return; } await Task.Delay(Convert.ToInt32(Config.PollingInterval * 1000)); try { presence = await System.Threading.Tasks.Task.Run(() => GetPresence()); if (!string.IsNullOrEmpty(Config.HueApiKey) && !string.IsNullOrEmpty(Config.HueIpAddress) && !string.IsNullOrEmpty(Config.SelectedHueLightId)) { await _hueService.SetColor(presence.Availability, Config.SelectedHueLightId); } if (Config.IsLIFXEnabled && !string.IsNullOrEmpty(Config.LIFXApiKey)) { await _lifxService.SetColor(presence.Availability, (Selector)Config.SelectedLIFXItemId); } MapUI(presence, null, null); } catch { } } }
public async Task <Unit> Handle(SetColorCommand command, CancellationToken cancellationToken) { await _service.SetColor(command.Availability, command.Activity, command.LightId, command.ApiKey); return(default);