Example #1
0
    public async Task UpdateSchedule()
    {
      Schedule schedule = new Schedule();
      schedule.Name = "t1";
      schedule.Description = "test";
      schedule.LocalTime = new HueDateTime
			{
				DateTime = DateTime.UtcNow.AddDays(1)
			};
      schedule.Command = new InternalBridgeCommand();
      var commandBody = new LightCommand();
      commandBody.Alert = Alert.Once;
      schedule.Command.Body = commandBody;
      schedule.Command.Address = "/api/huelandspoor/lights/5/state";
      schedule.Command.Method = HttpMethod.Put;

      var scheduleId = await _client.CreateScheduleAsync(schedule);

      //Update name
      schedule.Name = "t2";
      await _client.UpdateScheduleAsync(scheduleId, schedule);

      //Get saved schedule
      var savedSchedule = await _client.GetScheduleAsync(scheduleId);

      //Check 
      Assert.AreEqual(schedule.Name, savedSchedule.Name);

    }
Example #2
0
 private void QueueCommand(string commandType, LightCommand cmd)
 {
     if (_commandQueue.ContainsKey(commandType))
     {
         //replace with most recent
         _commandQueue[commandType] = cmd;
     }
     else
     {
         _commandQueue.Add(commandType, cmd);
     }
 }
 public void ExecuteInstantaneousCommand(LightCommand command)
 {
     if (command.Brightness != null)
     {
         this.ExpectedLight.Brightness = (byte)command.Brightness;
     }
     else
     {
         this.ExpectedLight.Brightness = this.NetworkLight.Brightness;
     }
     ChangeColour(command);
 }
Example #4
0
        public void AlertLights(string bulbID = "", Action callbackMethod = null)
        {
            try
            {
                Task flashLightsTask = new Task(async() =>
                {
                    if ((hueClient != null) &&
                        (await hueClient.CheckConnection() == true))
                    {
                        if (colorBulbs.Count > 0)
                        {
                            List <string> bulbIDs     = new List <string>();
                            LightCommand lightCommand = new LightCommand();

                            if (bulbID == string.Empty)
                            {
                                for (int i = 0; i < colorBulbs.Count; i++)
                                {
                                    bulbIDs.Add(colorBulbs[i].Id);
                                }
                            }
                            else
                            {
                                bulbIDs.Add(bulbID);
                            }

                            lightCommand.TurnOn();

                            lightCommand.Alert = Alert.Multiple;

                            await hueClient.SendCommandAsync(lightCommand, bulbIDs);
                        }

                        callbackMethod?.Invoke();
                    }
                    else
                    {
                        errorLog += "\r\n\r\n" + DateTime.Now.ToString() + ": Philips Hue bridge is not connected.";

                        callbackMethod?.Invoke();
                    }
                });

                flashLightsTask.Start();
            }
            catch (Exception lightEffectException)
            {
                errorLog += "\r\n\r\n" + DateTime.Now.ToString() + ": " + lightEffectException;

                callbackMethod?.Invoke();
            }
        }
Example #5
0
 private async void ColorButton_ClickAsync(object sender, RoutedEventArgs e)
 {
     Light        light   = (Light)LightListView.SelectedItem;
     LightCommand command = new LightCommand()
     {
         Hue        = model.Hue,
         Saturation = model.Saturation,
         Brightness = model.Brightness
     };
     await client.SendCommandAsync(command, new List <string> {
         light.Id
     });
 }
Example #6
0
        private async void SetHexColor(string hex)
        {
            if (await client.CheckConnection() == true)
            {
                var command = new LightCommand();
                command.SetColor(new RGBColor(hex));
                Q42.HueApi.Models.Groups.Group selectedGroup = getSelectedGroup();

                await client.SendCommandAsync(command, selectedGroup.Lights);

                logEvent("Setting Lights to " + hex, true);
            }
        }
Example #7
0
 public async Task TurnOnLight(RGBColor RgbColor, byte Brightness, List <string> lights)
 {
     try
     {
         var command = new LightCommand();
         command.TurnOn().SetColor(RgbColor);
         command.Brightness = Brightness;
         await client.SendCommandAsync(command, lights);
     }
     catch
     {
     }
 }
