static async Task RunLightCommand02()
        {
            LocalHueClient client = await HueManager.GetClient();

            if (client == null)
            {
                return;
            }

            var command = new LightCommand();

            // some random settings for tests
            command.SetColor(new RGBColor(255, 255, 255));
            client.SendCommandAsync(command);
            Thread.Sleep(1000);
            command.TurnOff();
            client.SendCommandAsync(command);
            Thread.Sleep(1000);
            command.TurnOn();
            client.SendCommandAsync(command);
            Thread.Sleep(1000);
            command.TurnOff();
            client.SendCommandAsync(command);
            Thread.Sleep(1000);
            command.TurnOn();
            client.SendCommandAsync(command);
            Thread.Sleep(1000);
            command.SetColor(new RGBColor(127, 0, 255));
            client.SendCommandAsync(command);
        }
Пример #2
0
        /*
         * Reset all light to what they were before starting
         */
        private async void reset()
        {
            if (gameStateListener != null)
            {
                gameStateListener.Stop();
            }
            gameStateListener = null;
            proccessStarted   = false;

            foreach (KeyValuePair <string, groupProperties> group in groups)
            {
                foreach (lightProperties light in group.Value.lights)
                {
                    var command = new LightCommand();
                    if (light.orgOn)
                    {
                        command.TurnOn();
                    }
                    else
                    {
                        command.TurnOff();
                    }
                    command.SetColor(light.colorCoordinates[0], light.colorCoordinates[1]);
                    List <string> listId = new List <string>();
                    listId.Add(light.id);
                    await client.SendCommandAsync(command, listId);
                }
            }
        }
Пример #3
0
        private void btnChangeColor_Click(object sender, EventArgs e)
        {
            string selectedLight = null;

            if (listboxLights.SelectedIndex == -1)
            {
                return;
            }
            else
            {
                foreach (var light in this.lights)
                {
                    if (listboxLights.SelectedItem.Equals(light.Name))
                    {
                        selectedLight = light.Id;
                    }
                }
            }

            var dialog = new ColorDialog();

            dialog.ShowDialog();
            var selectedColor = dialog.Color;

            var command = new LightCommand();

            command.On = true;
            command.TurnOn().SetColor(new RGBColor(selectedColor.R, selectedColor.G, selectedColor.B));

            client.SendCommandAsync(command, new List <string> {
                selectedLight
            });
        }
Пример #4
0
        private async Task <bool> ChangeStateLights(bool stateOfLights, List <string> lightsIds)
        {
            try
            {
                if (lightsIds.Any())
                {
                    var command = new LightCommand();
                    if (stateOfLights)
                    {
                        command.TurnOn();
                    }
                    else
                    {
                        command.TurnOff();
                    }

                    var result = await _hueClient.SendCommandAsync(command, lightsIds);

                    return(!result.HasErrors());
                }
                return(true);
            }
            catch (Exception e)
            {
                return(false);
            }
        }
        public async void ResetLights()
        {
            LightCommand command = new LightCommand();

            command.On = true;

            foreach (Tuple <RGBColor, string> light in lastColor)
            {
                command.TurnOn().SetColor(light.Item1);

                if (light.Item2 == "all")
                {
                    await client.SendCommandAsync(command);
                }
                else
                {
                    await client.SendCommandAsync(command, new List <string> {
                        light.Item2
                    });
                }
            }

            blinkTimer.Stop();
            lastColor.Clear();
        }
Пример #6
0
        private void lstScenes_SelectedIndexChanged(object sender, EventArgs e)
        {
            string sceneIndex = ""; //Reset scene index.

            try
            {
                sceneIndex = lstScenes.SelectedItem.ToString(); //Make sure selected scene isn't blank.

                if (sceneIndex == "Color loop")
                {
                    discoToggle = false;

                    var command = new LightCommand();

                    command.TurnOn().Effect = Effect.ColorLoop; //Set scene to color loop.

                    commandSender(command);

                    btnOnOff.BackgroundImage = Properties.Resources.On;
                }

                else //If not colour loop or disco then it is a normal theme so disable disco and send the scene to the method.
                {
                    discoToggle = false;
                    sceneSender(sceneIndex);
                }
            }

            catch
            {
            }
        }
