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); }
/// <summary> /// Sets the color of the common command. /// </summary> /// <param name="rgbColor">New color in the color type of the API</param> public static void SetRGBColorInCommonCommand(RGBColor rgbColor) { if (!canControl) { return; } if (BridgeInformation.demoMode) { DemoLightController.commonRGBColor = rgbColor; } commonLightCommand.SetColor(rgbColor); }
public async Task SetColor(string availability, string lightId) { _client = new LocalHueClient(_options.HueIpAddress); _client.Initialize(_options.HueApiKey); var command = new LightCommand(); if (_options.Brightness == 0) { command.On = false; } else { command.On = true; command.Brightness = Convert.ToByte(((_options.Brightness / 100) * 254)); command.TransitionTime = new TimeSpan(0); } 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("#B03CDE")); 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 }); }
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"); }
/* * AlertBounty rune */ private async Task <bool> BountyRuneAlert(GameState gs) { int realClockTime = gs.Map.ClockTime; if (lastBountTime != realClockTime) { if (realClockTime % 300 == 290 || realClockTime == 0) { var command = new LightCommand(); command.Alert = Alert.Multiple; Color color = this.BuntyColorLight.ForeColor; command.SetColor(new RGBColor(color.R, color.G, color.B)); if (client != null) { lastBountTime = realClockTime; count++; return(await SendCommand(command)); } else { this.infoText.Text = "client is null"; } } } return(false); }
public void SetColor(RgbColor color) { LightCommand command = new LightCommand(); command.SetColor(new RGBColor(color.ToHex())); _client.SendCommandAsync(command); }
static void UpdateHueLegacy(ILocalHueClient hue) { /* IBridgeLocator locator = new HttpBridgeLocator(); * var locateBridges = locator.LocateBridgesAsync(TimeSpan.FromSeconds(5)); * IEnumerable<LocatedBridge> bridgeIPs = locateBridges.Result; * * if (bridgeIPs.Where(B => B.BridgeId == "001788fffe678124").Count() > 0) * { * bridge = new LocalHueClient(bridgeIPs.Where(B => B.BridgeId == "001788fffe678124").First().IpAddress); * var registerOne = bridge.RegisterAsync("LightingLink", "WarMachine"); * //string appKeyOne = registerOne.Result; * bridge.Initialize("NnmhRXVqLmBUw93kmIwi8PPCt6QHgWlHwkTYT9NC"); * }*/ do { for (int lightNum = 1; lightNum <= 13; lightNum++) { Color color = colors[lightNum % 4]; var com1 = new LightCommand(); com1.TransitionTime = TimeSpan.FromMilliseconds(150); com1.SetColor(new RGBColor(color.R, color.G, color.B)); var send1 = hue.SendCommandAsync(com1, new List <string> { lightNum.ToString() }); System.Threading.Thread.Sleep(70); } } while (running); }
/* * 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); } } }
private LightCommand CreateColourCommand(HueColour colour) { var command = new LightCommand(); command.On = true; command.SetColor(colour.ToRGBColour()); return(command); }
public static void HUEColor(string value) { var command = new LightCommand(); command.SetColor("#" + value); client.SendCommandAsync(command); }
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); }
/* * Turn on all bulbs with a specific color * @param color: color in hex format */ public async Task TurnOn(string color) { var command = new LightCommand(); command.SetColor(color); command.TurnOn(); await SendCommand(command); }
public void Command(string hexCollor) { LightCommand Command = new LightCommand(); Command.TurnOn(); Command.SetColor(new RGBColor(hexCollor)); Command.Alert = Alert.Multiple; _client.SendCommandAsync(Command); }
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); }
internal static async void SetColor(Light light, int r, int g, int b) { var cmd = new LightCommand(); string sred = r.ToString("X2"); string sgreen = g.ToString("X2"); string sblue = b.ToString("X2"); cmd.SetColor(sred + sgreen + sblue); await SendCommand(cmd, light.Id); }
public async Task SendColorAsync(string key, Color color) { var lightCommand = new LightCommand { }; lightCommand.SetColor(color.ToString().Substring(0, 7)); await _client.SendCommandAsync(lightCommand, new [] { key }); Debug.WriteLine("Light {0} has been sent color {1}", key, color); }
public async Task ErrorAsync() { FulcrumAssert.IsNotNull(_hueClient, null, "Must have a valid HueClient."); var command = new LightCommand(); command.SetColor(ClientHelper.GetRgbColor(ClientHelper.ColorEnum.Red)); command.Alert = Alert.Once; _status = "Error"; await _hueClient.SendCommandAsync(command, _lamps); }
public async void HueUpdateState(BulbModeTypes mode, Color col, int transition) { var connect = await _client.CheckConnection(); if (connect && _hueBulbs > 0) { if (_huEpendingUpdateColor != null) { _huEpendingUpdateColorAction = () => HueUpdateState(mode, col, transition); return; } var _transition = TimeSpan.FromMilliseconds(transition); var _col = new RGBColor(col.R, col.G, col.B); //ushort _hue = Convert.ToUInt16(col.GetHue()); //ushort _sat = Convert.ToUInt16(col.GetSaturation()); //ushort _bright = Convert.ToUInt16(col.GetBrightness()); //ushort _kelvin = 2700; foreach (var d in _HueBulbsDat) { if (d.Value == mode || mode == BulbModeTypes.Unknown) { if (_HueStateMemory[d.Key.UniqueId] == 0) { return; } var state = await _client.GetLightAsync(d.Key.Id); //Unsure if Id or UniqueId should be used var command = new LightCommand(); command.On = true; command.SetColor(_col, d.Key.ModelId); var setColorTask = _client.SendCommandAsync(command, new List <string> { d.Key.Id }); //Unsure if Id or UniqueId should be used var throttleTask = Task.Delay(50); //Ensure task takes minimum 50 ms (no more than 20 messages per second) _huEpendingUpdateColor = Task.WhenAll(setColorTask, throttleTask); } } _huEpendingUpdateColor = null; if (_huEpendingUpdateColorAction != null) { var a = _huEpendingUpdateColorAction; _huEpendingUpdateColorAction = null; a(); } } }
/* * Turn on a specific bulb with a specific color * @param color: color in hex format * @param id: id of the bulb */ public async Task TurnOn(string color, int id) { var command = new LightCommand(); command.SetColor(color); command.TurnOn(); await SendCommand(command, new List <string> { id.ToString() }); }
public static LightCommand SetColor(this LightCommand lightCommand, RGBColor color, string model = "LCT001") { if (lightCommand == null) { throw new ArgumentNullException(nameof(lightCommand)); } var point = HueColorConverter.CalculateXY(color, model); return(lightCommand.SetColor(point.x, point.y)); }
public static LightCommand SetColor(this LightCommand lightCommand, RGBColor color, CIE1931Gamut?gamut) { if (lightCommand == null) { throw new ArgumentNullException(nameof(lightCommand)); } var point = HueColorConverter.RgbToXY(color, gamut); return(lightCommand.SetColor(point.x, point.y)); }
/* * Fades to the color specified with the percentage inbetween start and end color * for a specific bulb * @param percent: value between 0 and 100 * @param startColor: start color in hex format * @param endColor: end color in hex format * @param id: id of specific bulb */ public async Task Fade(int percent, string startColor, string endColor, int id) { ColorCalculation colorCalc = new ColorCalculation(); var command = new LightCommand(); command.SetColor(colorCalc.CalculateColorFade(percent, startColor, endColor)); await SendCommand(command, new List <string> { id.ToString() }); }
public void SetBulbColor(int redComponent, int greenComponent, int blueComponent, string bulbID = "", Action callbackMethod = null) { try { Task setColorTask = 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.SetColor(HueColorConverter.XyFromColor(redComponent, greenComponent, blueComponent).x, HueColorConverter.XyFromColor(redComponent, greenComponent, blueComponent).y); lightCommand.Brightness = 200; await hueClient.SendCommandAsync(lightCommand, bulbIDs); } callbackMethod?.Invoke(); } else { errorLog += "\r\n\r\n" + DateTime.Now.ToString() + ": Philips Hue bridge is not connected."; callbackMethod?.Invoke(); } }); setColorTask.Start(); } catch (Exception setColorException) { errorLog += "\r\n\r\n" + DateTime.Now.ToString() + ": " + setColorException; callbackMethod?.Invoke(); } }
private async void UpdateMicStatusAsync(MMDevice device) { bool muted; if (device == null || device.AudioEndpointVolume.Mute == true) { muted = true; } else { muted = false; } var hueKey = Properties.Settings.Default.HueKey; var hueLights = Properties.Settings.Default.HueLights?.Cast <string>().ToList() ?? new List <string>(); var hueLinked = !string.IsNullOrEmpty(hueKey) && hueLights.Count > 0; var changed = (muted != _muted) || !_init; ILocalHueClient hueClient = null; if (hueLinked) { hueClient = new LocalHueClient(Properties.Settings.Default.HueIPAddress, Properties.Settings.Default.HueKey); } try { _tbIcon.Icon = muted ? Properties.Resources.mic_off : Properties.Resources.mic_on; if (hueLinked && changed) { var command = new LightCommand(); // TODO: Make colours configurable var color = muted ? new RGBColor(255, 0, 0) : new RGBColor(255, 255, 255); command.SetColor(color); await hueClient.SendCommandAsync(command, hueLights); } } catch (Exception e) { if (changed) { MessageBox.Show($"Failed to update mic status: {e.Message}"); } } DisposeDevice(device); if (!_init) { _init = true; } _muted = muted; }
/// <summary> /// Get the color that a command has. /// </summary> /// <param name="command"></param> /// <returns></returns> public static ColorEnum GetColorFromCommand(LightCommand command) { var colorCommand = new LightCommand(); colorCommand.SetColor(GetRgbColor(ColorEnum.Green)); if (HasSameColor(colorCommand, command)) { return(ColorEnum.Green); } colorCommand.SetColor(GetRgbColor(ColorEnum.Yellow)); if (HasSameColor(colorCommand, command)) { return(ColorEnum.Yellow); } colorCommand.SetColor(GetRgbColor(ColorEnum.Red)); if (HasSameColor(colorCommand, command)) { return(ColorEnum.Red); } return(ColorEnum.Unknown); }
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); } }
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 }); }
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); }
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 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); }
private async Task ResetLight(string id) { if (IsBridgeDiscovered && IsRegisteredWithBridge && defaultLightStates.ContainsKey(id)) { var client = new LocalHueClient(LightsSettings.BridgeIP); client.Initialize(LightsSettings.AppKey); var color = defaultLightStates[id]; var command = new LightCommand(); command.SetColor(color[0], color[1]); await client.SendCommandAsync(command, new string[] { id }); } }
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); }
public void SetColor(int r, int g, int b) { LightCommand command = new LightCommand(); command.TurnOn(); command.SetColor(r, g, b); _hueClient.SendCommandAsync(command); }