public static IColor CalculateColor(Light light) { var hexColor = "#" + light.ToHex(); var result = hexColor.ToColor(); return result; }
public HueLightingServiceHandler(Q42.HueApi.HueClient client, Q42.HueApi.Light light) { //Doc on supported lights: // http://www.developers.meethue.com/documentation/supported-lights _light = light; var info = new HueLampInfo(light); var state = light.State; _client = client; LampDetails_Color = info.SupportsColor; LampDetails_ColorRenderingIndex = info.ColorRenderingIndex; LampDetails_Dimmable = info.IsDimmable; LampDetails_HasEffects = false; LampDetails_IncandescentEquivalent = info.IncandescentEquivalent; LampDetails_LampBaseType = (uint)info.BaseType; LampDetails_LampBeamAngle = info.LampBeamAngle; LampDetails_LampID = light.Id; LampDetails_LampType = (uint) info.LampType; LampDetails_Make = (uint)AdapterLib.LsfEnums.LampMake.MAKE_OEM1; LampDetails_MaxLumens = info.MaxLumens; LampDetails_MaxTemperature = info.MaxTemperature; LampDetails_MaxVoltage = 120; LampDetails_MinTemperature = info.MinTemperature; LampDetails_MinVoltage = 100; LampDetails_Model = 1; LampDetails_Type = (uint)AdapterLib.LsfEnums.DeviceType.TYPE_LAMP; LampDetails_VariableColorTemp = info.SupportsTemperature; LampDetails_Version = 1; LampDetails_Wattage = info.Wattage; }
public async void InitializeHue() { _isInitialized = false; //initialize client with bridge IP and app GUID _client = new LocalHueClient(BRIDGE_IP); _client.Initialize(APP_ID); //only working with light #1 in this demo _light = await _client.GetLightAsync("1"); _lightList = new List<string>() { "1" }; //initialize UI this.toggle_Power.IsOn = _light.State.On; string hexColor = _light.State.ToHex(); byte brightness = _light.State.Brightness; this.slider_Brightness.Value = brightness; //there seems to be a defect with the color picker, the initial color isn't visually changing the control //from code-behind. I'm leaving this code here in case it is fixed in the future. var rgb = HexToRGB(hexColor); this.color_Picker.SelectedColor = new SolidColorBrush(Color.FromArgb(brightness, rgb[0], rgb[1], rgb[2])); _isInitialized = true; _timer.Start(); }
public HueLightingServiceHandler(Q42.HueApi.HueClient client, Q42.HueApi.Light light) { //Doc on supported lights: // http://www.developers.meethue.com/documentation/supported-lights _light = light; var info = new HueLampInfo(light); var state = light.State; _client = client; LampDetails_Color = info.SupportsColor; LampDetails_ColorRenderingIndex = info.ColorRenderingIndex; LampDetails_Dimmable = info.IsDimmable; LampDetails_HasEffects = true; LampDetails_IncandescentEquivalent = info.IncandescentEquivalent; LampDetails_LampBaseType = (uint)info.BaseType; LampDetails_LampBeamAngle = info.LampBeamAngle; LampDetails_LampID = light.Id; LampDetails_LampType = (uint)info.LampType; LampDetails_Make = (uint)AdapterLib.LsfEnums.LampMake.MAKE_OEM1; LampDetails_MaxLumens = info.MaxLumens; LampDetails_MaxTemperature = info.MaxTemperature; LampDetails_MaxVoltage = 120; LampDetails_MinTemperature = info.MinTemperature; LampDetails_MinVoltage = 100; LampDetails_Model = 1; LampDetails_Type = (uint)AdapterLib.LsfEnums.DeviceType.TYPE_LAMP; LampDetails_VariableColorTemp = info.SupportsTemperature; LampDetails_Wattage = info.Wattage; }
public LightPage(Light selectedLight) { InitializeComponent(); var ViewModel = new ViewModels.LightViewModel(selectedLight); BindingContext = ViewModel; }
public static int CalculatePower(Light light) { var state = light.State; var result = state.Brightness; if (state.On == false) { result = 0; } return result; }
public Q42HueDevice(Q42HueNetwork network, Light light) : base(network, DeviceType.MultilevelSwitch) { HueNetwork = network; BackingObject = light; _binarySwitch = new Q42HueBinarySwitch(this); _multilevelSwitch = new Q42HueMultilevelSwitch(this); _colorSwitch = new Q42HueColorSwitch(this); Name = light.Name; Address = light.Id; IsConnected = light.State.IsReachable; }
/// <summary> /// Create a new information object. /// </summary> /// <param name="infoObject">Either a <see cref="Q42.HueApi.Light"/> or a <see cref="Q42.HueApi.Models.Groups.Group"/></param> public HueObject(object infoObject) { if (infoObject.GetType() == typeof(Q42.HueApi.Bridge)) { Bridge bridge = (Q42.HueApi.Bridge)infoObject; BridgeConfig config = bridge.Config; if (config == null) { id = "-1"; name = "Bridge"; } else { id = config.BridgeId; name = config.Name; } isBridge = true; lightIDs = new List <string>(); value = infoObject; } else if (infoObject.GetType() == typeof(Q42.HueApi.Light)) { Q42.HueApi.Light light = (Q42.HueApi.Light)infoObject; id = light.Id; name = light.Name; isLight = true; lightIDs = new List <string> { id }; value = infoObject; } else if (infoObject.GetType() == typeof(Q42.HueApi.Models.Groups.Group)) { Q42.HueApi.Models.Groups.Group grp = (Q42.HueApi.Models.Groups.Group)infoObject; id = grp.Id; name = grp.Name; isGroup = true; lightIDs = grp.Lights; value = infoObject; } else { throw new ArgumentException("Argument should be either Bridge, Group or Light.", "infoObject"); } }
public async void SetupValues(Q42.HueApi.Light thelight) { light = thelight; if (light != null) { Native_Hue = (uint)light.State.Hue << 24; Native_Brightness = (uint)light.State.Brightness << 24; Native_Saturation = (uint)light.State.Saturation << 24; Native_Temperature = (uint)light.State.ColorTemperature << 24; light.State.Saturation = 0xFF; light.State.Brightness = 0xFF; byte r = 0; byte g = 0; byte b = 0; ColorFromHSV((double)125, (double)light.State.Saturation, (double)light.State.Brightness, out r, out g, out b); await Task.Delay(1500); PhilipsHueController.SetColorAndOn(light, (int)r, (int)g, (int)b); } }
private LightEvent Convert(Q42.HueApi.Light light) { return(new LightEvent { Light = new Models.Light { Id = light.Id, Name = light.Name, HueType = light.Type, ModelId = light.ModelId, SWVersion = light.SoftwareVersion }, State = new LightState { Brightness = light.State.Brightness, Hue = (short)(light.State.Hue ?? 0), On = light.State.On, Reachable = light.State.IsReachable ?? false, Saturation = (short)(light.State.Saturation ?? 0), AddDate = DateTimeOffset.Now } }); }
public LightViewModel(Light selectedLight) { SelectedLight = selectedLight; }
public ActionResult Edit(Light light) { if (ModelState.IsValid) { Light lightIndex = _lightList.FirstOrDefault(x => x.Id == light.Id); lightIndex.State.On = light.State.On; lightIndex.State.Hex = light.State.Hex; var command = Mapper.Map<LightCommand>(lightIndex.State); _hueClient.SendCommandAsync(command, lightIndex); return RedirectToAction("Details"); } else { return View(); } }
/// <summary> /// Gets a list of lights that were discovered the last time a search for new lights was performed. The list of new lights is always deleted when a new search is started. /// </summary> /// <returns></returns> public async Task<List<Light>> GetNewLightsAsync() { CheckInitialized(); HttpClient client = new HttpClient(); string stringResult = await client.GetStringAsync(new Uri(String.Format("{0}lights/new", ApiBase))).ConfigureAwait(false); #if DEBUG //stringResult = "{\"7\": {\"name\": \"Hue Lamp 7\"}, \"8\": {\"name\": \"Hue Lamp 8\"}, \"lastscan\": \"2012-10-29T12:00:00\"}"; #endif List<Light> results = new List<Light>(); JToken token = JToken.Parse(stringResult); if (token.Type == JTokenType.Object) { //Each property is a light var jsonResult = (JObject)token; foreach(var prop in jsonResult.Properties()) { if (prop.Name != "lastscan") { Light newLight = new Light(); newLight.Id = prop.Name; newLight.Name = prop.First["name"].ToString(); results.Add(newLight); } } } return results; }
internal void UpdateBackingObject(Light newBackingObject) { if (BackingObject.Id != newBackingObject.Id) { throw new Exception("Light ID does not match"); } var oldBackingObject = BackingObject; BackingObject = newBackingObject; if (oldBackingObject.State.IsReachable != newBackingObject.State.IsReachable) { AddEvent(newBackingObject.State.IsReachable == true ? DeviceEvent.Found(this, null) : DeviceEvent.Lost(this, null)); } if (Helpers.CalculatePower(oldBackingObject) != Helpers.CalculatePower(newBackingObject)) { AddEvent(DeviceEvent.PowerChanged(this, null)); } var oldColor = Helpers.CalculateColor(oldBackingObject); var newColor = Helpers.CalculateColor(newBackingObject); if (!oldColor.RedGreenBlue.Equals(newColor.RedGreenBlue)) { AddEvent(DeviceEvent.ColorChanged(this, null)); } }
public static Task SendCommandAsync(this IHueClient hueClient, LightCommand command, Light light) { return hueClient.SendCommandAsync(command, new[] { light.Id }); }
public static void UpdateLight(this IHueClient hueClient, Light light) { light = hueClient.GetLightAsync(light.Id).Result; }
public static LightCommand CreateCommand(IColor color, Light light) { var rgb = color.RedGreenBlue; var result = new LightCommand() .SetColor(new RGBColor(rgb.Red, rgb.Green, rgb.Blue), light.ModelId); return result; }