private async Task ChangeState(LifxHttpLight light, object payload)
 {
     var client = new RestClient(BaseUrl);
     var request = new RestRequest($"v1/lights/{light.Id}/state");
     request.AddHeader("Authorization", $"Bearer {_token}");
     request.AddJsonBody(payload);
     await client.PutTaskAsync<object>(request);
 }
Пример #2
0
        private async Task ChangeState(LifxHttpLight light, object payload)
        {
            var client  = new RestClient(BaseUrl);
            var request = new RestRequest($"v1/lights/{light.Id}/state");

            request.AddHeader("Authorization", $"Bearer {_token}");
            request.AddJsonBody(payload);
            await client.PutTaskAsync <object>(request);
        }
        private void UpdateDeviceVariables(LifxDevice device, LifxHttpLight light)
        {
            var brightness  = Math.Round(light.Brightness, 2);
            var groupName   = light.Group.Name;
            var name        = light.Label;
            var isOn        = light.Power == LifxHttpLight.PowerState.On;
            var isConnected = light.IsConnected;
            var color       = light.GetHexColor();

            _messageQueue.Publish(new UpdateVariableMessage(Name, device.Id, "Brightness", brightness));
            _messageQueue.Publish(new UpdateVariableMessage(Name, device.Id, "IsOn", isOn));
            _messageQueue.Publish(new UpdateVariableMessage(Name, device.Id, "IsConnected", isConnected));
            _messageQueue.Publish(new UpdateVariableMessage(Name, device.Id, "Name", name));
            _messageQueue.Publish(new UpdateVariableMessage(Name, device.Id, "GroupName", groupName));
            _messageQueue.Publish(new UpdateVariableMessage(Name, device.Id, "Color", color));
        }
        private void UpdateDeviceVariables(LifxDevice device, LifxHttpLight light)
        {
            var brightness = Math.Round(light.Brightness, 2);
            var groupName = light.Group.Name;
            var name = light.Label;
            var isOn = light.Power == LifxHttpLight.PowerState.On;
            var isConnected = light.IsConnected;
            var color = light.GetHexColor();

            _messageQueue.Publish(new UpdateVariableMessage(Name, device.Id, "Brightness", brightness));
            _messageQueue.Publish(new UpdateVariableMessage(Name, device.Id, "IsOn", isOn));
            _messageQueue.Publish(new UpdateVariableMessage(Name, device.Id, "IsConnected", isConnected));
            _messageQueue.Publish(new UpdateVariableMessage(Name, device.Id, "Name", name));
            _messageQueue.Publish(new UpdateVariableMessage(Name, device.Id, "GroupName", groupName));
            _messageQueue.Publish(new UpdateVariableMessage(Name, device.Id, "Color", color));
        }
Пример #5
0
 internal LifxDevice(LifxHttpLight light)
 {
     Id     = light.Id;
     Name   = light.Label;
     Source = LifxSource.Cloud;
 }
 public async Task ChangeColor(LifxHttpLight light, string hexColor, int durationInSeconds)
 {
     await ChangeState(light, new {power = "on", color = hexColor, duration = durationInSeconds});
 }
 public async Task ChangeBrightness(LifxHttpLight light, double brightness, int durationInSeconds)
 {
     await ChangeState(light, new {power = "on", brightness = brightness, duration = durationInSeconds});
 }
 public async Task SwitchOff(LifxHttpLight light, int durationInSeconds = 0)
 {
     await ChangeState(light, new {power = "off", duration = durationInSeconds});
 }
 internal LifxDevice(LifxHttpLight light)
 {
     Id = light.Id;
     Name = light.Label;
     Source = LifxSource.Cloud;
 }
Пример #10
0
 public async Task ChangeColor(LifxHttpLight light, string hexColor, int durationInSeconds)
 {
     await ChangeState(light, new { power = "on", color = hexColor, duration = durationInSeconds });
 }
Пример #11
0
 public async Task ChangeBrightness(LifxHttpLight light, double brightness, int durationInSeconds)
 {
     await ChangeState(light, new { power = "on", brightness = brightness, duration = durationInSeconds });
 }
Пример #12
0
 public async Task SwitchOff(LifxHttpLight light, int durationInSeconds = 0)
 {
     await ChangeState(light, new { power = "off", duration = durationInSeconds });
 }