Пример #7
0
        public async Task discoThread()
        {
            while (discoToggle == true)                            //Loop until different colour, scene selected or lights turned off.
            {
                List <RGBColor> colorList = new List <RGBColor>(); //Initalise colour collection.

                Random rnd = new Random();

                foreach (var item in lights)
                {
                    Color randomColor = Color.FromArgb(rnd.Next(256), rnd.Next(256), rnd.Next(256)); //Get new random colour.

                    RGBColor convert = new RGBColor(randomColor.R, randomColor.G, randomColor.B);    //Convert colour to usable colour.

                    pnlCurrentSwatch.BackColor = randomColor;                                        //Set current swatch colour to the last random colour.

                    colorList.Add(convert);                                                          //Add colours to list.
                }

                for (int i = 0; i < lights.Count(); i++) //For each light grab relevant color from the list and send it to one light only.
                {
                    var command = new LightCommand();

                    command.TurnOn().SetColor(colorList[i]);

                    await client.SendCommandAsync(command, new List <string> {
                        (i + 1).ToString()
                    });
                }

                Thread.Sleep(500); //Wait after changing all lights before changing again.
            }
        }
Пример #8
0
        public async Task SetColour(RGBColor color)
        {
            // Set all lights to the specified colour

            var command = new LightCommand();

            // ColorConverter by default assumes a LCT001 fixture, the gamut
            // of which is very limited in the green direction.  Specify a
            // "Richer Colours" fixture so we can get green instead of lime.
            command.TurnOn().SetColor(color, "LCT015");
            var results = await client.SendCommandAsync(command);

            if (results.HasErrors())
            {
                Console.WriteLine("Errors encountered in setting lights:");
                foreach (var res in results.Errors)
                {
                    Console.WriteLine("Address: " + res.Error.Address + ", " +
                                      "Type: " + res.Error.Type + ", " +
                                      "Description: " + res.Error.Description);
                }
            }
            else
            {
                Console.WriteLine("Light test successful.");
            }
        }
Пример #9
0
        public void DoColorChange()
        {
            List <ColorCount> colors = new List <ColorCount>();

            foreach (KeyValuePair <string, ColorCount> kvp in colorCounts)
            {
                colors.Add(kvp.Value);
            }

            ColorCount ctp = colors.OrderByDescending(ccc => ccc.VoteCount).FirstOrDefault();
            Color      c;

            if (ctp != null)
            {
                c = ctp.color;

                LightCommand command = new LightCommand();
                command.Brightness = 100;
                command.TurnOn().SetColor(new RGBColor(c.ScR * 100, c.ScG * 100, c.ScB * 100));

                foreach (ILocalHueClient Hue in avaialableBridges)
                {
                    Hue.SendCommandAsync(command);
                }
            }
        }
Пример #10
0
        public async Task <Light> SetLampColorAsync(string colorCode, string lightId = "")
        {
            if (lightId == "")
            {
                lightId = _config["MainLight"];
            }

            RGBColor rgbColor = new RGBColor(colorCode);
            var      command  = new LightCommand();

            command.TurnOn().SetColor(rgbColor);

            var light = await GetLight(lightId);

            if (light != null)
            {
                _logger.Information($"Changing light color for lamp {lightId} to {colorCode}");
                await _hueClient.SendCommandAsync(command, new List <string> {
                    light.Id
                });
            }
            else
            {
                _logger.Error($"Could not find light for light id:{lightId}");
            }
            return(light);
        }
Пример #11
0
        async Task TurnLightRed()
        {
            Settings.IWasHere = Settings.IWasHere + 1;

            var bridgeLocator = new HttpBridgeLocator();
            var ips           = await bridgeLocator.LocateBridgesAsync(TimeSpan.FromSeconds(30));

            var client = new LocalHueClient(ips.First().IpAddress);

            if (!client.IsInitialized && !string.IsNullOrEmpty(Settings.HueKey))
            {
                client.Initialize(Settings.HueKey);
            }
            else
            {
                //await DisplayAlert("Not paired", "App not paired to a bridge, hit the register button.", "OK");

                return;
            }

            var command  = new LightCommand();
            var redColor = new RGBColor(220, 82, 74);

            command.TurnOn().SetColor(redColor);

            var allLights = await client.GetLightsAsync();

            foreach (var light in allLights)
            {
                if (light.Name.Equals("hue go 1", StringComparison.OrdinalIgnoreCase))
                {
                    await client.SendCommandAsync(command, new[] { light.Id });
                }
            }
        }
        public void SetLampColorAsync_SetsTheLampColor()
        {
            // Arrange
            string uniqueId               = "lightId221";
            string lightId                = "1";
            string expectedColor          = _red;
            IEnumerable <Light> lightList = new List <Light>()
            {
                new Light()
                {
                    UniqueId = uniqueId, Id = lightId
                }
            };

            RGBColor rgbColor = new RGBColor(expectedColor);
            var      command  = new LightCommand();

            command.TurnOn().SetColor(rgbColor);

            _loggerMock.Setup(m => m.Information(It.Is <string>(a => a.Contains(uniqueId) && a.Contains(expectedColor))));
            _hueClientMock.Setup(m => m.GetLightsAsync()).Returns(Task.FromResult(lightList));
            _hueClientMock.Setup(m => m.SendCommandAsync(It.IsAny <LightCommand>(), It.Is <IEnumerable <string> >(lc => lc.Contains(lightId))));

            var hueController = new HueController(_loggerMock.Object, _configMock.Object, _hueClientMock.Object);

            //Act
            var result = hueController.SetLampColorAsync(expectedColor, uniqueId);

            //Assert
            Assert.IsNotNull(result);
            _loggerMock.Verify(m => m.Information(It.Is <string>(a => a.Contains(uniqueId) && a.Contains(expectedColor))), Times.Once);
            _hueClientMock.Verify(m => m.SendCommandAsync(It.IsAny <LightCommand>(), It.Is <IEnumerable <string> >(lc => lc.Contains(lightId))), Times.Once);
        }