Example #8
0
        public Task AlertAsync(string color, double brightness = 100)
        {
            var command = new LightCommand();

            command.Brightness = (byte)(brightness / 100F * 255);
            command.TurnOn().SetColor(new RGBColor(color));
            command.Alert = Alert.Multiple;

            // Or start a colorloop
            //command.Effect = Effect.ColorLoop;

            return(SendCommandAsync(command));
        }
Example #9
0
        private async void DoBlink()
        {
            if (await client.CheckConnection() == true)
            {
                var command = new LightCommand();
                command.Alert = Alert.Multiple;
                Q42.HueApi.Models.Groups.Group selectedGroup = getSelectedGroup();

                await client.SendCommandAsync(command, selectedGroup.Lights);

                logEvent("Doing a Blink", true);
            }
        }
Example #10
0
        public static async Task SendLightsCommands(LightCommand command, IList <string> lights = null)
        {
            ILocalHueClient client = new LocalHueClient(AppSettings.Instance.DeviceIPAddress, AppSettings.Instance.UserKey);

            if (lights == null)
            {
                await client.SendCommandAsync(command);
            }
            else
            {
                await client.SendCommandAsync(command, lights);
            }
        }
Example #11
0
        private void TurnHeaterOnOff(bool on)
        {
            LightCommand lightCommand = new LightCommand()
            {
                On = on
            };

            client.SendCommandAsync(lightCommand, new List <string> {
                aquariumHeater.Id
            });

            ConsoleEx.WriteLineWithDate($"Heater {(on ? "on" : "off")}!");
        }
Example #12
0
        private async Task <(string color, LightCommand command, bool returnFunc)> Handle(string presence, string lightId)
        {
            var props = _options.LightSettings.Hue.Statuses.GetType().GetProperties().ToList();

            if (_options.LightSettings.Hue.UseActivityStatus)
            {
                props = props.Where(a => a.Name.ToLower().StartsWith("activity")).ToList();
            }
            else
            {
                props = props.Where(a => a.Name.ToLower().StartsWith("availability")).ToList();
            }

            string color = "";
            string message;
            var    command = new LightCommand();

            foreach (var prop in props)
            {
                if (presence == prop.Name.Replace("Status", "").Replace("Availability", "").Replace("Activity", ""))
                {
                    var value = (AvailabilityStatus)prop.GetValue(_options.LightSettings.Hue.Statuses);

                    if (!value.Disabled)
                    {
                        command.On = true;
                        color      = value.Colour;
                        return(color, command, false);
                    }
                    else
                    {
                        command.On = false;

                        if (lightId.Contains("group_id:"))
                        {
                            await _client.SendGroupCommandAsync(command, lightId.Replace("group_id:", ""));
                        }
                        else
                        {
                            await _client.SendCommandAsync(command, new List <string> {
                                lightId.Replace("id:", "")
                            });
                        }
                        message = $"Turning Hue Light {lightId} Off";
                        _logger.LogInformation(message);
                        return(color, command, true);
                    }
                }
            }
            return(color, command, false);
        }
Example #13
0
 public async Task SetAllToColor(string hexColor)
 {
     try
     {
         var lightCommand = new LightCommand().TurnOn().SetColor(new RGBColor(hexColor));
         var hueResults   = await _client.SendCommandAsync(lightCommand, new List <string> {
             "5", "6"
         });
     }
     catch (Exception e)
     {
         Console.WriteLine("Hue error: " + e);
     }
 }
Example #14
0
        public async Task SetToColor(string hexColor)
        {
            try
            {
                var lightCommand = new LightCommand().TurnOn().SetColor(new RGBColor(hexColor));
                var lights       = await _client.GetLightsAsync();

                var hueResults = await _client.SendCommandAsync(lightCommand, lights.Select(l => l.Id));
            }
            catch (Exception e)
            {
                Console.WriteLine("Hue error: " + e);
            }
        }
