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."); }
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."); }