Пример #13
0
        private async Task ParseAndControlLight(string lightid, ControlItem citem)
        {
            var cmd = new LightCommand();

            if (citem.Powered.HasValue)
            {
                cmd.On = citem.Powered.Value;
            }

            if (citem.Color.HasValue)
            {
                cmd.TurnOn().SetColor(citem.Color.Value);
            }

            if (citem.Alert.HasValue)
            {
                cmd.Alert = citem.Alert.Value;
            }

            if (citem.Effect.HasValue)
            {
                cmd.Effect = citem.Effect.Value;
            }

            await client.SendCommandAsync(cmd, new List <string> {
                lightid
            });
        }
Пример #14
0
        private async void Timer_Tick(object sender, object e)
        {
            timer.Stop();

            // set brightness
            var cmd = new LightCommand();

            cmd = (_brightness == 0) ? cmd.TurnOff() : cmd.TurnOn();
            var brightness = (byte?)((double)_brightness / 100.0 * 255.0);

            cmd.Brightness = brightness;

            // set color
            var color = this._lightBrush.Color;

            cmd.SetColor(color.R, color.G, color.B);
            SendLightCommands(cmd);

            // get changes and update
            var light = await HueMonger.Model.Bridge.GetLight(this.LightId);

            this.Update(light);
            RaisePropertyChanged("Brightness");
            RaisePropertyChanged("LightBrish");
        }
Пример #15
0
        /*
         * Check if player is dead and turn lights if so.
         */
        private async Task <bool> TurnOffOnDeath(GameState gs)
        {
            if (gs.Hero.IsAlive != isAlive)
            {
                isAlive = false;
                //we dont turn on light becose health update does that for us.
                if (!gs.Hero.IsAlive)
                {
                    //Create command to sent to lights
                    var command = new LightCommand();
                    command.TurnOff();

                    count++;
                    return(await SendCommand(command));
                }
                else if (!this.HealthBox.Checked)
                {
                    //Create command to sent to lights
                    var command = new LightCommand();
                    command.TurnOn();

                    count++;
                    return(await SendCommand(command));
                }
            }
            else
            {
                isAlive = true;
            }
            return(false);
        }
Пример #16
0
        public async void SwitchLights()
        {
            var cmd = new LightCommand();

            cmd = (AllLightsOn) ? cmd.TurnOn() : cmd.TurnOff();
            await Model.Bridge.SendLightsCommands(cmd);
        }
Пример #17
0
        private async void button6_Click_1(object sender, EventArgs e) //처음에 안됐던 이유는 double click을 하지 않아서 였다.
        {
            string weburl = "http://api.openweathermap.org/data/2.5/weather?q=" + textBox1.Text + "&mode=xml&units=imperial&APPID=15c1625f8d2317f825b8aada51d5dd9d";
            //&mode=xml&untis에서 끝내면 안되고, 위 url에서 얻은 내 key를 같이 입력해야 한다.
            //var client = new System.Net.WebClient();
            var xml = await new WebClient().DownloadStringTaskAsync(new Uri(weburl));

            XmlDocument doc = new XmlDocument();

            doc.LoadXml(xml);
            string szTemp = doc.DocumentElement.SelectSingleNode("temperature").Attributes["value"].Value;
            double temp   = (double.Parse(szTemp) - 32) * 5 / 9; //fernheit를 celcius로 바꾸기

            label1.Text = "Current temperature of this city is " + "'" + temp.ToString("N1") + "'" + " celcius.";


            double degree = temp;

            if (degree >= 20 && degree < 30)
            {
                MessageBox.Show("hot");
                var command = new LightCommand();
                //command.TurnOn().SetColor("FFBB00"); //20도이상은 주황불
                command.Brightness = 128;
                var result = await client.SendCommandAsync(command);
            }
            else if (degree >= 10 && degree < 20)
            {
                MessageBox.Show("cool");
                var command = new LightCommand();
                command.TurnOn().SetColor("0054FF");  //10도 이상은 파란불
                command.Brightness = 128;
                var result = await client.SendCommandAsync(command);
            }
            else if (degree >= 0 && degree < 10)
            {
                MessageBox.Show("cold");
                var command = new LightCommand();
                command.TurnOn().SetColor("FF00DD"); //0도 이상은 보라불
                command.Brightness = 128;
                var result = await client.SendCommandAsync(command);
            }
            else if (degree >= 30)
            {
                MessageBox.Show("very hot");
                var command = new LightCommand();
                command.TurnOn().SetColor("FF0000"); //30도 이상은 빨간불
                command.Brightness = 128;
                var result = await client.SendCommandAsync(command);
            }
            else
            {
                MessageBox.Show("very cold");
                var command = new LightCommand();
                command.TurnOn().SetColor("CACACA"); //영하는 회색불
                command.Brightness = 128;
                var result = await client.SendCommandAsync(command);
            }
        }
