def __init__(self, *args, **kwargs): self.state = { "pow": "on", "sta": 0, "bri": 1, "rgb": 16741971, "cct": 1, "snm": 0, "spr": 0, "spt": 15, "wke": 0, "bl": 1, "ms": 1, "mb": 1, "wkp": [0, 24, 0], } self.return_values = { "get_prop": self._get_state, "set_power": lambda x: self._set_state("pow", x), "set_bright": lambda x: self._set_state("bri", x), "set_cct": lambda x: self._set_state("cct", x), "set_rgb": lambda x: self._set_state("rgb", [rgb_to_int(x)]), "apply_fixed_scene": lambda x: self._set_state("snm", x), "go_night": lambda x: self._set_state("snm", [6]), "set_bricct": lambda x: ( self._set_state("bri", [x[0]]), self._set_state("cct", [x[1]]), ), "set_brirgb": lambda x: ( self._set_state("rgb", [rgb_to_int((x[0], x[1], x[2]))]), self._set_state("bri", [x[3]]), ), } super().__init__(args, kwargs)
def __init__(self, *args, **kwargs): self.state = { 'pow': 'on', 'sta': 0, 'bri': 1, 'rgb': 16741971, 'cct': 1, 'snm': 0, 'spr': 0, 'spt': 15, 'wke': 0, 'bl': 1, 'ms': 1, 'mb': 1, 'wkp': [0, 24, 0] } self.return_values = { 'get_prop': self._get_state, 'set_power': lambda x: self._set_state("pow", x), 'set_bright': lambda x: self._set_state("bri", x), 'set_cct': lambda x: self._set_state("cct", x), 'set_rgb': lambda x: self._set_state("rgb", [rgb_to_int(x)]), 'apply_fixed_scene': lambda x: self._set_state("snm", x), 'set_bricct': lambda x: ( self._set_state('bri', [x[0]]), self._set_state('cct', [x[1]]), ), 'set_brirgb': lambda x: ( self._set_state('rgb', [rgb_to_int((x[0], x[1], x[2]))]), self._set_state('bri', [x[3]]), ) } super().__init__(args, kwargs)
async def async_turn_on(self, **kwargs): if self.supported_features & SUPPORT_COLOR_TEMP and ATTR_COLOR_TEMP in kwargs: mired = kwargs[ATTR_COLOR_TEMP] color_temp = self.translate_mired(mired) _LOGGER.debug('Setting color temperature: %s mireds, %s ct', mired, color_temp) result = await self._try_command( 'Setting color temperature failed: %s ct', self._device.set_color_temp, color_temp, ) if result: self._color_temp = color_temp if self.supported_features & SUPPORT_BRIGHTNESS and ATTR_BRIGHTNESS in kwargs: brightness = kwargs[ATTR_BRIGHTNESS] percent_brightness = ceil(100 * brightness / 255) _LOGGER.debug('Setting brightness: %s %s%%', brightness, percent_brightness) result = await self._try_command( 'Setting brightness failed: %s', self._device.set_brightness, percent_brightness, ) if result: self._brightness = brightness if self.supported_features & SUPPORT_COLOR and ATTR_HS_COLOR in kwargs: rgb = color.color_hs_to_RGB(*kwargs[ATTR_HS_COLOR]) _LOGGER.debug('Setting light: %s color: %s', self.name, rgb) result = await self._try_command( 'Setting color failed: %s', self._device.set_rgb, rgb, ) if result: self._state_attrs['rgb'] = rgb_to_int(rgb) if not self._state: await self._try_command('Turning the light on failed.', self._device.on)
ret = self.set_property(self._prop_brightness, val) if self._prop_color_temp and ATTR_COLOR_TEMP in kwargs: mired = kwargs[ATTR_COLOR_TEMP] color_temp = self.translate_mired(mired) if self._vars.get('color_temp_reverse'): color_temp = self._vars.get('color_temp_sum') - color_temp self.logger.debug('%s: Setting light color temperature: %s mireds, %s ct', self.name_model, mired, color_temp) if trs: ret = self.send_miio_command('set_ct_abx', [color_temp, 'smooth', trs]) else: ret = self.set_property(self._prop_color_temp, color_temp) if self._prop_color and ATTR_HS_COLOR in kwargs: rgb = color.color_hs_to_RGB(*kwargs[ATTR_HS_COLOR]) num = rgb_to_int(rgb) self.logger.debug('%s: Setting light color: %s', self.name_model, rgb) ret = self.set_property(self._prop_color, num) if self._prop_mode and ATTR_EFFECT in kwargs: mode = kwargs[ATTR_EFFECT] val = self._prop_mode.list_value(mode) self.logger.debug('%s: Setting light effect: %s(%s)', self.name_model, mode, val) ret = self.set_property(self._prop_mode, val) return ret def turn_off(self, **kwargs): trs = kwargs.get(ATTR_TRANSITION) if trs is not None: trs *= 1000