Beispiel #1
0
        public async Task SetLightStateAsync(int lightId, LightState lightState)
        {
            bool setLightResponse = await _hueService.SetLightStateAsync(lightId, lightState);

            if (setLightResponse)
            {
                await GetLightInfoAsync(lightId);
            }
        }
Beispiel #2
0
        public async Task <bool> SetLightStateAsync(int lightId, LightState lightState)
        {
            _logger.LogInformation("Turning light {lightId} on: {isOn}", lightId, lightState.on);

            HttpResponseMessage response = await _httpClient.PutAsync($"http://{_ipAddress}/api/{_userToken}/lights/{lightId}/state",
                                                                      new StringContent(JsonSerializer.Serialize(lightState), Encoding.UTF8, "application/json"));

            LightStateChanged?.Invoke(this, new LightStateChangedEventArgs());

            return(response.IsSuccessStatusCode);
        }