/// <summary> /// Refresh device information /// </summary> public void Refresh() { dynamic sysInfo = Execute("system", "get_sysinfo"); IsColor = (bool)sysInfo.is_color; IsDimmable = (bool)sysInfo.is_dimmable; IsVariableColorTemperature = (bool)sysInfo.is_variable_color_temp; dynamic lightState = Execute("smartlife.iot.smartbulb.lightingservice", "get_light_state"); _poweredOn = lightState.on_off; if (!_poweredOn) { lightState = lightState.dft_on_state; } _hsv = new BulbHSV() { Hue = lightState.hue, Saturation = lightState.saturation, Value = lightState.brightness * 255 / 100 }; _colorTemp = lightState.color_temp; _brightness = lightState.brightness; Refresh(sysInfo); }
/// <summary> /// Refresh device information /// </summary> public async Task Refresh() { dynamic sysInfo = await Execute("system", "get_sysinfo").ConfigureAwait(false);// IsColor = (bool)sysInfo.is_color; IsDimmable = (bool)sysInfo.is_dimmable; IsVariableColorTemperature = (bool)sysInfo.is_variable_color_temp; dynamic lightState = await Execute("smartlife.iot.smartbulb.lightingservice", "get_light_state").ConfigureAwait(false); // _poweredOn = (bool)lightState.on_off; if (!_poweredOn) { lightState = lightState.dft_on_state; } _hsv = new BulbHSV() { Hue = (int)lightState.hue, Saturation = (int)lightState.saturation, Value = (int)lightState.brightness }; _colorTemp = (int)lightState.color_temp; _brightness = (int)lightState.brightness; dynamic lightDetails = await Execute("smartlife.iot.smartbulb.lightingservice", "get_light_details").ConfigureAwait(false); LightDetails = JsonConvert.DeserializeObject <LightDetails>(Convert.ToString(lightDetails)); await RetrievePresets().ConfigureAwait(false); await RetrieveCountDownRules().ConfigureAwait(false); await RetrieveSchedules().ConfigureAwait(false); await Refresh((object)sysInfo).ConfigureAwait(false); }
/// <summary> /// Set HSV color /// </summary> public void SetHSV(BulbHSV hsv) { if (IsColor) { Task.Run(async() => { dynamic result = await Execute("smartlife.iot.smartbulb.lightingservice", "transition_light_state", new JObject { new JProperty("hue", hsv.Hue), new JProperty("saturation", hsv.Saturation), new JProperty("brightness", hsv.Value), new JProperty("color_temp", 0) }, null); _hsv = hsv; }); } else { throw new NotSupportedException("Bulb does not support color changes."); } }
public async override Task SetHSVAsync(BulbHSV hsv) { // validate hsv model ValidateHsv(hsv); // validate heu (it's represented in degrees) if (hsv.Hue > 360) { throw new InvalidOperationException(nameof(hsv.Hue)); } const string system = "smartlife.iot.smartbulb.lightingservice"; const string command = "transition_light_state"; // the mode is always set to normal when allowing color changing await ExecuteAsync(system, command, "mode", "normal").ConfigureAwait(false); await Task.Delay(100).ConfigureAwait(false); await ExecuteAsync(system, command, "color_temp", 0).ConfigureAwait(false); await Task.Delay(100).ConfigureAwait(false); if (Brightness != hsv.Brightness) { await ExecuteAsync(system, command, "brightness", hsv.Brightness).ConfigureAwait(false); await Task.Delay(100).ConfigureAwait(false); } if (Saturation != hsv.Saturation) { await ExecuteAsync(system, command, "saturation", hsv.Saturation).ConfigureAwait(false); await Task.Delay(100).ConfigureAwait(false); } if (_hsv.Hue != hsv.Hue) { await ExecuteAsync(system, command, "hue", hsv.Hue).ConfigureAwait(false); } }
/// <summary> /// Set HSV color /// </summary> public async Task SetHSV(BulbHSV hsv, int transition_period = 0) { if (transition_period < 0 || transition_period > 10000) { throw new ArgumentException("transition_period only allows values between 0 and 10000"); } if (!IsColor) { throw new NotSupportedException("Bulb does not support color changes."); } dynamic result = await Execute("smartlife.iot.smartbulb.lightingservice", "transition_light_state", new JObject { new JProperty("hue", hsv.Hue), new JProperty("saturation", hsv.Saturation), new JProperty("brightness", hsv.Value), new JProperty("color_temp", 0), new JProperty("transition_period", transition_period) }, null).ConfigureAwait(false); _hsv = hsv; }