Example #15
0
        internal static async void SetOn(Light light, bool value)
        {
            var cmd = new LightCommand();

            if (value == true)
            {
                cmd.TurnOn();
            }
            else
            {
                cmd.TurnOff();
            }
            await SendCommand(cmd, light.Id);
        }
        public Task <HueResults> SendCommandAsync(LightCommand command, string specifiedLight)
        {
            if (command == null)
            {
                throw new ArgumentNullException(nameof(command));
            }

            string jsonCommand = JsonConvert.SerializeObject(command, new JsonSerializerSettings()
            {
                NullValueHandling = NullValueHandling.Ignore
            });

            return(SendCommandRawAsync(jsonCommand, specifiedLight));
        }
Example #17
0
 public void ExecuteCommand(LightCommand command, DateTime currentTime)
 {
     if (this.AppControlState != LightControlState.HueShift) throw new InvalidOperationException();
     if (command.TransitionTime != null)
     {
         this.PowerState = LightPowerState.Transitioning;
         this.Transition = new Transition(currentTime, ((TimeSpan)command.TransitionTime));
     }
     else
     {
         this.PowerState = LightPowerState.On;
     }
     ExecuteInstantaneousCommand(command);
 }
Example #18
0
    private void SendConfigurationRequest()
    {
        LightCommand cmd = new LightCommand
        {
            action = "getConfiguration"
        };

        StartCoroutine(SendCommand(cmd, (body) =>
        {
            ServerSmartPlugConfiguration conf = JsonUtility.FromJson <ServerSmartPlugConfiguration>(body);
            Lights.Clear();
            Lights.AddRange(conf.configuration);
        }));
    }
Example #19
0
    public async Task SendCommandAsync()
    {
      //Create command
      var command = new LightCommand();
      command.TurnOn();
      command.SetColor("#225566");

      List<string> lights = new List<string>();

      //Send Command
      await _client.SendCommandAsync(command);
      await _client.SendCommandAsync(command, lights);

    }
Example #20
0
        public static void HUEOff()
        {
            if (client == null)
            {
                return;
            }

            var command = new LightCommand();

            command.On             = false;
            command.TransitionTime = TimeSpan.FromMilliseconds(0);

            client.SendCommandAsync(command);
        }
Example #21
0
        /// <summary>
        /// Send a lightCommand to a list of lights
        /// </summary>
        /// <param name="command"></param>
        /// <param name="lightList">if null, send command to all lights</param>
        /// <returns></returns>
        public Task <DeConzResults> SendCommandAsync(LightCommand command, IEnumerable <string> lightList = null)
        {
            if (command == null)
            {
                throw new ArgumentNullException(nameof(command));
            }

            string jsonCommand = JsonConvert.SerializeObject(command, new JsonSerializerSettings()
            {
                NullValueHandling = NullValueHandling.Ignore
            });

            return(SendCommandRawAsync(jsonCommand, lightList));
        }
Example #22
0
        private async void button6_Click(object sender, EventArgs e)
        {
            // Blink
            if (await client.CheckConnection() == true)
            {
                var command = new LightCommand();
                command.Alert = Alert.Multiple;
                Q42.HueApi.Models.Groups.Group selectedGroup = getSelectedGroup();

                await client.SendCommandAsync(command, selectedGroup.Lights);

                logEvent("Blinked Lights via UI", true);
            }
        }
Example #23
0
        private async void button9_Click(object sender, EventArgs e)
        {
            // Lights Off
            if (await client.CheckConnection() == true)
            {
                var command = new LightCommand();
                command.TurnOff();
                Q42.HueApi.Models.Groups.Group selectedGroup = getSelectedGroup();

                await client.SendCommandAsync(command, selectedGroup.Lights);

                logEvent("Turned Off Lights via UI", true);
            }
        }
Example #24
0
        public async Task SetLightStateAsync(SetLightStateRequest request)
        {
            var client = await GetClientAsync();

            var command = new LightCommand
            {
                On             = request.PowerState,
                TransitionTime = request.TransitionTime ?? Config.TransitionTime,
                Brightness     = request.Brightness ?? 255
            };

            // TODO: Investigate the results to see what decent info could be returned e.g. errors
            await client.SendCommandAsync(command, request.LightIds);
        }
