Example #1
0
        public async Task <HueLightInfo> GetLightInfoAsync(int lightId)
        {
            HueLightInfo = await _hueService.GetLightInfoAsync(lightId);

            RaiseOnChangeEvent();

            return(HueLightInfo);
        }
Example #2
0
        public async Task <HueLightInfo> GetLightInfoAsync(int lightId)
        {
            HttpResponseMessage response;

            try
            {
                response = await _httpClient.GetAsync($"http://{_ipAddress}/api/{_userToken}/lights/{lightId}");
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, "Unable to load light state form address {address}.", _ipAddress);
                return(null);
            }

            string stringResponse = await response.Content.ReadAsStringAsync();

            JsonSerializerOptions options = new JsonSerializerOptions()
            {
                PropertyNameCaseInsensitive = true
            };
            HueLightInfo lightInfo = JsonSerializer.Deserialize <HueLightInfo>(stringResponse, options);

            return(lightInfo);
        }