def _turn_on_rgb_and_w(self, hex_template, **kwargs): """Turn on RGB or RGBW child device.""" rgb = list(color_util.color_hs_to_RGB(*self._hs)) white = self._white hex_color = self._values.get(self.value_type) hs_color = kwargs.get(ATTR_HS_COLOR) if hs_color is not None: new_rgb = color_util.color_hs_to_RGB(*hs_color) else: new_rgb = None new_white = kwargs.get(ATTR_WHITE_VALUE) if new_rgb is None and new_white is None: return if new_rgb is not None: rgb = list(new_rgb) if hex_template == '%02x%02x%02x%02x': if new_white is not None: rgb.append(new_white) else: rgb.append(white) hex_color = hex_template % tuple(rgb) if len(rgb) > 3: white = rgb.pop() self.gateway.set_child_value( self.node_id, self.child_id, self.value_type, hex_color) if self.gateway.optimistic: # optimistically assume that light has changed state self._hs = color_util.color_RGB_to_hs(*rgb) self._white = white self._values[self.value_type] = hex_color
def turn_on(self, **kwargs): """Turn the entity on.""" _LOGGER.debug("turn_on: {} {} {}".format(self._name, self._state, kwargs)) self._light.nightlight_on() if ATTR_BRIGHTNESS in kwargs: self._light.set_nightlight_brightness(kwargs[ATTR_BRIGHTNESS]) if ATTR_HS_COLOR in kwargs: rgb = color_util.color_hs_to_RGB(*kwargs[ATTR_HS_COLOR]) self._light.set_nightlight_rgb(red=rgb[0], green=rgb[1], blue=rgb[2]) if ATTR_COLOR_TEMP in kwargs: kelvin = color_util.color_temperature_mired_to_kelvin( kwargs.get(ATTR_COLOR_TEMP)) self._light.set_nightlight_color_temperature(kelvin) if ATTR_EFFECT in kwargs: effect = kwargs[ATTR_EFFECT] if effect == LIGHT_EFFECT_RAINBOW: self._light.set_nightlight_mode("rainbow") else: self._light.set_nightlight_mode("rgb")
def async_turn_on(self, **kwargs): """Instruct the light to turn on. Move to using one method on the DMX class to set/fade either a single channel or group of channels """ self._state = STATE_ON transition = kwargs.get(ATTR_TRANSITION, self._fade_time) # Update state from service call if ATTR_BRIGHTNESS in kwargs: self._brightness = kwargs[ATTR_BRIGHTNESS] if ATTR_HS_COLOR in kwargs: self._rgb = color_util.color_hs_to_RGB(*kwargs[ATTR_HS_COLOR]) # self._white_value = color_rgb_to_rgbw(*self._rgb)[3] if ATTR_WHITE_VALUE in kwargs: self._white_value = kwargs[ATTR_WHITE_VALUE] if ATTR_COLOR_TEMP in kwargs: self._color_temp = kwargs[ATTR_COLOR_TEMP] logging.debug("Setting light '%s' to %s with transition time %i", self._name, repr(self.dmx_values), transition) asyncio.ensure_future( self._controller.set_channels_async(self._channels, self.dmx_values, transition=transition)) self.async_schedule_update_ha_state()
def turn_on(self, **kwargs) -> None: if ATTR_BRIGHTNESS in kwargs: self.hass.bus.async_fire( SENDDOMAIN, dict(uuid=self.uuidAction, value='temp({},{})'.format( int(to_loxone_level(kwargs[ATTR_BRIGHTNESS])), int(to_loxone_color_temp(self._color_temp))))) elif ATTR_COLOR_TEMP in kwargs: self.hass.bus.async_fire( SENDDOMAIN, dict(uuid=self.uuidAction, value='temp({},{})'.format( self._position, int(to_loxone_color_temp(kwargs[ATTR_COLOR_TEMP]))))) elif ATTR_HS_COLOR in kwargs: r, g, b = color_util.color_hs_to_RGB(kwargs[ATTR_HS_COLOR][0], kwargs[ATTR_HS_COLOR][1]) h, s, v = color_util.color_RGB_to_hsv(r, g, b) self.hass.bus.async_fire( SENDDOMAIN, dict(uuid=self.uuidAction, value='hsv({},{},{})'.format(h, s, v))) else: self.hass.bus.async_fire( SENDDOMAIN, dict(uuid=self.uuidAction, value="setBrightness/1")) self.schedule_update_ha_state()
def state_attributes(self): """Return optional state attributes.""" data = {} supported_features = self.supported_features if supported_features & SUPPORT_COLOR_TEMP: data[ATTR_MIN_MIREDS] = self.min_mireds data[ATTR_MAX_MIREDS] = self.max_mireds if supported_features & SUPPORT_EFFECT: data[ATTR_EFFECT_LIST] = self.effect_list if self.is_on: if supported_features & SUPPORT_BRIGHTNESS: data[ATTR_BRIGHTNESS] = self.brightness if supported_features & SUPPORT_COLOR_TEMP: data[ATTR_COLOR_TEMP] = self.color_temp if supported_features & SUPPORT_COLOR and self.hs_color: # pylint: disable=unsubscriptable-object,not-an-iterable hs_color = self.hs_color data[ATTR_HS_COLOR] = (round(hs_color[0], 3), round(hs_color[1], 3)) data[ATTR_RGB_COLOR] = color_util.color_hs_to_RGB(*hs_color) data[ATTR_XY_COLOR] = color_util.color_hs_to_xy(*hs_color) if supported_features & SUPPORT_WHITE_VALUE: data[ATTR_WHITE_VALUE] = self.white_value if supported_features & SUPPORT_EFFECT: data[ATTR_EFFECT] = self.effect return {key: val for key, val in data.items() if val is not None}
def async_turn_on(self, **kwargs): """ Instruct the light to turn on. After adding "self._light_data.hexcolor is not None" for ATTR_HS_COLOR, this also supports Philips Hue bulbs. """ if ATTR_HS_COLOR in kwargs and self._light_data.hex_color is not None: rgb = color_util.color_hs_to_RGB(*kwargs[ATTR_HS_COLOR]) yield from self._api(self._light.light_control.set_rgb_color(*rgb)) elif ATTR_COLOR_TEMP in kwargs and \ self._light_data.hex_color is not None and \ self._temp_supported: kelvin = color_util.color_temperature_mired_to_kelvin( kwargs[ATTR_COLOR_TEMP]) yield from self._api(self._light_control.set_kelvin_color(kelvin)) keys = {} if ATTR_TRANSITION in kwargs: keys['transition_time'] = int(kwargs[ATTR_TRANSITION]) * 10 if ATTR_BRIGHTNESS in kwargs: if kwargs[ATTR_BRIGHTNESS] == 255: kwargs[ATTR_BRIGHTNESS] = 254 yield from self._api( self._light_control.set_dimmer(kwargs[ATTR_BRIGHTNESS], **keys)) else: yield from self._api(self._light_control.set_state(True))
def set_flash(self, flash) -> None: """Activate flash.""" if flash: if int(self._bulb.last_properties["color_mode"]) != 1: _LOGGER.error("Flash supported currently only in RGB mode") return transition = int(self.config[CONF_TRANSITION]) if flash == FLASH_LONG: count = 1 duration = transition * 5 if flash == FLASH_SHORT: count = 1 duration = transition * 2 red, green, blue = color_util.color_hs_to_RGB(*self._hs) transitions = [] transitions.append( RGBTransition(255, 0, 0, brightness=10, duration=duration)) transitions.append(SleepTransition(duration=transition)) transitions.append( RGBTransition(red, green, blue, brightness=self.brightness, duration=duration)) flow = Flow(count=count, transitions=transitions) try: self._bulb.start_flow(flow, light_type=self.light_type) except BulbException as ex: _LOGGER.error("Unable to set flash: %s", ex)
def turn_on(self, **kwargs): """Turn the device on.""" transition = int(kwargs.get(ATTR_TRANSITION, 0) * 10) if ATTR_EFFECT in kwargs: self.play_effect(kwargs[ATTR_EFFECT], transition) return if ATTR_HS_COLOR in kwargs: self._rgb_color = color_util.color_hs_to_RGB( *kwargs[ATTR_HS_COLOR]) self._luminary.set_rgb(*self._rgb_color, transition) if ATTR_COLOR_TEMP in kwargs: self._color_temp = kwargs[ATTR_COLOR_TEMP] self._luminary.set_temperature( int( color_util.color_temperature_mired_to_kelvin( self._color_temp)), transition, ) self._is_on = True if ATTR_BRIGHTNESS in kwargs: self._brightness = kwargs[ATTR_BRIGHTNESS] self._luminary.set_luminance(int(self._brightness / 2.55), transition) else: self._luminary.set_onoff(True)
def turn_on(self, **kwargs: Any) -> None: """Turn the light on.""" if not self.is_on: self._lamp.switch(True) if ATTR_BRIGHTNESS in kwargs: brightness = int((kwargs[ATTR_BRIGHTNESS] / 255.0) * 200.0) self._lamp.brightness(brightness) return if ATTR_HS_COLOR in kwargs: rgb = color_util.color_hs_to_RGB(*kwargs[ATTR_HS_COLOR]) self._lamp.rgb(*rgb) return if ATTR_COLOR_TEMP in kwargs: kelvin = int( color_util.color_temperature_mired_to_kelvin(kwargs[ATTR_COLOR_TEMP]) ) self._lamp.white(kelvin) return if ATTR_EFFECT in kwargs: effect = kwargs[ATTR_EFFECT] self._lamp.effect(effect) return
def state_attributes(self): """Return state attributes.""" if not self.is_on: return None data = {} supported_features = self.supported_features if supported_features & SUPPORT_BRIGHTNESS: data[ATTR_BRIGHTNESS] = self.brightness if supported_features & SUPPORT_COLOR_TEMP: data[ATTR_COLOR_TEMP] = self.color_temp if supported_features & SUPPORT_COLOR and self.hs_color: hs_color = self.hs_color data[ATTR_HS_COLOR] = (round(hs_color[0], 3), round(hs_color[1], 3)) data[ATTR_RGB_COLOR] = color_util.color_hs_to_RGB(*hs_color) data[ATTR_XY_COLOR] = color_util.color_hs_to_xy(*hs_color) if supported_features & SUPPORT_WHITE_VALUE: data[ATTR_WHITE_VALUE] = self.white_value if supported_features & SUPPORT_EFFECT: data[ATTR_EFFECT] = self.effect return {key: val for key, val in data.items() if val is not None}
def turn_on(self, **kwargs): """Turn the device on.""" rgbw = None if ATTR_WHITE_VALUE in kwargs: self._white = kwargs[ATTR_WHITE_VALUE] if ATTR_COLOR_TEMP in kwargs: # Color temperature. With the AEOTEC ZW098 bulb, only two color # temperatures are supported. The warm and cold channel values # indicate brightness for warm/cold color temperature. if self._zw098: if kwargs[ATTR_COLOR_TEMP] > TEMP_MID_HASS: self._ct = TEMP_WARM_HASS rgbw = '#000000ff00' else: self._ct = TEMP_COLD_HASS rgbw = '#00000000ff' elif ATTR_HS_COLOR in kwargs: self._hs = kwargs[ATTR_HS_COLOR] if ATTR_WHITE_VALUE in kwargs or ATTR_HS_COLOR in kwargs: rgbw = '#' for colorval in color_util.color_hs_to_RGB(*self._hs): rgbw += format(colorval, '02x') if self._white is not None: rgbw += format(self._white, '02x') + '00' else: rgbw += '0000' if rgbw and self.values.color: self.values.color.data = rgbw super().turn_on(**kwargs)
async def async_turn_on(self, **kwargs) -> None: capacity = 0 # Color is taken from either of these 2 values, but not both. if ATTR_HS_COLOR in kwargs: h, s = kwargs[ATTR_HS_COLOR] self._light["rgb"] = rgb_to_int(color_hs_to_RGB(h, s)) self._light.pop("temperature", None) capacity |= CAPACITY_RGB elif ATTR_COLOR_TEMP in kwargs: mired = kwargs[ATTR_COLOR_TEMP] norm_value = (mired - self.min_mireds) / (self.max_mireds - self.min_mireds) temperature = 100 - (norm_value * 100) self._light["temperature"] = temperature self._light.pop("rgb", None) capacity |= CAPACITY_TEMPERATURE if self._capacity & CAPACITY_LUMINANCE: capacity |= CAPACITY_LUMINANCE # Brightness must always be set, so take previous luminance if not explicitly set now. if ATTR_BRIGHTNESS in kwargs: self._light["luminance"] = kwargs[ATTR_BRIGHTNESS] * 100 / 255 self._light["capacity"] = capacity self._internal_send(onoff=1) return
def __init__(self, **kwargs): LoxoneEntity.__init__(self, **kwargs) self._async_add_devices = kwargs['async_add_devices'] self._position = 0 self._color_temp = 0 self._rgb_color = color_util.color_hs_to_RGB(0, 0) self.light_controller_id = kwargs.get("lightcontroller_id", None)
async def async_turn_on(self, **kwargs): """Instruct the light to turn on.""" rgb = None if ATTR_RGB_COLOR in kwargs: rgb = kwargs.get(ATTR_RGB_COLOR) if ATTR_HS_COLOR in kwargs: rgb = color_utils.color_hs_to_RGB( kwargs[ATTR_HS_COLOR][0], kwargs[ATTR_HS_COLOR][1] ) brightness = None if ATTR_BRIGHTNESS in kwargs: brightness = kwargs.get(ATTR_BRIGHTNESS) colortemp = None if ATTR_COLOR_TEMP in kwargs: kelvin = color_utils.color_temperature_mired_to_kelvin( kwargs[ATTR_COLOR_TEMP] ) colortemp = kelvin sceneid = None if ATTR_EFFECT in kwargs: sceneid = self._light.get_id_from_scene_name(kwargs[ATTR_EFFECT]) if sceneid == 1000: # rhythm pilot = PilotBuilder() else: pilot = PilotBuilder( rgb=rgb, brightness=brightness, colortemp=colortemp, scene=sceneid ) await self._light.turn_on(pilot)
def state_attributes(self): """Return optional state attributes.""" data = {} supported_features = self.supported_features if supported_features & SUPPORT_COLOR_TEMP: data[ATTR_MIN_MIREDS] = self.min_mireds data[ATTR_MAX_MIREDS] = self.max_mireds if self.is_on: if supported_features & SUPPORT_BRIGHTNESS: data[ATTR_BRIGHTNESS] = self.brightness if supported_features & SUPPORT_COLOR_TEMP: data[ATTR_COLOR_TEMP] = self.color_temp if self.supported_features & SUPPORT_COLOR and self.hs_color: # pylint: disable=unsubscriptable-object,not-an-iterable hs_color = self.hs_color data[ATTR_HS_COLOR] = ( round(hs_color[0], 3), round(hs_color[1], 3), ) data[ATTR_RGB_COLOR] = color_util.color_hs_to_RGB(*hs_color) data[ATTR_XY_COLOR] = color_util.color_hs_to_xy(*hs_color) if supported_features & SUPPORT_WHITE_VALUE: data[ATTR_WHITE_VALUE] = self.white_value if supported_features & SUPPORT_EFFECT: data[ATTR_EFFECT_LIST] = self.effect_list data[ATTR_EFFECT] = self.effect return {key: val for key, val in data.items() if val is not None}
def turn_on(self, **kwargs): """Instruct the light to turn on.""" import lw12 self._light.light_on() if ATTR_HS_COLOR in kwargs: self._rgb_color = color_util.color_hs_to_RGB( *kwargs[ATTR_HS_COLOR]) self._light.set_color(*self._rgb_color) self._effect = None if ATTR_BRIGHTNESS in kwargs: self._brightness = kwargs.get(ATTR_BRIGHTNESS) brightness = int(self._brightness / 255 * 100) self._light.set_light_option(lw12.LW12_LIGHT.BRIGHTNESS, brightness) if ATTR_EFFECT in kwargs: self._effect = kwargs[ATTR_EFFECT].replace(' ', '_').upper() # Check if a known and supported effect was selected. if self._effect in [eff.name for eff in lw12.LW12_EFFECT]: # Selected effect is supported and will be applied. self._light.set_effect(lw12.LW12_EFFECT[self._effect]) else: # Unknown effect was set, recover by disabling the effect # mode and log an error. _LOGGER.error("Unknown effect selected: %s", self._effect) self._effect = None if ATTR_TRANSITION in kwargs: transition_speed = int(kwargs[ATTR_TRANSITION]) self._light.set_light_option(lw12.LW12_LIGHT.FLASH, transition_speed) self._state = True
def turn_on(self, **kwargs): """Turn the device on.""" rgbw = None if ATTR_WHITE_VALUE in kwargs: self._white = kwargs[ATTR_WHITE_VALUE] if ATTR_COLOR_TEMP in kwargs: # Color temperature. With the AEOTEC ZW098 bulb, only two color # temperatures are supported. The warm and cold channel values # indicate brightness for warm/cold color temperature. if self._zw098: if kwargs[ATTR_COLOR_TEMP] > TEMP_MID_HASS: self._ct = TEMP_WARM_HASS rgbw = '#000000ff00' else: self._ct = TEMP_COLD_HASS rgbw = '#00000000ff' elif ATTR_HS_COLOR in kwargs: self._hs = kwargs[ATTR_HS_COLOR] if ATTR_WHITE_VALUE in kwargs or ATTR_HS_COLOR in kwargs: rgbw = '#' for colorval in color_util.color_hs_to_RGB(*self._hs): rgbw += format(colorval, '02x') if self._white is not None: rgbw += format(self._white, '02x') + '00' else: rgbw += '0000' if rgbw and self.values.color: self.values.color.data = rgbw super().turn_on(**kwargs)
def turn_on(self, **kwargs): """Turn the device on.""" if ATTR_TRANSITION in kwargs: transition = int(kwargs[ATTR_TRANSITION] * 10) else: transition = 0 if ATTR_BRIGHTNESS in kwargs: self._brightness = kwargs[ATTR_BRIGHTNESS] self._luminary.set_luminance( int(self._brightness / 2.55), transition) else: self._luminary.set_onoff(1) if ATTR_HS_COLOR in kwargs: red, green, blue = \ color_util.color_hs_to_RGB(*kwargs[ATTR_HS_COLOR]) self._luminary.set_rgb(red, green, blue, transition) if ATTR_COLOR_TEMP in kwargs: color_t = kwargs[ATTR_COLOR_TEMP] kelvin = int(color_temperature_mired_to_kelvin(color_t)) self._luminary.set_temperature(kelvin, transition) if ATTR_EFFECT in kwargs: effect = kwargs.get(ATTR_EFFECT) if effect == EFFECT_RANDOM: self._luminary.set_rgb( random.randrange(0, 255), random.randrange(0, 255), random.randrange(0, 255), transition) self.schedule_update_ha_state()
def async_turn_on(self, **kwargs): """ Instruct the light to turn on. After adding "self._light_data.hexcolor is not None" for ATTR_HS_COLOR, this also supports Philips Hue bulbs. """ if ATTR_HS_COLOR in kwargs and self._light_data.hex_color is not None: rgb = color_util.color_hs_to_RGB(*kwargs[ATTR_HS_COLOR]) yield from self._api( self._light.light_control.set_rgb_color(*rgb)) elif ATTR_COLOR_TEMP in kwargs and \ self._light_data.hex_color is not None and \ self._temp_supported: kelvin = color_util.color_temperature_mired_to_kelvin( kwargs[ATTR_COLOR_TEMP]) yield from self._api( self._light_control.set_kelvin_color(kelvin)) keys = {} if ATTR_TRANSITION in kwargs: keys['transition_time'] = int(kwargs[ATTR_TRANSITION]) * 10 if ATTR_BRIGHTNESS in kwargs: if kwargs[ATTR_BRIGHTNESS] == 255: kwargs[ATTR_BRIGHTNESS] = 254 yield from self._api( self._light_control.set_dimmer(kwargs[ATTR_BRIGHTNESS], **keys)) else: yield from self._api( self._light_control.set_state(True))
def state_attributes(self): """Return optional state attributes.""" data = {} if self.supported_features & SUPPORT_COLOR_TEMP: data[ATTR_MIN_MIREDS] = self.min_mireds data[ATTR_MAX_MIREDS] = self.max_mireds if self.is_on: for prop, attr in PROP_TO_ATTR.items(): value = getattr(self, prop) if value is not None: data[attr] = value # Expose current color also as RGB and XY if ATTR_HS_COLOR in data: data[ATTR_RGB_COLOR] = color_util.color_hs_to_RGB( *data[ATTR_HS_COLOR]) data[ATTR_XY_COLOR] = color_util.color_hs_to_xy( *data[ATTR_HS_COLOR]) data[ATTR_HS_COLOR] = ( round(data[ATTR_HS_COLOR][0], 3), round(data[ATTR_HS_COLOR][1], 3), ) return data
def turn_on(self, **kwargs): """Instruct the light to turn on, optionally set colour/brightness.""" # when no arguments, just turn light on (full brightness) if not kwargs: self._light.turn_on() else: if ATTR_HS_COLOR in kwargs and ATTR_BRIGHTNESS in kwargs: rgb = color_util.color_hs_to_RGB(*kwargs[ATTR_HS_COLOR]) bright = int(kwargs[ATTR_BRIGHTNESS] / 255 * 100) self._light.set_all(rgb[0], rgb[1], rgb[2], bright) elif ATTR_HS_COLOR in kwargs: rgb = color_util.color_hs_to_RGB(*kwargs[ATTR_HS_COLOR]) self._light.set_rgb_color(rgb[0], rgb[1], rgb[2]) elif ATTR_BRIGHTNESS in kwargs: bright = int(kwargs[ATTR_BRIGHTNESS] / 255 * 100) self._light.set_brightness(bright)
def turn_on(self, **kwargs): """Instruct the light to turn on.""" import lw12 self._light.light_on() if ATTR_HS_COLOR in kwargs: self._rgb_color = color_util.color_hs_to_RGB( *kwargs[ATTR_HS_COLOR]) self._light.set_color(*self._rgb_color) self._effect = None if ATTR_BRIGHTNESS in kwargs: self._brightness = kwargs.get(ATTR_BRIGHTNESS) brightness = int(self._brightness / 255 * 100) self._light.set_light_option(lw12.LW12_LIGHT.BRIGHTNESS, brightness) if ATTR_EFFECT in kwargs: self._effect = kwargs[ATTR_EFFECT].replace(' ', '_').upper() # Check if a known and supported effect was selected. if self._effect in [eff.name for eff in lw12.LW12_EFFECT]: # Selected effect is supported and will be applied. self._light.set_effect(lw12.LW12_EFFECT[self._effect]) else: # Unknown effect was set, recover by disabling the effect # mode and log an error. _LOGGER.error("Unknown effect selected: %s", self._effect) self._effect = None if ATTR_TRANSITION in kwargs: transition_speed = int(kwargs[ATTR_TRANSITION]) self._light.set_light_option(lw12.LW12_LIGHT.FLASH, transition_speed) self._state = True
def turn_on(self, **kwargs): """Turn the specified or all lights on.""" if not self.is_on: self._bulb.turnOn() hs_color = kwargs.get(ATTR_HS_COLOR) if hs_color: rgb = color_util.color_hs_to_RGB(*hs_color) else: rgb = None brightness = kwargs.get(ATTR_BRIGHTNESS) effect = kwargs.get(ATTR_EFFECT) if rgb is not None and brightness is not None: self._bulb.setRgb(*tuple(rgb), brightness=brightness) elif rgb is not None: self._bulb.setRgb(*tuple(rgb)) elif brightness is not None: if self._mode == MODE_RGBW: self._bulb.setWarmWhite255(brightness) elif self._mode == MODE_RGB: (red, green, blue) = self._bulb.getRgb() self._bulb.setRgb(red, green, blue, brightness=brightness) elif effect == EFFECT_RANDOM: self._bulb.setRgb(random.randint(0, 255), random.randint(0, 255), random.randint(0, 255)) elif effect in EFFECT_MAP: self._bulb.setPresetPattern(EFFECT_MAP[effect], 50)
def set_flash(self, flash) -> None: """Activate flash.""" if flash: from yeelight import (RGBTransition, SleepTransition, Flow, BulbException) if self._bulb.last_properties["color_mode"] != 1: _LOGGER.error("Flash supported currently only in RGB mode.") return transition = int(self.config[CONF_TRANSITION]) if flash == FLASH_LONG: count = 1 duration = transition * 5 if flash == FLASH_SHORT: count = 1 duration = transition * 2 red, green, blue = color_util.color_hs_to_RGB(*self._hs) transitions = list() transitions.append( RGBTransition(255, 0, 0, brightness=10, duration=duration)) transitions.append(SleepTransition( duration=transition)) transitions.append( RGBTransition(red, green, blue, brightness=self.brightness, duration=duration)) flow = Flow(count=count, transitions=transitions) try: self._bulb.start_flow(flow) except BulbException as ex: _LOGGER.error("Unable to set flash: %s", ex)
async def async_turn_on(self, **kwargs: Any) -> None: """Turn the device on.""" # RGB/HS color hs_color = kwargs.get(ATTR_HS_COLOR) if hs_color is not None and self._supports_color: red, green, blue = color_util.color_hs_to_RGB(*hs_color) colors = { ColorComponent.RED: red, ColorComponent.GREEN: green, ColorComponent.BLUE: blue, } if self._supports_color_temp: # turn of white leds when setting rgb colors[ColorComponent.WARM_WHITE] = 0 colors[ColorComponent.COLD_WHITE] = 0 await self._async_set_colors(colors) # Color temperature color_temp = kwargs.get(ATTR_COLOR_TEMP) if color_temp is not None and self._supports_color_temp: # Limit color temp to min/max values cold = max( 0, min( 255, round((self._max_mireds - color_temp) / (self._max_mireds - self._min_mireds) * 255), ), ) warm = 255 - cold await self._async_set_colors({ # turn off color leds when setting color temperature ColorComponent.RED: 0, ColorComponent.GREEN: 0, ColorComponent.BLUE: 0, ColorComponent.WARM_WHITE: warm, ColorComponent.COLD_WHITE: cold, }) # White value white_value = kwargs.get(ATTR_WHITE_VALUE) if white_value is not None and self._supports_white_value: # white led brightness is controlled by white level # rgb leds (if any) can be on at the same time await self._async_set_colors({ ColorComponent.WARM_WHITE: white_value, ColorComponent.COLD_WHITE: white_value, }) # set brightness await self._async_set_brightness(kwargs.get(ATTR_BRIGHTNESS), kwargs.get(ATTR_TRANSITION))
def hs_to_alexa_color( hs: Optional[Tuple[float, float]] ) -> Tuple[Optional[Tuple[float, float]], Optional[Text]]: """Convert a given hue/saturation value into the closest Alexa color.""" if hs is None: return None, None hue, saturation = hs return rgb_to_alexa_color(color_hs_to_RGB(hue, saturation))
def _turn_on(self, **kwargs: Any) -> None: """Turn the specified or all lights on.""" if not self.is_on: self._bulb.turnOn() if hs_color := kwargs.get(ATTR_HS_COLOR): rgb: tuple[int, int, int] | None = color_util.color_hs_to_RGB( *hs_color)
def turn_on(self, **kwargs): """Turn the specified or all lights on.""" if not self.is_on: self._bulb.turnOn() hs_color = kwargs.get(ATTR_HS_COLOR) if hs_color: rgb = color_util.color_hs_to_RGB(*hs_color) else: rgb = None brightness = kwargs.get(ATTR_BRIGHTNESS) effect = kwargs.get(ATTR_EFFECT) # brightness percent is not passed as param argument, its calculate as brightness, so wee need to calc back to % # 128 = 50 default effect_speed = int(kwargs.get(ATTR_BRIGHTNESS, 128) / 255 * 100) white = kwargs.get(ATTR_WHITE_VALUE) # Show warning if effect set with rgb, brightness, or white level #if effect and (brightness or white or rgb): if effect and (white or rgb): _LOGGER.warning("RGB, brightness and white level are ignored when" " an effect is specified for a flux bulb") # Random color effect if effect == EFFECT_RANDOM: self._bulb.setRgb(random.randint(0, 255), random.randint(0, 255), random.randint(0, 255)) return # Effect selection if effect in EFFECT_MAP: self._bulb.setPresetPattern(EFFECT_MAP[effect], effect_speed) return # Preserve current brightness on color/white level change if brightness is None: brightness = self.brightness # Preserve color on brightness/white level change if rgb is None: rgb = self._bulb.getRgb() if white is None and self._mode == MODE_RGBW: white = self.white_value # handle W only mode (use brightness instead of white value) if self._mode == MODE_WHITE: self._bulb.setRgbw(0, 0, 0, w=brightness) # handle RGBW mode elif self._mode == MODE_RGBW: self._bulb.setRgbw(*tuple(rgb), w=white, brightness=brightness) # handle RGB mode else: self._bulb.setRgb(*tuple(rgb), brightness=brightness)
def turn_on(self, **kwargs): """Turn the specified light on.""" rgb = None if ATTR_HS_COLOR in kwargs: rgb = color_util.color_hs_to_RGB(*kwargs[ATTR_HS_COLOR]) white = kwargs.get(ATTR_WHITE_VALUE) bright = kwargs.get(ATTR_BRIGHTNESS) flash = kwargs.get(ATTR_FLASH) effect = kwargs.get(ATTR_EFFECT) if self._state is False: if rgb is None and bright is None and flash is None: self._white = 255 white = 255 self._state = True self._bulb.on() self._state = True if effect is not None: if effect == "Rainbow": self._mode = 3 elif effect == "Rainbow jump": self._mode = 2 elif effect == "Pulse": self._mode = 1 if flash is not None: if flash == FLASH_LONG: self._speed = 2 elif flash == FLASH_SHORT: self._speed = 1 if bright is not None: rgbs = self._bulb.get_colour() hsvs = self.hsv_conv(rgbs[0], rgbs[1], rgbs[2]) bri = bright / 255 rgbv = self.rgb_conv(hsvs[0], hsvs[1], bri) respred = int(round(rgbv[0]*255)) respgreen = int(round(rgbv[1]*255)) respblue = int(round(rgbv[2]*255)) self._rgb = (respred, respgreen, respblue) self._white = 0 elif rgb is not None: self._white = 0 self._rgb = rgb elif white is not None: self._white = white self._brightness = 0 self._rgb = (0, 0, 0) if bright is not None: self.set_rgb(self._rgb[0], self._rgb[1], self._rgb[2]) elif self._white != 0 and flash is None: self.set_white(self._white) elif flash is not None: self.set_effect(self._rgb[0], self._rgb[1], self._rgb[2], self._white, 0, self._speed) elif effect is not None: self.set_effect(self._rgb[0], self._rgb[1], self._rgb[2], self._white, self._mode, 1) else: self.set_rgb(self._rgb[0], self._rgb[1], self._rgb[2])
def turn_on(self, **kwargs): """Turn on the light.""" if ATTR_HS_COLOR in kwargs: rgb = color_util.color_hs_to_RGB(*kwargs[ATTR_HS_COLOR]) self._device.led_rgb = rgb elif ATTR_BRIGHTNESS in kwargs: self._device.led_intensity = _to_skybell_level(kwargs[ATTR_BRIGHTNESS]) else: self._device.led_intensity = _to_skybell_level(255)
def _light_internal_convert_color(self, color_mode: ColorMode | str) -> dict: data: dict[str, tuple] = {} if color_mode == ColorMode.HS and self.hs_color: hs_color = self.hs_color data[ATTR_HS_COLOR] = (round(hs_color[0], 3), round(hs_color[1], 3)) data[ATTR_RGB_COLOR] = color_util.color_hs_to_RGB(*hs_color) data[ATTR_XY_COLOR] = color_util.color_hs_to_xy(*hs_color) elif color_mode == ColorMode.XY and self.xy_color: xy_color = self.xy_color data[ATTR_HS_COLOR] = color_util.color_xy_to_hs(*xy_color) data[ATTR_RGB_COLOR] = color_util.color_xy_to_RGB(*xy_color) data[ATTR_XY_COLOR] = (round(xy_color[0], 6), round(xy_color[1], 6)) elif color_mode == ColorMode.RGB and self.rgb_color: rgb_color = self.rgb_color data[ATTR_HS_COLOR] = color_util.color_RGB_to_hs(*rgb_color) data[ATTR_RGB_COLOR] = tuple(int(x) for x in rgb_color[0:3]) data[ATTR_XY_COLOR] = color_util.color_RGB_to_xy(*rgb_color) elif color_mode == ColorMode.RGBW and self._light_internal_rgbw_color: rgbw_color = self._light_internal_rgbw_color rgb_color = color_util.color_rgbw_to_rgb(*rgbw_color) data[ATTR_HS_COLOR] = color_util.color_RGB_to_hs(*rgb_color) data[ATTR_RGB_COLOR] = tuple(int(x) for x in rgb_color[0:3]) data[ATTR_RGBW_COLOR] = tuple(int(x) for x in rgbw_color[0:4]) data[ATTR_XY_COLOR] = color_util.color_RGB_to_xy(*rgb_color) elif color_mode == ColorMode.RGBWW and self.rgbww_color: rgbww_color = self.rgbww_color rgb_color = color_util.color_rgbww_to_rgb(*rgbww_color, self.min_mireds, self.max_mireds) data[ATTR_HS_COLOR] = color_util.color_RGB_to_hs(*rgb_color) data[ATTR_RGB_COLOR] = tuple(int(x) for x in rgb_color[0:3]) data[ATTR_RGBWW_COLOR] = tuple(int(x) for x in rgbww_color[0:5]) data[ATTR_XY_COLOR] = color_util.color_RGB_to_xy(*rgb_color) elif color_mode == ColorMode.COLOR_TEMP and self.color_temp: hs_color = color_util.color_temperature_to_hs( color_util.color_temperature_mired_to_kelvin(self.color_temp)) data[ATTR_HS_COLOR] = (round(hs_color[0], 3), round(hs_color[1], 3)) data[ATTR_RGB_COLOR] = color_util.color_hs_to_RGB(*hs_color) data[ATTR_XY_COLOR] = color_util.color_hs_to_xy(*hs_color) return data
async def async_turn_on(self, **kwargs): """Turn the device on.""" self.async_set_duration(**kwargs) rgbw = None hs_color = kwargs.get(ATTR_HS_COLOR) rgbw_color = kwargs.get(ATTR_RGBW_COLOR) color_temp = kwargs.get(ATTR_COLOR_TEMP) if hs_color is not None: rgbw = "#" for colorval in color_util.color_hs_to_RGB(*hs_color): rgbw += f"{colorval:02x}" if self._color_channels and self._color_channels & COLOR_CHANNEL_COLD_WHITE: rgbw += "0000" else: # trim the CW value or it will not work correctly rgbw += "00" # white LED must be off in order for color to work elif rgbw_color is not None: red = rgbw_color[0] green = rgbw_color[1] blue = rgbw_color[2] white = rgbw_color[3] if self._color_channels & COLOR_CHANNEL_WARM_WHITE: # trim the CW value or it will not work correctly rgbw = f"#{red:02x}{green:02x}{blue:02x}{white:02x}" else: rgbw = f"#{red:02x}{green:02x}{blue:02x}00{white:02x}" elif color_temp is not None: # Limit color temp to min/max values cold = max( 0, min( 255, round((self._max_mireds - color_temp) / (self._max_mireds - self._min_mireds) * 255), ), ) warm = 255 - cold rgbw = f"#000000{warm:02x}{cold:02x}" if rgbw and self.values.color: self.values.color.send_value(rgbw) # Zwave multilevel switches use a range of [0, 99] to control # brightness. Level 255 means to set it to previous value. if ATTR_BRIGHTNESS in kwargs: brightness = kwargs[ATTR_BRIGHTNESS] brightness = byte_to_zwave_brightness(brightness) else: brightness = 255 self.values.primary.send_value(brightness)
def _close_enough(actual_rgb, testing_rgb): """Validate the given RGB value is in acceptable tolerance.""" # Convert the given RGB values to hue / saturation and then back again # as it wasn't reading the same RGB value set against it. actual_hs = color_util.color_RGB_to_hs(*actual_rgb) actual_rgb = color_util.color_hs_to_RGB(*actual_hs) testing_hs = color_util.color_RGB_to_hs(*testing_rgb) testing_rgb = color_util.color_hs_to_RGB(*testing_hs) actual_red, actual_green, actual_blue = actual_rgb testing_red, testing_green, testing_blue = testing_rgb r_diff = abs(actual_red - testing_red) g_diff = abs(actual_green - testing_green) b_diff = abs(actual_blue - testing_blue) return (r_diff <= CLOSE_THRESHOLD and g_diff <= CLOSE_THRESHOLD and b_diff <= CLOSE_THRESHOLD)
def turn_on(self, **kwargs): """Turn on the light.""" if ATTR_HS_COLOR in kwargs: rgb = color_util.color_hs_to_RGB(*kwargs[ATTR_HS_COLOR]) self._device.led_rgb = rgb elif ATTR_BRIGHTNESS in kwargs: self._device.led_intensity = _to_skybell_level( kwargs[ATTR_BRIGHTNESS]) else: self._device.led_intensity = _to_skybell_level(255)
def turn_on(self, **kwargs): """Turn the specified or all lights on.""" hs_color = kwargs.get(ATTR_HS_COLOR) if hs_color: rgb = color_util.color_hs_to_RGB(*hs_color) else: rgb = None brightness = kwargs.get(ATTR_BRIGHTNESS) effect = kwargs.get(ATTR_EFFECT) white = kwargs.get(ATTR_WHITE_VALUE) # Show warning if effect set with rgb, brightness, or white level if effect and (brightness or white or rgb): _LOGGER.warning("RGB, brightness and white level are ignored when" " an effect is specified for a flux bulb") # Random color effect if effect == EFFECT_RANDOM: self._bulb.setRgb(random.randint(0, 255), random.randint(0, 255), random.randint(0, 255)) return # Effect selection elif effect in EFFECT_MAP: self._bulb.setPresetPattern(EFFECT_MAP[effect], 50) return # Preserve current brightness on color/white level change if brightness is None: brightness = self.brightness # Preserve color on brightness/white level change if rgb is None: rgb = self._bulb.getRgb() if white is None and self._mode == MODE_RGBW: white = self.white_value # handle W only mode (use brightness instead of white value) if self._mode == MODE_WHITE: self._bulb.setRgbw(0, 0, 0, w=brightness) # handle RGBW mode elif self._mode == MODE_RGBW: self._bulb.setRgbw(*tuple(rgb), w=white, brightness=brightness) # handle RGB mode else: self._bulb.setRgb(*tuple(rgb), brightness=brightness) if not self.is_on: self._bulb.turnOn()
def _turn_on_rgb_and_w(self, hex_template: str, **kwargs: Any) -> None: """Turn on RGB or RGBW child device.""" assert self._hs rgb = list(color_util.color_hs_to_RGB(*self._hs)) white = self._white hex_color = self._values.get(self.value_type) hs_color: tuple[float, float] | None = kwargs.get(ATTR_HS_COLOR) new_rgb: tuple[int, int, int] | None if hs_color is not None: new_rgb = color_util.color_hs_to_RGB(*hs_color) else: new_rgb = None new_white: int | None = kwargs.get(ATTR_WHITE_VALUE) if new_rgb is None and new_white is None: return if new_rgb is not None: rgb = list(new_rgb) if hex_template == "%02x%02x%02x%02x": if new_white is not None: rgb.append(new_white) elif white is not None: rgb.append(white) else: rgb.append(0) hex_color = hex_template % tuple(rgb) if len(rgb) > 3: white = rgb.pop() self.gateway.set_child_value(self.node_id, self.child_id, self.value_type, hex_color, ack=1) if self.assumed_state: # optimistically assume that light has changed state # pylint: disable=no-value-for-parameter # https://github.com/PyCQA/pylint/issues/4546 self._hs = color_util.color_RGB_to_hs( *rgb) # type: ignore[assignment] self._white = white self._values[self.value_type] = hex_color
def turn_on(self, **kwargs): """Instruct the light to turn on.""" if self._zlight.devicetype == 'switchMultilevel': self._zlight.level = kwargs.get(ATTR_BRIGHTNESS, 255) elif self._zlight.devicetype == 'switchRGBW': hs_color = kwargs.get(ATTR_HS_COLOR) if hs_color: self._zlight.rgb = color_util.color_hs_to_RGB(*hs_color) self._zlight.level = kwargs.get(ATTR_BRIGHTNESS, 255) else: self._zlight.on = True
def turn_on(self, **kwargs): """Turn the light on.""" _LOGGER.info("turn_on: {}".format(pprint.pformat(kwargs))) rgb = kwargs.get(ATTR_HS_COLOR, None) if rgb is not None: rgb = color_util.color_hs_to_RGB(*rgb) brightness = kwargs.get(ATTR_BRIGHTNESS, None) self._light.turn_on(brightness=brightness, rgb=rgb) self._state = "on"
async def async_turn_on(self, **kwargs): """Turn the light on.""" if ATTR_BRIGHTNESS in kwargs: brightness_pct = kwargs[ATTR_BRIGHTNESS] / 255.0 await self._lightpad.set_config({"glowIntensity": brightness_pct}) elif ATTR_HS_COLOR in kwargs: hs_color = kwargs[ATTR_HS_COLOR] red, green, blue = color_util.color_hs_to_RGB(*hs_color) await self._lightpad.set_glow_color(red, green, blue, 0) else: await self._lightpad.set_config({"glowEnabled": True})
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()
async def async_turn_on(self, **kwargs): """Turn the light on.""" if ATTR_BRIGHTNESS in kwargs: if self.device.supports_brightness: await self.device.set_brightness(int(kwargs[ATTR_BRIGHTNESS])) elif ATTR_HS_COLOR in kwargs: if self.device.supports_color: await self.device.set_color(color_util.color_hs_to_RGB( *kwargs[ATTR_HS_COLOR])) else: await self.device.set_on()
async def async_turn_on(self, **kwargs): """Turn the light on.""" if ATTR_BRIGHTNESS in kwargs: if self.device.supports_brightness: await self.device.set_brightness(int(kwargs[ATTR_BRIGHTNESS])) elif ATTR_HS_COLOR in kwargs: if self.device.supports_color: await self.device.set_color( color_util.color_hs_to_RGB(*kwargs[ATTR_HS_COLOR])) else: await self.device.set_on()
def turn_on(self, **kwargs): """Turn on the light.""" if (ATTR_HS_COLOR in kwargs and self._device.is_dimmable and self._device.has_color): self._device.set_color(color_util.color_hs_to_RGB( *kwargs[ATTR_HS_COLOR])) if ATTR_BRIGHTNESS in kwargs and self._device.is_dimmable: self._device.set_level(kwargs[ATTR_BRIGHTNESS]) else: self._device.switch_on()
async def async_turn_on(self, **kwargs): """Turn the light on.""" if ATTR_BRIGHTNESS in kwargs: await self._lightpad.set_config( {"glowIntensity": kwargs[ATTR_BRIGHTNESS]}) elif ATTR_HS_COLOR in kwargs: hs_color = kwargs[ATTR_HS_COLOR] red, green, blue = color_util.color_hs_to_RGB(*hs_color) await self._lightpad.set_glow_color(red, green, blue, 0) else: await self._lightpad.set_config({"glowEnabled": True})
def turn_on(self, **kwargs): """Instruct the light to turn on.""" if not kwargs: self._light.set_brightness(4095) else: if ATTR_BRIGHTNESS in kwargs: bright = round((kwargs[ATTR_BRIGHTNESS] / 255) * 4095) self._light.set_brightness(bright) if ATTR_HS_COLOR in kwargs: rgb = color_util.color_hs_to_RGB(*kwargs[ATTR_HS_COLOR]) self._light.set_rgb(rgb[0], rgb[1], rgb[2])
def turn_on(self, **kwargs): """Turn the light on.""" if ATTR_HS_COLOR in kwargs and self._color: rgb = color_util.color_hs_to_RGB(*kwargs[ATTR_HS_COLOR]) self.vera_device.set_color(rgb) elif ATTR_BRIGHTNESS in kwargs and self.vera_device.is_dimmable: self.vera_device.set_brightness(kwargs[ATTR_BRIGHTNESS]) else: self.vera_device.switch_on() self._state = True self.schedule_update_ha_state(True)
def query_attributes(self): """Return color spectrum query attributes.""" response = {} color_hs = self.state.attributes.get(light.ATTR_HS_COLOR) if color_hs is not None: response['color'] = { 'spectrumRGB': int(color_util.color_rgb_to_hex( *color_util.color_hs_to_RGB(*color_hs)), 16), } return response
def turn_on(self, **kwargs): """Turn on the light.""" if (ATTR_HS_COLOR in kwargs and self._device.is_dimmable and self._device.has_color): self._device.set_color(color_util.color_hs_to_RGB( *kwargs[ATTR_HS_COLOR])) if ATTR_BRIGHTNESS in kwargs and self._device.is_dimmable: # Convert HASS brightness (0-255) to Abode brightness (0-99) # If 100 is sent to Abode, response is 99 causing an error self._device.set_level(ceil(kwargs[ATTR_BRIGHTNESS] * 99 / 255.0)) else: self._device.switch_on()
def turn_on(self, **kwargs): """Turn the light on.""" if ATTR_HS_COLOR in kwargs: self._hs = kwargs[ATTR_HS_COLOR] if ATTR_BRIGHTNESS in kwargs: self._brightness = int(100 * kwargs[ATTR_BRIGHTNESS] / 255) rgb = color_util.color_hs_to_RGB(*self._hs) rgba = (self._brightness,) + rgb rgbhex = binascii.hexlify(struct.pack('BBBB', *rgba)).decode("ASCII") rgbhex = int(rgbhex, 16) if self._write_to_hub(self._sid, **{self._data_key: rgbhex}): self._state = True
def _turn_on(self, **kwargs): """Really turn the light on.""" if self._supported_flags & SUPPORT_BRIGHTNESS: target_brightness = kwargs.get(ATTR_BRIGHTNESS) # No brightness specified, so we either restore it to # last brightness or switch it on at maximum level if target_brightness is None: if self._brightness == 0: if self._last_brightness: self._brightness = self._last_brightness else: self._brightness = 100 else: # We set it to the target brightness and turn it on self._brightness = scaleto100(target_brightness) if self._supported_flags & SUPPORT_COLOR: if self._reset_color and \ kwargs.get(ATTR_WHITE_VALUE) is None and \ kwargs.get(ATTR_HS_COLOR) is None and \ kwargs.get(ATTR_BRIGHTNESS) is None: self._color = (100, 0) # Update based on parameters self._white = kwargs.get(ATTR_WHITE_VALUE, self._white) self._color = kwargs.get(ATTR_HS_COLOR, self._color) rgb = color_util.color_hs_to_RGB(*self._color) self.call_set_color( round(rgb[0] * self._brightness / 100.0), round(rgb[1] * self._brightness / 100.0), round(rgb[2] * self._brightness / 100.0), round(self._white * self._brightness / 100.0)) if self.state == 'off': self.set_level(int(self._brightness)) return if self._reset_color: bri255 = scaleto255(self._brightness) self.call_set_color(bri255, bri255, bri255, bri255) if self._supported_flags & SUPPORT_BRIGHTNESS: self.set_level(int(self._brightness)) return # The simplest case is left for last. No dimming, just switch on self.call_turn_on()
def turn_on(self, **kwargs): """Turn the specified light on.""" self._state = True hs_color = kwargs.get(ATTR_HS_COLOR) brightness = kwargs.get(ATTR_BRIGHTNESS) if hs_color is not None: self._hs = hs_color if brightness is not None: self._brightness = brightness rgb = color_util.color_hs_to_RGB(*self._hs) self.set_state(rgb[0], rgb[1], rgb[2], self.brightness) self.schedule_update_ha_state()
def turn_on(self, **kwargs) -> None: """Turn the bulb on.""" import yeelight brightness = kwargs.get(ATTR_BRIGHTNESS) colortemp = kwargs.get(ATTR_COLOR_TEMP) hs_color = kwargs.get(ATTR_HS_COLOR) rgb = color_util.color_hs_to_RGB(*hs_color) if hs_color else None flash = kwargs.get(ATTR_FLASH) effect = kwargs.get(ATTR_EFFECT) duration = int(self.config[CONF_TRANSITION]) # in ms if ATTR_TRANSITION in kwargs: # passed kwarg overrides config duration = int(kwargs.get(ATTR_TRANSITION) * 1000) # kwarg in s try: self._bulb.turn_on(duration=duration) except yeelight.BulbException as ex: _LOGGER.error("Unable to turn the bulb on: %s", ex) return if self.config[CONF_MODE_MUSIC] and not self._bulb.music_mode: try: self.set_music_mode(self.config[CONF_MODE_MUSIC]) except yeelight.BulbException as ex: _LOGGER.error("Unable to turn on music mode," "consider disabling it: %s", ex) try: # values checked for none in methods self.set_rgb(rgb, duration) self.set_colortemp(colortemp, duration) self.set_brightness(brightness, duration) self.set_flash(flash) self.set_effect(effect) except yeelight.BulbException as ex: _LOGGER.error("Unable to set bulb properties: %s", ex) return # save the current state if we had a manual change. if self.config[CONF_SAVE_ON_CHANGE] and (brightness or colortemp or rgb): try: self.set_default() except yeelight.BulbException as ex: _LOGGER.error("Unable to set the defaults: %s", ex) return
def turn_on(self, **kwargs): """Instruct the light to turn on and set correct brightness & color.""" if ATTR_HS_COLOR in kwargs: self._hs_color = kwargs[ATTR_HS_COLOR] if ATTR_BRIGHTNESS in kwargs: self._brightness = kwargs[ATTR_BRIGHTNESS] percent_bright = (self._brightness / 255) rgb_color = color_util.color_hs_to_RGB(*self._hs_color) self._blinkt.set_pixel(self._index, rgb_color[0], rgb_color[1], rgb_color[2], percent_bright) self._blinkt.show() self._is_on = True self.schedule_update_ha_state()
def turn_on(self, **kwargs): """Turn the light on.""" if not self.is_on: self._lamp.switch(True) if ATTR_BRIGHTNESS in kwargs: brightness = int((kwargs[ATTR_BRIGHTNESS] / 255.0) * 200.0) self._lamp.brightness(brightness) return if ATTR_HS_COLOR in kwargs: rgb = color_util.color_hs_to_RGB(*kwargs[ATTR_HS_COLOR]) self._lamp.rgb(*rgb) return if ATTR_COLOR_TEMP in kwargs: kelvin = int(color_util.color_temperature_mired_to_kelvin( kwargs[ATTR_COLOR_TEMP])) self._lamp.white(kelvin) return if ATTR_EFFECT in kwargs: effect = kwargs[ATTR_EFFECT] self._lamp.effect(effect) return
def turn_on(self, **kwargs): """Turn the lights on.""" if ATTR_HS_COLOR in kwargs: rgb_color = color_util.color_hs_to_RGB(*kwargs[ATTR_HS_COLOR]) elif self._rgb_mem == [0, 0, 0]: rgb_color = self._default_color else: rgb_color = self._rgb_mem brightness = kwargs.get(ATTR_BRIGHTNESS, self._brightness) if ATTR_EFFECT in kwargs: self._skip_update = True self._effect = kwargs[ATTR_EFFECT] if self._effect == 'HDMI': self.json_request({'command': 'clearall'}) self._icon = 'mdi:video-input-hdmi' self._brightness = 255 self._rgb_color = [125, 125, 125] else: self.json_request({ 'command': 'effect', 'priority': self._priority, 'effect': {'name': self._effect} }) self._icon = 'mdi:lava-lamp' self._rgb_color = [175, 0, 255] return cal_color = [int(round(x*float(brightness)/255)) for x in rgb_color] self.json_request({ 'command': 'color', 'priority': self._priority, 'color': cal_color })
def limitlessled_color(self): """Convert Home Assistant HS list to RGB Color tuple.""" from limitlessled import Color return Color(*color_hs_to_RGB(*tuple(self._color)))
def _from_hass_color(color): """Convert Home Assistant RGB list to Color tuple.""" from pwmled import Color rgb = color_util.color_hs_to_RGB(*color) return Color(*tuple(rgb))
async def async_turn_on(self, **kwargs): """Turn the light on.""" if ATTR_COLOR_TEMP in kwargs: color_temp = kwargs[ATTR_COLOR_TEMP] percent_color_temp = self.translate( color_temp, self.max_mireds, self.min_mireds, CCT_MIN, CCT_MAX) if ATTR_BRIGHTNESS in kwargs: brightness = kwargs[ATTR_BRIGHTNESS] percent_brightness = ceil(100 * brightness / 255.0) if ATTR_HS_COLOR in kwargs: hs_color = kwargs[ATTR_HS_COLOR] rgb = color.color_hs_to_RGB(*hs_color) if ATTR_BRIGHTNESS in kwargs and ATTR_HS_COLOR in kwargs: _LOGGER.debug( "Setting brightness and color: " "%s %s%%, %s", brightness, percent_brightness, rgb) result = await self._try_command( "Setting brightness and color failed: " "%s bri, %s color", self._light.set_brightness_and_rgb, percent_brightness, rgb) if result: self._hs_color = hs_color self._brightness = brightness elif ATTR_BRIGHTNESS in kwargs and ATTR_COLOR_TEMP in kwargs: _LOGGER.debug( "Setting brightness and color temperature: " "%s %s%%, %s mireds, %s%% cct", brightness, percent_brightness, color_temp, percent_color_temp) result = await self._try_command( "Setting brightness and color temperature failed: " "%s bri, %s cct", self._light.set_brightness_and_color_temperature, percent_brightness, percent_color_temp) if result: self._color_temp = color_temp self._brightness = brightness elif ATTR_HS_COLOR in kwargs: _LOGGER.debug( "Setting color: %s", rgb) result = await self._try_command( "Setting color failed: %s", self._light.set_rgb, rgb) if result: self._hs_color = hs_color elif ATTR_COLOR_TEMP in kwargs: _LOGGER.debug( "Setting color temperature: " "%s mireds, %s%% cct", color_temp, percent_color_temp) result = await self._try_command( "Setting color temperature failed: %s cct", self._light.set_color_temperature, percent_color_temp) if result: self._color_temp = color_temp elif ATTR_BRIGHTNESS in kwargs: brightness = kwargs[ATTR_BRIGHTNESS] percent_brightness = ceil(100 * brightness / 255.0) _LOGGER.debug( "Setting brightness: %s %s%%", brightness, percent_brightness) result = await self._try_command( "Setting brightness failed: %s", self._light.set_brightness, percent_brightness) if result: self._brightness = brightness else: await self._try_command( "Turning the light on failed.", self._light.on)