Example #25
0
        public async Task SetColor(string availability, string lightId)
        {
            _client = new LocalHueClient(_options.HueIpAddress);
            _client.Initialize(_options.HueApiKey);

            var command = new LightCommand
            {
                On = true
            };

            switch (availability)
            {
            case "Available":
                command.SetColor(new RGBColor("#009933"));
                break;

            case "Busy":
                command.SetColor(new RGBColor("#ff3300"));
                break;

            case "BeRightBack":
                command.SetColor(new RGBColor("#ffff00"));
                break;

            case "Away":
                command.SetColor(new RGBColor("#ffff00"));
                break;

            case "DoNotDisturb":
                command.SetColor(new RGBColor("#800000"));
                break;

            case "Offline":
                command.SetColor(new RGBColor("#FFFFFF"));
                break;

            case "Off":
                command.SetColor(new RGBColor("#FFFFFF"));
                break;

            default:
                command.SetColor(new RGBColor(availability));
                break;
            }

            await _client.SendCommandAsync(command, new List <string> {
                lightId
            });
        }
Example #26
0
        static void UpdateHue(ILocalHueClient hue, Color c1, Color c2, Color c3, Color c4)
        {
            do
            {
                c1 = backIOColor;

                var com1 = new LightCommand();
                com1.TransitionTime = TimeSpan.FromMilliseconds(150);
                com1.SetColor(new RGBColor(c1.R, c1.G, c1.B));

                var send1 = hue.SendCommandAsync(com1, new List <string> {
                    "1"
                });
                System.Threading.Thread.Sleep(75);

                c2 = headerTwoColor;

                var com2 = new LightCommand();
                com2.TransitionTime = TimeSpan.FromMilliseconds(150);
                com2.SetColor(new RGBColor(c2.R, c2.G, c2.B));

                var send2 = hue.SendCommandAsync(com2, new List <string> {
                    "2"
                });
                System.Threading.Thread.Sleep(75);

                c3 = pchColor;

                var com3 = new LightCommand();
                com3.TransitionTime = TimeSpan.FromMilliseconds(150);
                com3.SetColor(new RGBColor(c3.R, c3.G, c3.B));

                var send3 = hue.SendCommandAsync(com3, new List <string> {
                    "3"
                });
                System.Threading.Thread.Sleep(75);

                c4 = headerOneColor;

                var com4 = new LightCommand();
                com4.TransitionTime = TimeSpan.FromMilliseconds(150);
                com4.SetColor(new RGBColor(c4.R, c4.G, c4.B));

                var send4 = hue.SendCommandAsync(com4, new List <string> {
                    "4"
                });
                System.Threading.Thread.Sleep(75);
            } while (running);
        }
        public async Task SendCommand(string color)
        {
            var command = new LightCommand();

            if (color == "000000")
            {
                command.TurnOff();
            }
            else
            {
                command.TurnOn().SetColor(new RGBColor(color));
            }

            await BridgeConnecter.getClient().SendCommandAsync(command);
        }
        private async void allLightsOn()
        {
            var command = new LightCommand();

            command.On         = true;
            command.Brightness = 254; // to avoid switching on and still see nothing
            HueResults results = await client.SendCommandAsync(command);

            statusLabel.Text = gatherResults(results);
            foreach (System.Windows.Forms.Control control in flowLayoutPanel.Controls)
            {
                LightControl lc = (LightControl)control;
                lc.Resync();
            }
        }
Example #29
0
        public static async Task BombExplode()
        {
            ILocalHueClient client = new LocalHueClient("192.168.1.104");

            client.Initialize("7R70D9970VOrmdffj3qwNgUBpNwu4d7I12IZKTqj");
            var command = new LightCommand();

            command.TurnOn().SetColor(new RGBColor("FFA500"));

            command.Alert = Alert.None;

            await client.SendCommandAsync(command);

            Thread.Sleep(10000);
        }
