def test_color_RGB_to_hsv(): """Test color_RGB_to_hsv.""" assert color_util.color_RGB_to_hsv(0, 0, 0) == (0, 0, 0) assert color_util.color_RGB_to_hsv(255, 255, 255) == (0, 0, 100) assert color_util.color_RGB_to_hsv(0, 0, 255) == (240, 100, 100) assert color_util.color_RGB_to_hsv(0, 255, 0) == (120, 100, 100) assert color_util.color_RGB_to_hsv(255, 0, 0) == (0, 100, 100)
def test_color_RGB_to_hsv(self): """Test color_RGB_to_hsv.""" self.assertEqual((0, 0, 0), color_util.color_RGB_to_hsv(0, 0, 0)) self.assertEqual((0, 0, 255), color_util.color_RGB_to_hsv(255, 255, 255)) self.assertEqual((43690, 255, 255), color_util.color_RGB_to_hsv(0, 0, 255)) self.assertEqual((21845, 255, 255), color_util.color_RGB_to_hsv(0, 255, 0)) self.assertEqual((0, 255, 255), color_util.color_RGB_to_hsv(255, 0, 0))
def test_color_RGB_to_hsv(self): """Test color_RGB_to_hsv.""" self.assertEqual((0, 0, 0), color_util.color_RGB_to_hsv(0, 0, 0)) self.assertEqual((0, 0, 100), color_util.color_RGB_to_hsv(255, 255, 255)) self.assertEqual((240, 100, 100), color_util.color_RGB_to_hsv(0, 0, 255)) self.assertEqual((120, 100, 100), color_util.color_RGB_to_hsv(0, 255, 0)) self.assertEqual((0, 100, 100), color_util.color_RGB_to_hsv(255, 0, 0))
def test_color_xy_brightness_to_hsv(self): """Test color_RGB_to_xy.""" self.assertEqual(color_util.color_RGB_to_hsv(0, 0, 0), color_util.color_xy_brightness_to_hsv(1, 1, 0)) self.assertEqual(color_util.color_RGB_to_hsv(255, 243, 222), color_util.color_xy_brightness_to_hsv(.35, .35, 255)) self.assertEqual(color_util.color_RGB_to_hsv(255, 0, 60), color_util.color_xy_brightness_to_hsv(1, 0, 255)) self.assertEqual(color_util.color_RGB_to_hsv(0, 255, 0), color_util.color_xy_brightness_to_hsv(0, 1, 255)) self.assertEqual(color_util.color_RGB_to_hsv(0, 63, 255), color_util.color_xy_brightness_to_hsv(0, 0, 255))
def test_color_RGB_to_hsv(self): """Test color_RGB_to_hsv.""" self.assertEqual((0, 0, 0), color_util.color_RGB_to_hsv(0, 0, 0)) self.assertEqual((0, 0, 255), color_util.color_RGB_to_hsv(255, 255, 255)) self.assertEqual((43690, 255, 255), color_util.color_RGB_to_hsv(0, 0, 255)) self.assertEqual((21845, 255, 255), color_util.color_RGB_to_hsv(0, 255, 0)) self.assertEqual((0, 255, 255), color_util.color_RGB_to_hsv(255, 0, 0))
def test_color_RGB_to_hsv(self): """Test color_RGB_to_hsv.""" self.assertEqual((0, 0, 0), color_util.color_RGB_to_hsv(0, 0, 0)) self.assertEqual((0, 0, 100), color_util.color_RGB_to_hsv(255, 255, 255)) self.assertEqual((240, 100, 100), color_util.color_RGB_to_hsv(0, 0, 255)) self.assertEqual((120, 100, 100), color_util.color_RGB_to_hsv(0, 255, 0)) self.assertEqual((0, 100, 100), color_util.color_RGB_to_hsv(255, 0, 0))
def test_color_RGB_to_hsv(self): """Test color_RGB_to_hsv.""" assert (0, 0, 0) == \ color_util.color_RGB_to_hsv(0, 0, 0) assert (0, 0, 100) == \ color_util.color_RGB_to_hsv(255, 255, 255) assert (240, 100, 100) == \ color_util.color_RGB_to_hsv(0, 0, 255) assert (120, 100, 100) == \ color_util.color_RGB_to_hsv(0, 255, 0) assert (0, 100, 100) == \ color_util.color_RGB_to_hsv(255, 0, 0)
def find_hsbk(**kwargs): """Find the desired color from a number of possible inputs.""" hue, saturation, brightness, kelvin = [None]*4 preprocess_turn_on_alternatives(kwargs) if ATTR_RGB_COLOR in kwargs: hue, saturation, brightness = \ color_util.color_RGB_to_hsv(*kwargs[ATTR_RGB_COLOR]) saturation = convert_8_to_16(saturation) brightness = convert_8_to_16(brightness) kelvin = 3500 if ATTR_XY_COLOR in kwargs: hue, saturation = color_util.color_xy_to_hs(*kwargs[ATTR_XY_COLOR]) saturation = convert_8_to_16(saturation) kelvin = 3500 if ATTR_COLOR_TEMP in kwargs: kelvin = int(color_util.color_temperature_mired_to_kelvin( kwargs[ATTR_COLOR_TEMP])) saturation = 0 if ATTR_BRIGHTNESS in kwargs: brightness = convert_8_to_16(kwargs[ATTR_BRIGHTNESS]) hsbk = [hue, saturation, brightness, kelvin] return None if hsbk == [None]*4 else hsbk
def update(self) -> None: """Read back the device state.""" rgb_color = self._stick.get_color() hsv = color_util.color_RGB_to_hsv(*rgb_color) self._attr_hs_color = hsv[:2] self._attr_brightness = int(hsv[2]) self._attr_is_on = self.brightness is not None and self.brightness > 0
def find_hsbk(**kwargs): """Find the desired color from a number of possible inputs.""" hue, saturation, brightness, kelvin = [None] * 4 preprocess_turn_on_alternatives(kwargs) if ATTR_RGB_COLOR in kwargs: hue, saturation, brightness = \ color_util.color_RGB_to_hsv(*kwargs[ATTR_RGB_COLOR]) saturation = convert_8_to_16(saturation) brightness = convert_8_to_16(brightness) kelvin = 3500 if ATTR_XY_COLOR in kwargs: hue, saturation = color_util.color_xy_to_hs(*kwargs[ATTR_XY_COLOR]) saturation = convert_8_to_16(saturation) kelvin = 3500 if ATTR_COLOR_TEMP in kwargs: kelvin = int( color_util.color_temperature_mired_to_kelvin( kwargs[ATTR_COLOR_TEMP])) saturation = 0 if ATTR_BRIGHTNESS in kwargs: brightness = convert_8_to_16(kwargs[ATTR_BRIGHTNESS]) hsbk = [hue, saturation, brightness, kelvin] return None if hsbk == [None] * 4 else hsbk
def turn_on(self, **kwargs) -> None: if ATTR_BRIGHTNESS in kwargs: self.hass.bus.async_fire( SENDDOMAIN, dict(uuid=self._action_uuid, 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._action_uuid, 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._action_uuid, value='hsv({},{},{})'.format(h, s, v))) else: self.hass.bus.async_fire( SENDDOMAIN, dict(uuid=self._action_uuid, value="setBrightness/1")) self.schedule_update_ha_state()
async def async_update(self): """Update the light's status.""" if self.device.appliance.status.get(self._key, {}).get(ATTR_VALUE) is True: self._state = True elif self.device.appliance.status.get(self._key, {}).get(ATTR_VALUE) is False: self._state = False else: self._state = None _LOGGER.debug("Updated, new light state: %s", self._state) if self._ambient: color = self.device.appliance.status.get(self._custom_color_key, {}) if not color: self._hs_color = None self._brightness = None else: colorvalue = color.get(ATTR_VALUE)[1:] rgb = color_util.rgb_hex_to_rgb_list(colorvalue) hsv = color_util.color_RGB_to_hsv(rgb[0], rgb[1], rgb[2]) self._hs_color = [hsv[0], hsv[1]] self._brightness = ceil((hsv[2] - 10) * 255 / 90) _LOGGER.debug("Updated, new brightness: %s", self._brightness) else: brightness = self.device.appliance.status.get(self._brightness_key, {}) if brightness is None: self._brightness = None else: self._brightness = ceil((brightness.get(ATTR_VALUE) - 10) * 255 / 90) _LOGGER.debug("Updated, new brightness: %s", self._brightness)
def turn_on(self, **kwargs): """Turn the specified or all lights on.""" command = {'on': True} if ATTR_TRANSITION in kwargs: command['transitiontime'] = int(kwargs[ATTR_TRANSITION] * 10) if ATTR_XY_COLOR in kwargs: if self.info.get('manufacturername') == "OSRAM": hsv = color_util.color_xy_brightness_to_hsv( *kwargs[ATTR_XY_COLOR], ibrightness=self.info['bri']) command['hue'] = hsv[0] command['sat'] = hsv[1] command['bri'] = hsv[2] else: command['xy'] = kwargs[ATTR_XY_COLOR] elif ATTR_RGB_COLOR in kwargs: if self.info.get('manufacturername') == "OSRAM": hsv = color_util.color_RGB_to_hsv( *(int(val) for val in kwargs[ATTR_RGB_COLOR])) command['hue'] = hsv[0] command['sat'] = hsv[1] command['bri'] = hsv[2] else: xyb = color_util.color_RGB_to_xy( *(int(val) for val in kwargs[ATTR_RGB_COLOR])) command['xy'] = xyb[0], xyb[1] command['bri'] = xyb[2] if ATTR_BRIGHTNESS in kwargs: command['bri'] = kwargs[ATTR_BRIGHTNESS] if ATTR_COLOR_TEMP in kwargs: command['ct'] = kwargs[ATTR_COLOR_TEMP] flash = kwargs.get(ATTR_FLASH) if flash == FLASH_LONG: command['alert'] = 'lselect' del command['on'] elif flash == FLASH_SHORT: command['alert'] = 'select' del command['on'] elif self.bridge_type == 'hue': command['alert'] = 'none' effect = kwargs.get(ATTR_EFFECT) if effect == EFFECT_COLORLOOP: command['effect'] = 'colorloop' elif effect == EFFECT_RANDOM: command['hue'] = random.randrange(0, 65535) command['sat'] = random.randrange(150, 254) elif self.bridge_type == 'hue': if self.info.get('manufacturername') != "OSRAM": command['effect'] = 'none' self._command_func(self.light_id, command)
def turn_on(self, **kwargs): """Turn the specified or all lights on.""" command = {'on': True} if ATTR_TRANSITION in kwargs: command['transitiontime'] = int(kwargs[ATTR_TRANSITION] * 10) if ATTR_XY_COLOR in kwargs: if self.info.get('manufacturername') == "OSRAM": hsv = color_util.color_xy_brightness_to_hsv( *kwargs[ATTR_XY_COLOR], ibrightness=self.info['bri']) command['hue'] = hsv[0] command['sat'] = hsv[1] command['bri'] = hsv[2] else: command['xy'] = kwargs[ATTR_XY_COLOR] elif ATTR_RGB_COLOR in kwargs: if self.info.get('manufacturername') == "OSRAM": hsv = color_util.color_RGB_to_hsv( *(int(val) for val in kwargs[ATTR_RGB_COLOR])) command['hue'] = hsv[0] command['sat'] = hsv[1] command['bri'] = hsv[2] else: xyb = color_util.color_RGB_to_xy( *(int(val) for val in kwargs[ATTR_RGB_COLOR])) command['xy'] = xyb[0], xyb[1] command['bri'] = xyb[2] if ATTR_BRIGHTNESS in kwargs: command['bri'] = kwargs[ATTR_BRIGHTNESS] if ATTR_COLOR_TEMP in kwargs: command['ct'] = kwargs[ATTR_COLOR_TEMP] flash = kwargs.get(ATTR_FLASH) if flash == FLASH_LONG: command['alert'] = 'lselect' del command['on'] elif flash == FLASH_SHORT: command['alert'] = 'select' del command['on'] elif self.bridge_type == 'hue': command['alert'] = 'none' effect = kwargs.get(ATTR_EFFECT) if effect == EFFECT_COLORLOOP: command['effect'] = 'colorloop' elif effect == EFFECT_RANDOM: command['hue'] = random.randrange(0, 65535) command['sat'] = random.randrange(150, 254) elif self.bridge_type == 'hue': if self.info.get('manufacturername') != "OSRAM": command['effect'] = 'none' self._command_func(self.light_id, command)
def update(self): """Synchronise internal state with the actual light state.""" rgb = self._bulb.get_colour() hsv = color_util.color_RGB_to_hsv(*rgb) self._hs_color = hsv[:2] self._brightness = (hsv[2] / 100) * 255 self._white = self._bulb.get_white() self._state = self._bulb.get_on()
def update(self): """Synchronise internal state with the actual light state.""" rgb = self._bulb.get_colour() hsv = color_util.color_RGB_to_hsv(*rgb) self._hs_color = hsv[:2] self._brightness = hsv[2] self._white = self._bulb.get_white() self._state = self._bulb.get_on()
def update(self) -> None: """Synchronise internal state with the actual light state.""" rgb = self._bulb.get_colour() hsv = color_util.color_RGB_to_hsv(*rgb) self._attr_hs_color = hsv[:2] self._attr_brightness = int((hsv[2] / 100) * 255) self._white = self._bulb.get_white() if self._white: self._attr_brightness = self._white self._attr_is_on = self._bulb.get_on()
def turn_on(self, **kwargs): """Turn the specified or all lights on.""" command = {'on': True} if ATTR_TRANSITION in kwargs: command['transitiontime'] = int(kwargs[ATTR_TRANSITION] * 10) if ATTR_XY_COLOR in kwargs: if self.info.get('manufacturername') == 'OSRAM': color_hue, sat = color_util.color_xy_to_hs( *kwargs[ATTR_XY_COLOR]) command['hue'] = color_hue / 360 * 65535 command['sat'] = sat / 100 * 255 else: command['xy'] = kwargs[ATTR_XY_COLOR] elif ATTR_RGB_COLOR in kwargs: if self.info.get('manufacturername') == 'OSRAM': hsv = color_util.color_RGB_to_hsv( *(int(val) for val in kwargs[ATTR_RGB_COLOR])) command['hue'] = hsv[0] / 360 * 65535 command['sat'] = hsv[1] / 100 * 255 command['bri'] = hsv[2] / 100 * 255 else: xyb = color_util.color_RGB_to_xy( *(int(val) for val in kwargs[ATTR_RGB_COLOR])) command['xy'] = xyb[0], xyb[1] elif ATTR_COLOR_TEMP in kwargs: temp = kwargs[ATTR_COLOR_TEMP] command['ct'] = max(self.min_mireds, min(temp, self.max_mireds)) if ATTR_BRIGHTNESS in kwargs: command['bri'] = kwargs[ATTR_BRIGHTNESS] flash = kwargs.get(ATTR_FLASH) if flash == FLASH_LONG: command['alert'] = 'lselect' del command['on'] elif flash == FLASH_SHORT: command['alert'] = 'select' del command['on'] else: command['alert'] = 'none' effect = kwargs.get(ATTR_EFFECT) if effect == EFFECT_COLORLOOP: command['effect'] = 'colorloop' elif effect == EFFECT_RANDOM: command['hue'] = random.randrange(0, 65535) command['sat'] = random.randrange(150, 254) elif self.info.get('manufacturername') == 'Philips': command['effect'] = 'none' self._command_func(self.light_id, command)
def turn_on(self, **kwargs): """Turn the specified or all lights on.""" command = {'on': True} if ATTR_TRANSITION in kwargs: command['transitiontime'] = int(kwargs[ATTR_TRANSITION] * 10) if ATTR_XY_COLOR in kwargs: if self.info.get('manufacturername') == 'OSRAM': color_hue, sat = color_util.color_xy_to_hs( *kwargs[ATTR_XY_COLOR]) command['hue'] = color_hue / 360 * 65535 command['sat'] = sat / 100 * 255 else: command['xy'] = kwargs[ATTR_XY_COLOR] elif ATTR_RGB_COLOR in kwargs: if self.info.get('manufacturername') == 'OSRAM': hsv = color_util.color_RGB_to_hsv( *(int(val) for val in kwargs[ATTR_RGB_COLOR])) command['hue'] = hsv[0] / 360 * 65535 command['sat'] = hsv[1] / 100 * 255 command['bri'] = hsv[2] / 100 * 255 else: xyb = color_util.color_RGB_to_xy( *(int(val) for val in kwargs[ATTR_RGB_COLOR])) command['xy'] = xyb[0], xyb[1] elif ATTR_COLOR_TEMP in kwargs: temp = kwargs[ATTR_COLOR_TEMP] command['ct'] = max(self.min_mireds, min(temp, self.max_mireds)) if ATTR_BRIGHTNESS in kwargs: command['bri'] = kwargs[ATTR_BRIGHTNESS] flash = kwargs.get(ATTR_FLASH) if flash == FLASH_LONG: command['alert'] = 'lselect' del command['on'] elif flash == FLASH_SHORT: command['alert'] = 'select' del command['on'] else: command['alert'] = 'none' effect = kwargs.get(ATTR_EFFECT) if effect == EFFECT_COLORLOOP: command['effect'] = 'colorloop' elif effect == EFFECT_RANDOM: command['hue'] = random.randrange(0, 65535) command['sat'] = random.randrange(150, 254) elif self.info.get('manufacturername') == 'Philips': command['effect'] = 'none' self._command_func(self.light_id, command)
def update(self): request = requests.get(self._host) lights = json.loads(request.text) for light in lights: if (light["device_eui"] == self._device_eui): self._light = light self._hsv = list( color_util.color_RGB_to_hsv(light["color"][0] * 255, light["color"][1] * 255, light["color"][2] * 255)) break
def __init__(self, light, host, props): self._light = light self._host = host self._device_eui = light["device_eui"] self._unique_id = light["device_eui"] self._serial = props["serial"] self._hsv = list( color_util.color_RGB_to_hsv(light["color"][0] * 255, light["color"][1] * 255, light["color"][2] * 255)) props["serial"] += 1
def update(self): """Fetch new state data for this light. This is the only method that should fetch new data for Home Assistant. """ jsonData = self.base_update() lastRGB = jsonData["switchState"][0]["lastRGB"] fullhsv = color_util.color_RGB_to_hsv( (lastRGB >> 16) & 0xFF, (lastRGB >> 8) & 0xFF, lastRGB & 0xFF) self._hs_color = (fullhsv[0], fullhsv[1]) self._brightness = (255 / 100) * fullhsv[2]
def rgb_received(msg): """Handle new MQTT messages for RGB.""" payload = templates[CONF_RGB](msg.payload) if not payload: _LOGGER.debug("Ignoring empty rgb message from '%s'", msg.topic) return rgb = [int(val) for val in payload.split(",")] self._hs = color_util.color_RGB_to_hs(*rgb) if self._topic[CONF_BRIGHTNESS_STATE_TOPIC] is None: percent_bright = float(color_util.color_RGB_to_hsv(*rgb)[2]) / 100.0 self._brightness = percent_bright * 255 self.async_write_ha_state()
def update(self): """Synchronize state with bulb.""" if not self.available: try: self._connect() self._error_reported = False if self._bulb.getRgb() != (0, 0, 0): color = self._bulb.getRgbw() self._color = color_util.color_RGB_to_hsv(*color[0:3]) self._white_value = color[3] except socket.error: self._disconnect() if not self._error_reported: _LOGGER.warning("Failed to connect to bulb %s, %s", self._ipaddr, self._name) self._error_reported = True return self._bulb.update_state(retry=2) if self._bulb.getRgb() != (0, 0, 0): color = self._bulb.getRgbw() self._color = color_util.color_RGB_to_hsv(*color[0:3]) self._white_value = color[3]
def update(self): """Synchronize state with bulb.""" if not self.available: try: self._connect() self._error_reported = False if self._bulb.getRgb() != (0, 0, 0): color = self._bulb.getRgbw() self._color = color_util.color_RGB_to_hsv(*color[0:3]) self._white_value = color[3] except socket.error: self._disconnect() if not self._error_reported: _LOGGER.warning("Failed to connect to bulb %s, %s", self._ipaddr, self._name) self._error_reported = True return self._bulb.update_state(retry=2) if self._bulb.getRgb() != (0, 0, 0): color = self._bulb.getRgbw() self._color = color_util.color_RGB_to_hsv(*color[0:3]) self._white_value = color[3]
def rgb_received(topic, payload, qos): """Handle new MQTT messages for RGB.""" payload = templates[CONF_RGB](payload) if not payload: _LOGGER.debug("Ignoring empty rgb message from '%s'", topic) return rgb = [int(val) for val in payload.split(',')] self._hs = color_util.color_RGB_to_hs(*rgb) if self._topic[CONF_BRIGHTNESS_STATE_TOPIC] is None: percent_bright = \ float(color_util.color_RGB_to_hsv(*rgb)[2]) / 100.0 self._brightness = int(percent_bright * 255) self.async_schedule_update_ha_state()
def rgb_received(topic, payload, qos): """Handle new MQTT messages for RGB.""" payload = templates[CONF_RGB](payload) if not payload: _LOGGER.debug("Ignoring empty rgb message from '%s'", topic) return rgb = [int(val) for val in payload.split(',')] self._hs = color_util.color_RGB_to_hs(*rgb) if self._topic[CONF_BRIGHTNESS_STATE_TOPIC] is None: percent_bright = \ float(color_util.color_RGB_to_hsv(*rgb)[2]) / 100.0 self._brightness = int(percent_bright * 255) self.async_schedule_update_ha_state()
def rgb_received(msg): """Handler new MQTT message.""" payload = msg.payload rgb = list(map(int, payload.split(","))) if any(rgb): self._hs = color_util.color_RGB_to_hs(*rgb[:3]) percent_bright = float( color_util.color_RGB_to_hsv(*rgb[:3])[2]) / 100.0 self._brightness = percent_bright * 255 self._state = True else: self._state = False self.async_write_ha_state()
def _rgbx_received(msg, template, color_mode, convert_color): """Handle new MQTT messages for RGBW and RGBWW.""" payload = self._value_templates[template](msg.payload, None) if not payload: _LOGGER.debug( "Ignoring empty %s message from '%s'", color_mode, msg.topic ) return None color = tuple(int(val) for val in payload.split(",")) if self._optimistic_color_mode: self._color_mode = color_mode if self._topic[CONF_BRIGHTNESS_STATE_TOPIC] is None: rgb = convert_color(*color) percent_bright = float(color_util.color_RGB_to_hsv(*rgb)[2]) / 100.0 self._brightness = percent_bright * 255 return color
def update(self): """Fetch new state data for this light.""" try: state = self._light.get_state() except pyzerproc.ZerprocException: if self._available: _LOGGER.warning("Unable to connect to %s", self.entity_id) self._available = False return if self._available is False: _LOGGER.info("Reconnected to %s", self.entity_id) self._available = True self._is_on = state.is_on hsv = color_util.color_RGB_to_hsv(*state.color) self._hs_color = hsv[:2] self._brightness = int(round((hsv[2] / 100) * 255))
async def async_update(self): """Update light's status.""" # get all messages of this appliance stored in status status = self._device.appliance.status # check if a message has been received already if self._key not in status: self._state = None elif "value" not in status[self._key]: self._state = None else: # Functional or ambient lighting if self._key in ["BSH.Common.Setting.AmbientLightEnabled", "Cooking.Common.Setting.Lighting"]: self._state = status[self._key].get("value") == "true" # Functional lighting if self._key == "Cooking.Common.Setting.Lighting": # Brightness brightness = self._device.appliance.status.get("Cooking.Common.Setting.LightingBrightness", {}) if brightness is not None and brightness.get("value") is not None: self._brightness = ceil((brightness.get("value") - 10) * 255 / 90) else: self._brightness = None # Ambient lighting elif self._key == "BSH.Common.Setting.AmbientLightEnabled": # Brightness brightness = self._device.appliance.status.get("BSH.Common.Setting.AmbientLightBrightness", {}) if brightness is not None and brightness.get("value") is not None: self._brightness = ceil((brightness.get("value") - 10) * 255 / 90) else: self._brightness = None # Hue, saturation and brightness for custom color color = self._device.appliance.status.get("BSH.Common.Setting.AmbientLightCustomColor", {}) if color is not None and color.get("value") is not None: colorvalue = color.get("value")[1:] rgb = color_util.rgb_hex_to_rgb_list(colorvalue) hsv = color_util.color_RGB_to_hsv(rgb[0], rgb[1], rgb[2]) self._hs_color = [hsv[0], hsv[1]] self._brightness = ceil((hsv[2] - 10) * 255 / 90) else: self._hs_color = None self._brightness = None
def find_hsbk(self, **kwargs): """Find the desired color from a number of possible inputs.""" changed_color = False hsbk = kwargs.pop(ATTR_HSBK, None) if hsbk is not None: return [hsbk, True] preprocess_turn_on_alternatives(kwargs) if ATTR_RGB_COLOR in kwargs: hue, saturation, brightness = \ color_util.color_RGB_to_hsv(*kwargs[ATTR_RGB_COLOR]) saturation = convert_8_to_16(saturation) brightness = convert_8_to_16(brightness) changed_color = True else: hue = self._hue saturation = self._sat brightness = self._bri if ATTR_XY_COLOR in kwargs: hue, saturation = color_util.color_xy_to_hs(*kwargs[ATTR_XY_COLOR]) saturation = convert_8_to_16(saturation) changed_color = True # When color or temperature is set, use a default value for the other if ATTR_COLOR_TEMP in kwargs: kelvin = int(color_util.color_temperature_mired_to_kelvin( kwargs[ATTR_COLOR_TEMP])) if not changed_color: saturation = 0 changed_color = True else: if changed_color: kelvin = 3500 else: kelvin = self._kel if ATTR_BRIGHTNESS in kwargs: brightness = convert_8_to_16(kwargs[ATTR_BRIGHTNESS]) changed_color = True else: brightness = self._bri return [[hue, saturation, brightness, kelvin], changed_color]
async def async_update(self) -> None: """Fetch new state data for this light.""" try: if not self.available: await self._light.connect() state = await self._light.get_state() except pyzerproc.ZerprocException: if self.available: _LOGGER.warning("Unable to connect to %s", self._light.address) self._attr_available = False return if not self.available: _LOGGER.info("Reconnected to %s", self._light.address) self._attr_available = True self._attr_is_on = state.is_on hsv = color_util.color_RGB_to_hsv(*state.color) self._attr_hs_color = hsv[:2] self._attr_brightness = int(round((hsv[2] / 100) * 255))
async def async_update(self): """Fetch new state data for this light.""" try: if not self._available: await self._light.connect() # pylint: disable=invalid-name r, g, b, w = await self._light.get_color() except pykulersky.PykulerskyException as exc: if self._available: _LOGGER.warning("Unable to connect to %s: %s", self._light.address, exc) self._available = False return if self._available is False: _LOGGER.info("Reconnected to %s", self._light.address) self._available = True hsv = color_util.color_RGB_to_hsv(r, g, b) self._hs_color = hsv[:2] self._brightness = int(round((hsv[2] / 100) * 255)) self._white_value = w
async def async_turn_on(self, **kwargs): """Turn the light on.""" hs_color = kwargs.get(ATTR_HS_COLOR, self._hs_color) brightness = kwargs.get(ATTR_BRIGHTNESS, self._brightness) effect = kwargs.get(ATTR_EFFECT) if effect is not None: colors = await self._api.set_pattern_by_id(self._channel, effect) rgb = color_int_to_rgb(colors[0]) hsv = color_util.color_RGB_to_hsv(*rgb) hs_color = hsv[:2] brightness = hsv[2] / 100 * 255 else: rgb = color_util.color_hsv_to_RGB(*hs_color, brightness/255*100) colors = [color_rgb_to_int(*rgb)] await self._api.set_pattern(self._channel, colors) self._hs_color = hs_color self._brightness = brightness self._effect = effect
async def async_turn_on(self, **kwargs): """Turn the light on.""" hs_color = kwargs.get(ATTR_HS_COLOR, self._hs_color) brightness = kwargs.get(ATTR_BRIGHTNESS, self._brightness) effect = kwargs.get(ATTR_EFFECT) if effect is not None: colors = await self._api.set_pattern_by_id(self._channel, effect) rgb = color_int_to_rgb(colors[0]) hsv = color_util.color_RGB_to_hsv(*rgb) hs_color = hsv[:2] brightness = hsv[2] / 100 * 255 else: rgb = color_util.color_hsv_to_RGB(*hs_color, brightness/255*100) colors = [color_rgb_to_int(*rgb)] await self._api.set_pattern(self._channel, colors) self._hs_color = hs_color self._brightness = brightness self._effect = effect
def turn_on(self, **kwargs) -> None: if ATTR_EFFECT in kwargs: effects = kwargs["effect"].split(",") if len(effects) == 1: mood_id = self.get_id_by_moodname(kwargs["effect"]) if mood_id != kwargs["effect"]: self.hass.bus.async_fire( SENDDOMAIN, dict(uuid=self.uuidAction, value="changeTo/{}".format(mood_id)), ) else: self.hass.bus.async_fire( SENDDOMAIN, dict(uuid=self.uuidAction, value="plus")) else: effect_ids = [] for _ in effects: mood_id = self.get_id_by_moodname(_.strip()) if mood_id != _: effect_ids.append(mood_id) self.hass.bus.async_fire( SENDDOMAIN, dict(uuid=self.uuidAction, value="on")) for _ in effect_ids: self.hass.bus.async_fire( SENDDOMAIN, dict(uuid=self.uuidAction, value="addMood/{}".format(_)), ) if ATTR_BRIGHTNESS in kwargs: if self.states.get("masterValue", None): self.hass.bus.async_fire( SENDDOMAIN, dict( uuid=self._uuid_dict.get( self.states.get("masterValue"), self.uuidAction), value="{}".format( round(hass_to_lox(kwargs[ATTR_BRIGHTNESS]))), ), ) elif self.color_temp: self.hass.bus.async_fire( SENDDOMAIN, dict( uuid=self.uuidAction, value="temp({},{})".format( round(hass_to_lox(kwargs[ATTR_BRIGHTNESS])), int(to_loxone_color_temp(self.color_temp)), ), ), ) elif self.hs_color: r, g, b = color_util.color_hs_to_RGB(self.hs_color[0], self.hs_color[1]) h, s, v = color_util.color_RGB_to_hsv(r, g, b) self.hass.bus.async_fire( SENDDOMAIN, dict( uuid=self._uuid_dict.get( self.states.get("masterColor"), self.uuidAction), value="hsv({},{},{})".format( h, s, round(hass_to_lox(kwargs[ATTR_BRIGHTNESS]))), ), ) if 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) if self.brightness: v = round(hass_to_lox(self.brightness)) self.hass.bus.async_fire( SENDDOMAIN, dict( uuid=self._uuid_dict.get(self.states.get("masterColor"), self.uuidAction), value="hsv({},{},{})".format(h, s, v), ), ) if ATTR_COLOR_TEMP in kwargs: self.hass.bus.async_fire( SENDDOMAIN, dict( uuid=self._uuid_dict.get(self.states.get("masterColor"), self.uuidAction), value="temp({},{})".format( round(hass_to_lox(self.brightness)), int(to_loxone_color_temp(kwargs[ATTR_COLOR_TEMP])), ), ), ) if kwargs == {}: self.hass.bus.async_fire(SENDDOMAIN, dict(uuid=self.uuidAction, value="on")) self.schedule_update_ha_state()
def hs_color(self): """Return the hs value.""" return color_util.color_RGB_to_hsv(*self._lamp.state()['rgb'])
def update(self): """Read back the device state.""" rgb_color = self._stick.get_color() hsv = color_util.color_RGB_to_hsv(*rgb_color) self._hs_color = hsv[:2] self._brightness = hsv[2]
if current and current["isExpert"]: if settings := _get_settings(current): color = settings["color"] effect = AmbilightEffect.from_str(self._attr_effect) if effect.is_on(self._tv.powerstate): self._last_selected_effect = effect if effect.mode == EFFECT_EXPERT and color: self._attr_hs_color = ( color["hue"] * 360.0 / 255.0, color["saturation"] * 100.0 / 255.0, ) self._attr_brightness = color["brightness"] elif effect.mode == EFFECT_MODE and self._tv.ambilight_cached: hsv_h, hsv_s, hsv_v = color_RGB_to_hsv( *_average_pixels(self._tv.ambilight_cached)) self._attr_hs_color = hsv_h, hsv_s self._attr_brightness = hsv_v * 255.0 / 100.0 else: self._attr_hs_color = None self._attr_brightness = None @callback def _handle_coordinator_update(self) -> None: """Handle updated data from the coordinator.""" self._update_from_coordinator() super()._handle_coordinator_update() async def _set_ambilight_cached(self, effect: AmbilightEffect, hs_color: tuple[float, float], brightness: int):
def _hsv_color(self): """Return the HSV color value.""" rgb = None if self.device.supports_rgbw or self.device.supports_color: rgb, _ = self.device.current_color return color_util.color_RGB_to_hsv(*rgb) if rgb else None