def turn_on(self, **kwargs): """Turn the light on.""" self._state = True _LOGGER.error("[YEELIGHT]") _LOGGER.error(kwargs.get(ATTR_RGB_COLOR)) hs_color = kwargs.get(ATTR_HS_COLOR) rgb = color_util.color_hs_to_RGB(*hs_color) if hs_color else None with self._dev: if ATTR_BRIGHTNESS in kwargs: brightness = kwargs[ATTR_BRIGHTNESS] if rgb: _LOGGER.error("[YEELIGHT]") _LOGGER.error(kwargs.get(ATTR_HS_COLOR)) self._rgb = rgb self._dev.set_color(rgb[0], rgb[1], rgb[2], int(self._brightness / 255 * 100)) if ATTR_COLOR_TEMP in kwargs: mireds = kwargs[ATTR_COLOR_TEMP] temp_in_k = mired_to_kelvin(mireds) self._dev.set_temperature(int(temp_in_k)) self._ct = mireds if ATTR_BRIGHTNESS in kwargs: brightness = kwargs[ATTR_BRIGHTNESS] self._dev.set_brightness(int(brightness / 255 * 100)) self._brightness = brightness # if we are just started without parameters, turn on. if ATTR_HS_COLOR not in kwargs and \ ATTR_COLOR_TEMP not in kwargs and \ ATTR_BRIGHTNESS not in kwargs: self._dev.turn_on() else: self._dev.turn_on()
def turn_on(self, **kwargs): """Instruct the light to turn on.""" brightness = kwargs.get(ATTR_BRIGHTNESS) hs_color = kwargs.get(ATTR_HS_COLOR) color_temp_mired = kwargs.get(ATTR_COLOR_TEMP) effect = kwargs.get(ATTR_EFFECT) transition = kwargs.get(ATTR_TRANSITION) if hs_color: hue, saturation = hs_color self._light.hue = int(hue) self._light.saturation = int(saturation) if color_temp_mired: self._light.color_temperature = mired_to_kelvin(color_temp_mired) if transition: if brightness: # tune to the required brightness in n seconds self._light.brightness_transition( int(brightness / 2.55), int(transition)) else: # If brightness is not specified, assume full brightness self._light.brightness_transition(100, int(transition)) else: # If no transition is occurring, turn on the light self._light.on = True if brightness: self._light.brightness = int(brightness / 2.55) if effect: self._light.effect = effect
def turn_on(self, **kwargs): """Turn the switch on.""" brightness = kwargs.get(ATTR_BRIGHTNESS) rgb_color = kwargs.get(ATTR_RGB_COLOR) color_temp_mired = kwargs.get(ATTR_COLOR_TEMP) state_kwargs = { } if rgb_color: if self.wink.supports_xy_color(): xyb = color_util.color_RGB_to_xy(*rgb_color) state_kwargs['color_xy'] = xyb[0], xyb[1] state_kwargs['brightness'] = xyb[2] if self.wink.supports_hue_saturation(): hsv = colorsys.rgb_to_hsv( rgb_color[0], rgb_color[1], rgb_color[2]) state_kwargs['color_hue_saturation'] = hsv[0], hsv[1] if color_temp_mired: state_kwargs['color_kelvin'] = mired_to_kelvin(color_temp_mired) if brightness: state_kwargs['brightness'] = brightness / 255.0 self.wink.set_state(True, **state_kwargs)
def turn_on(self, **kwargs): """Turn the light on.""" self._state = True with self._dev: if ATTR_RGB_COLOR in kwargs: rgb = kwargs[ATTR_RGB_COLOR] self._rgb = rgb self._dev.set_color(rgb[0], rgb[1], rgb[2]) if ATTR_COLOR_TEMP in kwargs: mireds = kwargs[ATTR_COLOR_TEMP] temp_in_k = mired_to_kelvin(mireds) self._dev.set_temperature(int(temp_in_k)) self._ct = mireds if ATTR_BRIGHTNESS in kwargs: brightness = kwargs[ATTR_BRIGHTNESS] self._dev.set_brightness(int(brightness / 255 * 100)) self._brightness = brightness # if we are just started without parameters, turn on. if ATTR_RGB_COLOR not in kwargs and \ ATTR_COLOR_TEMP not in kwargs and \ ATTR_BRIGHTNESS not in kwargs: self._dev.turn_on()
def turn_on(self, **kwargs): """Instruct the light to turn on.""" brightness = kwargs.get(ATTR_BRIGHTNESS) hs_color = kwargs.get(ATTR_HS_COLOR) color_temp_mired = kwargs.get(ATTR_COLOR_TEMP) effect = kwargs.get(ATTR_EFFECT) transition = kwargs.get(ATTR_TRANSITION) if hs_color: hue, saturation = hs_color self._light.hue = int(hue) self._light.saturation = int(saturation) if color_temp_mired: self._light.color_temperature = mired_to_kelvin(color_temp_mired) if transition: if brightness: # tune to the required brightness in n seconds self._light.brightness_transition(int(brightness / 2.55), int(transition)) else: # If brightness is not specified, assume full brightness self._light.brightness_transition(100, int(transition)) else: # If no transition is occurring, turn on the light self._light.on = True if brightness: self._light.brightness = int(brightness / 2.55) if effect: if effect not in self._effects_list: raise ValueError( f"Attempting to apply effect not in the effect list: '{effect}'" ) self._light.effect = effect
def turn_on(self, **kwargs): brightness = None color_temp = None if ATTR_EFFECT in kwargs: dimtype = kwargs[ATTR_EFFECT] if dimtype in ["dim_up_down", "dim_up", "dim_down", "dim_stop"]: if dimtype == "dim_up_down": if self._dim_up_down == 1: dimtype = "dim_up" self._dim_up_down = 0 else: dimtype = "dim_down" self._dim_up_down = 1 self._dev.dimming(dimtype, self._state) return if ATTR_BRIGHTNESS in kwargs: brightness = int(kwargs[ATTR_BRIGHTNESS] / 2.55) self._brightness = brightness if ATTR_COLOR_TEMP in kwargs: color_temp = int(mired_to_kelvin(kwargs[ATTR_COLOR_TEMP])) if color_temp > self._color_temp_max: color_temp = self._color_temp_max if color_temp < self._color_temp_min: color_temp = self._color_temp_min self._color_temp = color_temp if color_temp: self._dev.turn_on(brightness, color_temp) else: self._dev.turn_on(brightness) self._state = True self._update_ha_state()
def set_colortemp(self, colortemp, duration) -> None: """Set bulb's color temperature.""" if colortemp and self.supported_features & SUPPORT_COLOR_TEMP: temp_in_k = mired_to_kelvin(colortemp) _LOGGER.debug("Setting color temp: %s K", temp_in_k) self._bulb.set_color_temp(temp_in_k, duration=duration)
async def async_turn_on(self, **kwargs: Any) -> None: """Instruct the light to turn on.""" brightness = kwargs.get(ATTR_BRIGHTNESS) hs_color = kwargs.get(ATTR_HS_COLOR) color_temp_mired = kwargs.get(ATTR_COLOR_TEMP) effect = kwargs.get(ATTR_EFFECT) transition = kwargs.get(ATTR_TRANSITION) if effect: if effect not in self.effect_list: raise ValueError( f"Attempting to apply effect not in the effect list: '{effect}'" ) await self._nanoleaf.set_effect(effect) elif hs_color: hue, saturation = hs_color await self._nanoleaf.set_hue(int(hue)) await self._nanoleaf.set_saturation(int(saturation)) elif color_temp_mired: await self._nanoleaf.set_color_temperature( mired_to_kelvin(color_temp_mired)) if transition: if brightness: # tune to the required brightness in n seconds await self._nanoleaf.set_brightness( int(brightness / 2.55), transition=int(kwargs[ATTR_TRANSITION])) else: # If brightness is not specified, assume full brightness await self._nanoleaf.set_brightness(100, transition=int(transition)) else: # If no transition is occurring, turn on the light await self._nanoleaf.turn_on() if brightness: await self._nanoleaf.set_brightness(int(brightness / 2.55))
def turn_on(self, **kwargs): """Turn the light on.""" _LOGGER.debug("Trying to turn on. ATTR:") _LOGGER.debug(kwargs) self._state = True with self._dev: if ATTR_HS_COLOR in kwargs: rgb = color_hs_to_RGB(*kwargs.get(ATTR_HS_COLOR)) self._rgb = rgb _LOGGER.debug("Trying to set color RGB: %i %i %i",rgb[0], rgb[1], rgb[2]) self._dev.set_color(rgb[0], rgb[1], rgb[2], int(self._brightness / 255 * 100)) if ATTR_COLOR_TEMP in kwargs: mireds = kwargs[ATTR_COLOR_TEMP] temp_in_k = mired_to_kelvin(mireds) _LOGGER.debug("Trying to set temp: %i",int(temp_in_k)) self._dev.set_temperature(int(temp_in_k),int(self._brightness / 255 * 100)) self._ct = mireds if ATTR_BRIGHTNESS in kwargs: brightness = kwargs[ATTR_BRIGHTNESS] _LOGGER.debug("Trying to set brightness: %i",int(brightness / 255 * 100)) self._dev.set_brightness(int(brightness / 255 * 100)) self._brightness = brightness # if we are just started without parameters, turn on. if ATTR_HS_COLOR not in kwargs and \ ATTR_COLOR_TEMP not in kwargs and \ ATTR_BRIGHTNESS not in kwargs: self._dev.turn_on()
def set_colortemp(self, colortemp, duration) -> None: """Set bulb's color temperature.""" if colortemp and COLOR_MODE_COLOR_TEMP in self.supported_color_modes: temp_in_k = mired_to_kelvin(colortemp) _LOGGER.debug("Setting color temp: %s K", temp_in_k) self._bulb.set_color_temp(temp_in_k, duration=duration, light_type=self.light_type)
async def _async_set_color_temp( self, color_temp_mireds: int, brightness: int | None, transition: int | None ) -> None: # Handle temp conversion mireds -> kelvin being slightly outside of valid range kelvin = mired_to_kelvin(color_temp_mireds) kelvin_range = self.device.valid_temperature_range color_tmp = max(kelvin_range.min, min(kelvin_range.max, kelvin)) _LOGGER.debug("Changing color temp to %s", color_tmp) await self.device.set_color_temp( color_tmp, brightness=brightness, transition=transition )
async def _change_color_temp(self, color_temp): _LOGGER.info(f"Mapped color temp: {color_temp}") constraint_color_temp = clamp(color_temp, self._min_merids, self._max_merids) kelvin_color_temp = clamp( mired_to_kelvin(constraint_color_temp), min_value=self._min_kelvin, max_value=self._max_kelvin, ) await self._execute_with_fallback( lambda: self._tapo_coordinator.api.set_color_temperature(kelvin_color_temp) )
def turn_on(self, **kwargs): """Turn the light on.""" if ATTR_COLOR_TEMP in kwargs: self.smartbulb.color_temp = \ mired_to_kelvin(kwargs[ATTR_COLOR_TEMP]) if ATTR_KELVIN in kwargs: self.smartbulb.color_temp = kwargs[ATTR_KELVIN] if ATTR_BRIGHTNESS in kwargs: brightness = kwargs.get(ATTR_BRIGHTNESS, self.brightness or 255) self.smartbulb.brightness = brightness_to_percentage(brightness) self.smartbulb.state = self.smartbulb.BULB_STATE_ON
def turn_on(self, **kwargs): """Turn on light""" brightness = None rgb = None color_temp = None effect_nr = None mode = None white_value = None if ATTR_BRIGHTNESS in kwargs: brightness = int(kwargs[ATTR_BRIGHTNESS] / 2.55) self._brightness = brightness if ATTR_WHITE_VALUE in kwargs: white_value = int(kwargs[ATTR_WHITE_VALUE]) self._white_value = white_value if ATTR_HS_COLOR in kwargs: red, green, blue = \ color_util.color_hs_to_RGB(*kwargs[ATTR_HS_COLOR]) rgb = [red, green, blue] self._rgb = rgb if ATTR_COLOR_TEMP in kwargs: color_temp = int(mired_to_kelvin(kwargs[ATTR_COLOR_TEMP])) if color_temp > 6500: color_temp = 6500 if color_temp < 3000: color_temp = 3000 self._color_temp = color_temp if ATTR_EFFECT in kwargs: affect_attr = kwargs.get(ATTR_EFFECT) effect = [ e for e in self._dev.effects_list if e['name'] == affect_attr ][0] #if 'mode' in effect: # mode = effect['mode'] if 'effect' in effect: effect_nr = effect['effect'] self._effect = effect_nr self._dev.turn_on(brightness=brightness, rgb=rgb, color_temp=color_temp, mode=mode, effect=effect_nr, white_value=white_value) self._state = True self._update_ha_state()
def turn_on(self, **kwargs): """Instruct the light to turn on.""" _LOGGER.debug("Turn on light %s %s", self._device.ip, kwargs) if not self.is_on: self._device.power_on = True if ATTR_BRIGHTNESS in kwargs and self.brightness != kwargs[ATTR_BRIGHTNESS]: self._device.brightness = kwargs[ATTR_BRIGHTNESS] if ATTR_COLOR_TEMP in kwargs and self.color_temp != kwargs[ATTR_COLOR_TEMP]: color_temp = mired_to_kelvin(kwargs[ATTR_COLOR_TEMP]) self._device.color_temperature = color_temp
def to_param(self): """Return a version that we can send to the bulb.""" if self.color_temp: color_temp = mired_to_kelvin(self.color_temp) else: color_temp = None return { LIGHT_STATE_ON_OFF: 1 if self.state else 0, LIGHT_STATE_BRIGHTNESS: brightness_to_percentage(self.brightness), LIGHT_STATE_COLOR_TEMP: color_temp, LIGHT_STATE_HUE: self.hs[0] if self.hs else 0, LIGHT_STATE_SATURATION: self.hs[1] if self.hs else 0, }
def turn_on(self, **kwargs): """Instruct the light to turn on.""" _LOGGER.debug("Turn on light %s %s", self._device.ip, kwargs) if not self.is_on: self._device.power_on = True if ATTR_BRIGHTNESS in kwargs and \ self.brightness != kwargs[ATTR_BRIGHTNESS]: self._device.brightness = kwargs[ATTR_BRIGHTNESS] if ATTR_COLOR_TEMP in kwargs and \ self.color_temp != kwargs[ATTR_COLOR_TEMP]: color_temp = mired_to_kelvin(kwargs[ATTR_COLOR_TEMP]) self._device.color_temperature = color_temp
def turn_on(self, **kwargs): """Turn the light on.""" _LOGGER.debug(f"Trying to turn on. with ATTR:{kwargs}") # First if brightness of dev to 0: turn off if ATTR_BRIGHTNESS in kwargs: brightness = kwargs[ATTR_BRIGHTNESS] if brightness == 0: _LOGGER.debug( "Lamp brightness to be set to 0... so turning off") self.turn_off() return else: brightness = self._brightness brightness_dev = int(round(brightness * 1.0 / 255 * 100)) # ATTR cannot be set while light is off, so turn it on first if not self._is_on: self._dev.turn_on() self._is_on = True if ATTR_HS_COLOR in kwargs: rgb = color_hs_to_RGB(*kwargs.get(ATTR_HS_COLOR)) self._rgb = rgb _LOGGER.debug( f"Trying to set color RGB:{rgb} with brighntess:{brightness_dev}" ) self._dev.set_color(*rgb, brightness=brightness_dev) self._brightness = brightness return if ATTR_COLOR_TEMP in kwargs: mireds = kwargs[ATTR_COLOR_TEMP] temp_in_k = int(mired_to_kelvin(mireds)) scaled_temp_in_k = self.scale_temp(temp_in_k) _LOGGER.debug( f"Trying to set temp:{scaled_temp_in_k} with brightness:{brightness_dev}" ) self._dev.set_temperature(scaled_temp_in_k, brightness=brightness_dev) self._ct = mireds self._brightness = brightness return if ATTR_BRIGHTNESS in kwargs: _LOGGER.debug(f"Trying to set brightness: {brightness_dev}") self._dev.set_brightness(brightness_dev) self._brightness = brightness return
def turn_on(self, **kwargs): brightness = None color_temp = None if ATTR_BRIGHTNESS in kwargs: brightness = int(kwargs[ATTR_BRIGHTNESS] / 2.55) if ATTR_COLOR_TEMP in kwargs: color_temp = int(mired_to_kelvin(kwargs[ATTR_COLOR_TEMP])) if color_temp > self._color_temp_max: color_temp = self._color_temp_max if color_temp < self._color_temp_min: color_temp = self._color_temp_min if color_temp: self._dev.turn_on(brightness, color_temp) else: self._dev.turn_on(brightness)
def set_value(self, **kwargs): brightness = None color_temp = None state = None if ATTR_BRIGHTNESS in kwargs: brightness = round(kwargs[ATTR_BRIGHTNESS] / 2.55) if ATTR_COLOR_TEMP in kwargs: color_temp = int(mired_to_kelvin(kwargs[ATTR_COLOR_TEMP])) if color_temp > self._color_temp_max: color_temp = self._color_temp_max if color_temp < self._color_temp_min: color_temp = self._color_temp_min if ATTR_STATE in kwargs: state = kwargs[ATTR_STATE] self._dev.set_values(state=state, brightness=brightness, color_temp=color_temp)
def turn_on(self, **kwargs): """Turn the light on.""" self.smartbulb.state = self.smartbulb.BULB_STATE_ON if ATTR_COLOR_TEMP in kwargs: self.smartbulb.color_temp = \ mired_to_kelvin(kwargs[ATTR_COLOR_TEMP]) if ATTR_KELVIN in kwargs: self.smartbulb.color_temp = kwargs[ATTR_KELVIN] if ATTR_BRIGHTNESS in kwargs: brightness = kwargs.get(ATTR_BRIGHTNESS, self.brightness or 255) self.smartbulb.brightness = brightness_to_percentage(brightness) if ATTR_RGB_COLOR in kwargs: rgb = kwargs.get(ATTR_RGB_COLOR) self.smartbulb.hsv = rgb_to_hsv(rgb)
def turn_on(self, **kwargs): """Turn the light on.""" self.smartbulb.state = self.smartbulb.BULB_STATE_ON if ATTR_COLOR_TEMP in kwargs: self.smartbulb.color_temp = \ mired_to_kelvin(kwargs[ATTR_COLOR_TEMP]) brightness = brightness_to_percentage( kwargs.get(ATTR_BRIGHTNESS, self.brightness or 255)) if ATTR_HS_COLOR in kwargs: hue, sat = kwargs.get(ATTR_HS_COLOR) hsv = (int(hue), int(sat), brightness) self.smartbulb.hsv = hsv elif ATTR_BRIGHTNESS in kwargs: self.smartbulb.brightness = brightness
def turn_on(self, **kwargs): """Turn the light on.""" self.smartbulb.state = SmartBulb.BULB_STATE_ON if ATTR_COLOR_TEMP in kwargs: self.smartbulb.color_temp = \ mired_to_kelvin(kwargs[ATTR_COLOR_TEMP]) brightness = brightness_to_percentage( kwargs.get(ATTR_BRIGHTNESS, self.brightness or 255)) if ATTR_HS_COLOR in kwargs: hue, sat = kwargs.get(ATTR_HS_COLOR) hsv = (int(hue), int(sat), brightness) self.smartbulb.hsv = hsv elif ATTR_BRIGHTNESS in kwargs: self.smartbulb.brightness = brightness
async def async_set_colortemp(self, colortemp, duration) -> None: """Set bulb's color temperature.""" if not colortemp or COLOR_MODE_COLOR_TEMP not in self.supported_color_modes: return temp_in_k = mired_to_kelvin(colortemp) if self.color_mode == COLOR_MODE_COLOR_TEMP and self.color_temp == colortemp: _LOGGER.debug("Color temp already set to: %s", temp_in_k) # Already set, and since we get pushed updates # we avoid setting it again to ensure we do not # hit the rate limit return await self._bulb.async_set_color_temp(temp_in_k, duration=duration, light_type=self.light_type)
def turn_on(self, **kwargs): """Turn the switch on.""" brightness = kwargs.get(ATTR_BRIGHTNESS) rgb_color = kwargs.get(ATTR_RGB_COLOR) color_temp_mired = kwargs.get(ATTR_COLOR_TEMP) state_kwargs = {} if rgb_color: state_kwargs['color_xy'] = color_util.color_RGB_to_xy(*rgb_color) if color_temp_mired: state_kwargs['color_kelvin'] = mired_to_kelvin(color_temp_mired) if brightness: state_kwargs['brightness'] = brightness / 255.0 self.wink.set_state(True, **state_kwargs)
def turn_on(self, **kwargs): """Turn the specified light on.""" brightness = kwargs.get(ATTR_BRIGHTNESS) colortemp = kwargs.get(ATTR_COLOR_TEMP) # pylint: disable=invalid-name hs = kwargs.get(ATTR_HS_COLOR) if brightness is not None: brightness = int(brightness * 100 / 255) else: if self._brightness is None: self._brightness = 100 brightness = self._brightness if colortemp is not None: self._colormode = False temp_in_k = mired_to_kelvin(colortemp) relative_temp = temp_in_k - EUFY_MIN_KELVIN temp = int(relative_temp * 100 / (EUFY_MAX_KELVIN - EUFY_MIN_KELVIN)) else: temp = None if hs is not None: rgb = color_util.color_hsv_to_RGB(hs[0], hs[1], brightness / 255 * 100) self._colormode = True elif self._colormode: rgb = color_util.color_hsv_to_RGB(self._hs[0], self._hs[1], brightness / 255 * 100) else: rgb = None try: self._bulb.set_state(power=True, brightness=brightness, temperature=temp, colors=rgb) except BrokenPipeError: self._bulb.connect() self._bulb.set_state(power=True, brightness=brightness, temperature=temp, colors=rgb)
def turn_on(self, **kwargs): """Instruct the light to turn on.""" self._light.on = True brightness = kwargs.get(ATTR_BRIGHTNESS) hs_color = kwargs.get(ATTR_HS_COLOR) color_temp_mired = kwargs.get(ATTR_COLOR_TEMP) effect = kwargs.get(ATTR_EFFECT) if hs_color: hue, saturation = hs_color self._light.hue = int(hue) self._light.saturation = int(saturation) if color_temp_mired: self._light.color_temperature = mired_to_kelvin(color_temp_mired) if brightness: self._light.brightness = int(brightness / 2.55) if effect: self._light.effect = effect
class TPLinkSmartBulb(CoordinatedTPLinkEntity, LightEntity): """Representation of a TPLink Smart Bulb.""" coordinator: TPLinkDataUpdateCoordinator def __init__( self, device: SmartDevice, coordinator: TPLinkDataUpdateCoordinator, ) -> None: """Initialize the switch.""" super().__init__(device, coordinator) # For backwards compat with pyHS100 self._attr_unique_id = self.device.mac.replace(":", "").upper() @async_refresh_after async def async_turn_on(self, **kwargs: Any) -> None: """Turn the light on.""" transition = kwargs.get(ATTR_TRANSITION) if (brightness := kwargs.get(ATTR_BRIGHTNESS)) is not None: brightness = round((brightness * 100.0) / 255.0) # Handle turning to temp mode if ATTR_COLOR_TEMP in kwargs: color_tmp = mired_to_kelvin(int(kwargs[ATTR_COLOR_TEMP])) _LOGGER.debug("Changing color temp to %s", color_tmp) await self.device.set_color_temp( color_tmp, brightness=brightness, transition=transition ) return # Handling turning to hs color mode if ATTR_HS_COLOR in kwargs: # TP-Link requires integers. hue, sat = tuple(int(val) for val in kwargs[ATTR_HS_COLOR]) await self.device.set_hsv(hue, sat, brightness, transition=transition) return # Fallback to adjusting brightness or turning the bulb on if brightness is not None: await self.device.set_brightness(brightness, transition=transition) else: await self.device.turn_on(transition=transition)
def turn_on(self, **kwargs): brightness = None color_temp = None if ATTR_BRIGHTNESS in kwargs: brightness = round(kwargs[ATTR_BRIGHTNESS] / 2.55) self._brightness = brightness if ATTR_COLOR_TEMP in kwargs: color_temp = int(mired_to_kelvin(kwargs[ATTR_COLOR_TEMP])) if color_temp > self._color_temp_max: color_temp = self._color_temp_max if color_temp < self._color_temp_min: color_temp = self._color_temp_min self._color_temp = color_temp if color_temp: self._dev.turn_on(brightness, color_temp) else: self._dev.turn_on(brightness) self._state = True self._update_ha_state()
def turn_on(self, **kwargs): """Turn the specified or all lights on.""" if not self.is_on: self._bulb.turn_on() if ATTR_RGB_COLOR in kwargs: rgb = kwargs[ATTR_RGB_COLOR] self._bulb.set_rgb_color(rgb[0], rgb[1], rgb[2]) self._rgb = [rgb[0], rgb[1], rgb[2]] if ATTR_COLOR_TEMP in kwargs: kelvin = int(mired_to_kelvin(kwargs[ATTR_COLOR_TEMP])) self._bulb.set_color_temperature(kelvin) self._ct = kelvin if ATTR_BRIGHTNESS in kwargs: bright = int(kwargs[ATTR_BRIGHTNESS] * 100 / 255) self._bulb.set_brightness(bright) self._bright = kwargs[ATTR_BRIGHTNESS]
def turn_on(self, **kwargs): """Turn the switch on.""" brightness = kwargs.get(ATTR_BRIGHTNESS) rgb_color = kwargs.get(ATTR_RGB_COLOR) color_temp_mired = kwargs.get(ATTR_COLOR_TEMP) state_kwargs = { } if rgb_color: state_kwargs['color_xy'] = color_util.color_RGB_to_xy(*rgb_color) if color_temp_mired: state_kwargs['color_kelvin'] = mired_to_kelvin(color_temp_mired) if brightness: state_kwargs['brightness'] = brightness / 255.0 self.wink.set_state(True, **state_kwargs)
def turn_on(self, **kwargs): """Turn the light on.""" self._state = True self.smartbulb.state = SmartBulb.BULB_STATE_ON if ATTR_COLOR_TEMP in kwargs: self._color_temp = kwargs.get(ATTR_COLOR_TEMP) self.smartbulb.color_temp = mired_to_kelvin(self._color_temp) brightness_value = kwargs.get(ATTR_BRIGHTNESS, self.brightness or 255) brightness_pct = brightness_to_percentage(brightness_value) if ATTR_HS_COLOR in kwargs: self._hs = kwargs.get(ATTR_HS_COLOR) hue, sat = self._hs hsv = (int(hue), int(sat), brightness_pct) self.smartbulb.hsv = hsv elif ATTR_BRIGHTNESS in kwargs: self._brightness = brightness_value self.smartbulb.brightness = brightness_pct
def _get_hs_from_properties(self): rgb = self._properties.get('rgb', None) color_mode = self._properties.get('color_mode', None) if not rgb or not color_mode: return None color_mode = int(color_mode) if color_mode == 2: # color temperature temp_in_k = mired_to_kelvin(self._color_temp) return color_util.color_temperature_to_hs(temp_in_k) if color_mode == 3: # hsv hue = int(self._properties.get('hue')) sat = int(self._properties.get('sat')) return (hue / 360 * 65536, sat / 100 * 255) rgb = int(rgb) blue = rgb & 0xff green = (rgb >> 8) & 0xff red = (rgb >> 16) & 0xff return color_util.color_RGB_to_hs(red, green, blue)
def turn_on(self, **kwargs): """Turn the specified light on.""" brightness = kwargs.get(ATTR_BRIGHTNESS) colortemp = kwargs.get(ATTR_COLOR_TEMP) # pylint: disable=invalid-name hs = kwargs.get(ATTR_HS_COLOR) if brightness is not None: brightness = int(brightness * 100 / 255) else: if self._brightness is None: self._brightness = 100 brightness = self._brightness if colortemp is not None: self._colormode = False temp_in_k = mired_to_kelvin(colortemp) relative_temp = temp_in_k - EUFY_MIN_KELVIN temp = int(relative_temp * 100 / (EUFY_MAX_KELVIN - EUFY_MIN_KELVIN)) else: temp = None if hs is not None: rgb = color_util.color_hsv_to_RGB( hs[0], hs[1], brightness / 255 * 100) self._colormode = True elif self._colormode: rgb = color_util.color_hsv_to_RGB( self._hs[0], self._hs[1], brightness / 255 * 100) else: rgb = None try: self._bulb.set_state(power=True, brightness=brightness, temperature=temp, colors=rgb) except BrokenPipeError: self._bulb.connect() self._bulb.set_state(power=True, brightness=brightness, temperature=temp, colors=rgb)
def turn_on(self, **kwargs): """Turn on light""" brightness = None rgb = None temp = None effect_nr = None mode = None white_value = None if ATTR_BRIGHTNESS in kwargs: brightness = int(kwargs[ATTR_BRIGHTNESS] / 2.55) if ATTR_WHITE_VALUE in kwargs: white_value = int(kwargs[ATTR_WHITE_VALUE]) if ATTR_HS_COLOR in kwargs: red, green, blue = \ color_util.color_hs_to_RGB(*kwargs[ATTR_HS_COLOR]) rgb = [red, green, blue] if ATTR_COLOR_TEMP in kwargs: temp = int(mired_to_kelvin(kwargs[ATTR_COLOR_TEMP])) if ATTR_EFFECT in kwargs: affect_attr = kwargs.get(ATTR_EFFECT) effect = [e for e in EFFECT_LIST if e['name'] == affect_attr][0] if 'mode' in effect: mode = effect['mode'] if 'effect' in effect: effect_nr = effect['effect'] self._dev.turn_on(brightness=brightness, rgb=rgb, temp=temp, mode=mode, effect=effect_nr, white_value=white_value)
async def async_turn_on(self, **kwargs) -> None: """Instruct the light to turn on.""" _LOGGER.debug("Turn on light %s %s", self._device.ip, kwargs) if not self.is_on: if self._model == MODEL_K2_LIGHT: await self._device.turn_on_light() else: await self._device.turn_on() if ATTR_BRIGHTNESS in kwargs and \ self.brightness != kwargs[ATTR_BRIGHTNESS]: await self._device.set_brightness(int(round(kwargs[ATTR_BRIGHTNESS] * 100 / 255))) if ATTR_COLOR_TEMP in kwargs and \ self.color_temp != kwargs[ATTR_COLOR_TEMP]: await self._device.set_ct(mired_to_kelvin(kwargs[ATTR_COLOR_TEMP])) if ATTR_HS_COLOR in kwargs and \ self.hs_color != kwargs[ATTR_HS_COLOR]: hs_color = kwargs[ATTR_HS_COLOR] rgb_color = hs_to_RGB(*hs_color) await self._device.set_color(*rgb_color)
def _get_rgb_from_properties(self): rgb = self._properties.get('rgb', None) color_mode = self._properties.get('color_mode', None) if not rgb or not color_mode: return rgb color_mode = int(color_mode) if color_mode == 2: # color temperature temp_in_k = mired_to_kelvin(self._color_temp) return color_temperature_to_rgb(temp_in_k) if color_mode == 3: # hsv hue = int(self._properties.get('hue')) sat = int(self._properties.get('sat')) val = int(self._properties.get('bright')) return hsv_to_rgb((hue, sat, val)) rgb = int(rgb) blue = rgb & 0xff green = (rgb >> 8) & 0xff red = (rgb >> 16) & 0xff return red, green, blue
def turn_on(self, **kwargs): """Turn the switch on.""" brightness = kwargs.get(ATTR_BRIGHTNESS) hs_color = kwargs.get(ATTR_HS_COLOR) color_temp_mired = kwargs.get(ATTR_COLOR_TEMP) state_kwargs = {} if hs_color: if self.wink.supports_xy_color(): xy_color = color_util.color_hs_to_xy(*hs_color) state_kwargs['color_xy'] = xy_color if self.wink.supports_hue_saturation(): state_kwargs['color_hue_saturation'] = hs_color if color_temp_mired: state_kwargs['color_kelvin'] = mired_to_kelvin(color_temp_mired) if brightness: state_kwargs['brightness'] = brightness / 255.0 self.wink.set_state(True, **state_kwargs)