Example #30
0
        public static LightCommand SetColor(this LightCommand lightCommand, RGBColor color)
        {
            if (lightCommand == null)
            {
                throw new ArgumentNullException(nameof(lightCommand));
            }

            var hsb = color.GetHSB();

            lightCommand.Brightness = (byte)hsb.Brightness;
            lightCommand.Hue        = hsb.Hue;
            lightCommand.Saturation = hsb.Saturation;

            return(lightCommand);
        }
 private async void trackBarHue_ValueChanged(object sender, EventArgs e)
 {
     if ((client != null) && (light != null))
     {
         try
         {
             LightCommand cmd = new LightCommand();
             cmd.Hue = (int)trackBarHue.Value;
             await client.SendCommandAsync(cmd, new List <string> {
                 light.Id
             });
         }
         catch (Q42.HueApi.HueException) { }
     }
 }
Example #32
0
        public async Task SendCommandAsync()
        {
            //Create command
            var command = new LightCommand();

            command.TurnOn();
            command.SetColor("#225566");

            List <string> lights = new List <string>();

            //Send Command
            await _client.SendCommandAsync(command);

            await _client.SendCommandAsync(command, lights);
        }
		public void CanConvertToLightCommand()
		{
			LightCommand lightCommand = new LightCommand();
			lightCommand.Alert = Alert.Multiple;
			lightCommand.On = true;

			var json = JsonConvert.SerializeObject(lightCommand);

			GenericScheduleCommand genericCommand = new GenericScheduleCommand(json);

			Assert.IsFalse(genericCommand.IsSceneCommand());
			Assert.IsNotNull(genericCommand.AsLightCommand());

			var light = genericCommand.AsLightCommand();
			Assert.AreEqual(lightCommand.Alert, light.Alert);
		}
Example #34
0
    public async Task CreateScheduleSingle()
    {
      Schedule schedule = new Schedule();
      schedule.Name = "t1";
      schedule.Description = "test";
			schedule.LocalTime = new HueDateTime()
			{
				DateTime = DateTime.Now.AddDays(1)
			};
      schedule.Command = new InternalBridgeCommand();

      var commandBody = new LightCommand();
      commandBody.Alert = Alert.Once;
      schedule.Command.Body = commandBody;
      schedule.Command.Address = "/api/huelandspoor/lights/5/state";
      schedule.Command.Method = HttpMethod.Put;

      var result = await _client.CreateScheduleAsync(schedule);

      Assert.IsNotNull(result);
    }
    public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
    {
      if (reader.TokenType == JsonToken.StartObject)
      {
        JObject jObject = JObject.Load(reader);

        //Check if it is a scene command
        if (jObject["scene"] != null || jObject["Scene"] != null)
        {
          var sceneTarget = new SceneCommand();
          // Populate the object properties
          serializer.Populate(jObject.CreateReader(), sceneTarget);
          return sceneTarget;
        }

        // Populate the object properties
        var target = new LightCommand();
        serializer.Populate(jObject.CreateReader(), target);
        return target;
      }
     
      return serializer.Deserialize<LightCommand>(reader);
    }
Example #36
0
				private void FlashAction()
				{
					LightCommand command = new LightCommand();
					command.TurnOn();
					command.Alert = Alert.Once;

					_hueClient.SendCommandAsync(command);
				}
Example #37
0
				public void SetColor(int r, int g, int b)
				{
					LightCommand command = new LightCommand();
					command.TurnOn();
					command.SetColor(r, g, b);

					_hueClient.SendCommandAsync(command);
				}
Example #38
0
				private void GreenAction()
				{
					LightCommand command = new LightCommand();
					command.TurnOn().SetColor("00FF00");

					_hueClient.SendCommandAsync(command);
				}
Example #39
0
				private void ColorloopAction()
				{
					LightCommand command = new LightCommand();
					command.TurnOn();
					command.Effect = Effect.ColorLoop;

					_hueClient.SendCommandAsync(command);
				}
Example #40
0
    public async Task SendCommandAsync()
    {
      //Create command
      var command = new LightCommand();
      command.TurnOn();
      command.SetColor(new RGBColor("#225566"));

      List<string> lights = new List<string>() { "1", "2", "3" };

      //Send Command
      var result = await _client.SendCommandAsync(command);
      var result2 = await _client.SendCommandAsync(command, lights);

    }
Example #41
0
				private void TurnOnAction()
				{
					LightCommand command = new LightCommand();
					command.TurnOn();

					_hueClient.SendCommandAsync(command);
				}