Пример #18
0
        /*
         * Turn on all bulbs
         */
        public async Task TurnOn()
        {
            var command = new LightCommand();

            command.TurnOn();

            await SendCommand(command);
        }
        async void ChangeLightColor(HueLight light, string color)
        {
            var command = new LightCommand();

            command.TurnOn().SetColor(new RGBColor(color));

            SendCommandToClient(command, light.getLightId());
        }
Пример #20
0
        private void TurnOnAction()
        {
            LightCommand command = new LightCommand();

            command.TurnOn();

            _hueClient.SendCommandAsync(command);
        }
Пример #21
0
        public LightCommand GetColorCommand(String color)
        {
            var command = new LightCommand();

            command.On = true;
            command.TurnOn().SetColor(color);
            return(command);
        }
Пример #22
0
        public void SetColor(RGBColor color, List <string> lights)
        {
            var command = new LightCommand();

            command.TurnOn().SetColor(color);

            _hueClient.SendCommandAsync(command, lights);
        }
Пример #23
0
        private void pictureBox3_Click(object sender, EventArgs e)
        {
            var command = new LightCommand();

            command.TurnOn().SetColor("CACACA");
            command.Brightness = 128;
            client.SendCommandAsync(command);
        }
Пример #24
0
        private void GreenAction()
        {
            LightCommand command = new LightCommand();

            command.TurnOn().SetColor(new RGBColor("00FF00"));

            _hueClient.SendCommandAsync(command);
        }
Пример #25
0
        private void RedAction()
        {
            LightCommand command = new LightCommand();

            command.TurnOn().SetColor("FF0000");

            _hueClient.SendCommandAsync(command);
        }
Пример #26
0
        private void ColorloopAction()
        {
            LightCommand command = new LightCommand();

            command.TurnOn();
            command.Effect = Effect.ColorLoop;

            _hueClient.SendCommandAsync(command);
        }
Пример #27
0
        public void FlashLights(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.Brightness = 255;

                            await hueClient.SendCommandAsync(lightCommand, bulbIDs);
                            await Task.Delay(100);

                            lightCommand.Brightness = 155;

                            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();
            }
        }
Пример #28
0
        public void SetColor(int r, int g, int b, string light)
        {
            LightCommand command = new LightCommand();

            command.TurnOn();
            command.SetColor(new RGBColor(r, g, b));

            SendCommandAsync(command, light);
        }
Пример #29
0
        public void SetColor(int r, int g, int b)
        {
            LightCommand command = new LightCommand();

            command.TurnOn();
            command.SetColor(new RGBColor(r, g, b));

            _hueClient.SendCommandAsync(command);
        }
Пример #30
0
        private void FlashAction()
        {
            LightCommand command = new LightCommand();

            command.TurnOn();
            command.Alert = Alert.Once;

            _hueClient.SendCommandAsync(command);
        }
Пример #31
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);

    }
Пример #32
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);

    }
Пример #33
0
				private void FlashAction()
				{
					LightCommand command = new LightCommand();
					command.TurnOn();
					command.Alert = Alert.Once;

					_hueClient.SendCommandAsync(command);
				}
Пример #34
0
				private void GreenAction()
				{
					LightCommand command = new LightCommand();
					command.TurnOn().SetColor("00FF00");

					_hueClient.SendCommandAsync(command);
				}
Пример #35
0
				private void TurnOnAction()
				{
					LightCommand command = new LightCommand();
					command.TurnOn();

					_hueClient.SendCommandAsync(command);
				}
Пример #36
0
				public void SetColor(int r, int g, int b)
				{
					LightCommand command = new LightCommand();
					command.TurnOn();
					command.SetColor(r, g, b);

					_hueClient.SendCommandAsync(command);
				}
Пример #37
0
				private void ColorloopAction()
				{
					LightCommand command = new LightCommand();
					command.TurnOn();
					command.Effect = Effect.ColorLoop;

					_hueClient.SendCommandAsync(command);
				}