Use ColorMode enum in tasmota (#70549)

This commit is contained in:
epenet 2022-04-23 22:02:18 +02:00 committed by GitHub
parent 265bf3e9e0
commit 1b08e509ed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -22,13 +22,9 @@ from homeassistant.components.light import (
ATTR_HS_COLOR, ATTR_HS_COLOR,
ATTR_TRANSITION, ATTR_TRANSITION,
ATTR_WHITE, ATTR_WHITE,
COLOR_MODE_BRIGHTNESS,
COLOR_MODE_COLOR_TEMP,
COLOR_MODE_HS,
COLOR_MODE_ONOFF,
COLOR_MODE_WHITE,
SUPPORT_EFFECT, SUPPORT_EFFECT,
SUPPORT_TRANSITION, SUPPORT_TRANSITION,
ColorMode,
LightEntity, LightEntity,
brightness_supported, brightness_supported,
) )
@ -132,23 +128,23 @@ class TasmotaLight(
if light_type in [LIGHT_TYPE_RGB, LIGHT_TYPE_RGBW, LIGHT_TYPE_RGBCW]: if light_type in [LIGHT_TYPE_RGB, LIGHT_TYPE_RGBW, LIGHT_TYPE_RGBCW]:
# Mark HS support for RGBW light because we don't have direct control over the # Mark HS support for RGBW light because we don't have direct control over the
# white channel, so the base component's RGB->RGBW translation does not work # white channel, so the base component's RGB->RGBW translation does not work
self._supported_color_modes.add(COLOR_MODE_HS) self._supported_color_modes.add(ColorMode.HS)
self._color_mode = COLOR_MODE_HS self._color_mode = ColorMode.HS
if light_type == LIGHT_TYPE_RGBW: if light_type == LIGHT_TYPE_RGBW:
self._supported_color_modes.add(COLOR_MODE_WHITE) self._supported_color_modes.add(ColorMode.WHITE)
if light_type in [LIGHT_TYPE_COLDWARM, LIGHT_TYPE_RGBCW]: if light_type in [LIGHT_TYPE_COLDWARM, LIGHT_TYPE_RGBCW]:
self._supported_color_modes.add(COLOR_MODE_COLOR_TEMP) self._supported_color_modes.add(ColorMode.COLOR_TEMP)
self._color_mode = COLOR_MODE_COLOR_TEMP self._color_mode = ColorMode.COLOR_TEMP
if light_type != LIGHT_TYPE_NONE and not self._supported_color_modes: if light_type != LIGHT_TYPE_NONE and not self._supported_color_modes:
self._supported_color_modes.add(COLOR_MODE_BRIGHTNESS) self._supported_color_modes.add(ColorMode.BRIGHTNESS)
self._color_mode = COLOR_MODE_BRIGHTNESS self._color_mode = ColorMode.BRIGHTNESS
if not self._supported_color_modes: if not self._supported_color_modes:
self._supported_color_modes.add(COLOR_MODE_ONOFF) self._supported_color_modes.add(ColorMode.ONOFF)
self._color_mode = COLOR_MODE_ONOFF self._color_mode = ColorMode.ONOFF
if light_type in [LIGHT_TYPE_RGB, LIGHT_TYPE_RGBW, LIGHT_TYPE_RGBCW]: if light_type in [LIGHT_TYPE_RGB, LIGHT_TYPE_RGBW, LIGHT_TYPE_RGBCW]:
supported_features |= SUPPORT_EFFECT supported_features |= SUPPORT_EFFECT
@ -180,15 +176,15 @@ class TasmotaLight(
if self._tasmota_entity.light_type == LIGHT_TYPE_RGBW: if self._tasmota_entity.light_type == LIGHT_TYPE_RGBW:
# Tasmota does not support RGBW mode, set mode to white or hs # Tasmota does not support RGBW mode, set mode to white or hs
if self._white_value == 0: if self._white_value == 0:
self._color_mode = COLOR_MODE_HS self._color_mode = ColorMode.HS
else: else:
self._color_mode = COLOR_MODE_WHITE self._color_mode = ColorMode.WHITE
elif self._tasmota_entity.light_type == LIGHT_TYPE_RGBCW: elif self._tasmota_entity.light_type == LIGHT_TYPE_RGBCW:
# Tasmota does not support RGBWW mode, set mode to ct or hs # Tasmota does not support RGBWW mode, set mode to ct or hs
if self._white_value == 0: if self._white_value == 0:
self._color_mode = COLOR_MODE_HS self._color_mode = ColorMode.HS
else: else:
self._color_mode = COLOR_MODE_COLOR_TEMP self._color_mode = ColorMode.COLOR_TEMP
self.async_write_ha_state() self.async_write_ha_state()
@ -256,11 +252,11 @@ class TasmotaLight(
attributes: dict[str, Any] = {} attributes: dict[str, Any] = {}
if ATTR_HS_COLOR in kwargs and COLOR_MODE_HS in supported_color_modes: if ATTR_HS_COLOR in kwargs and ColorMode.HS in supported_color_modes:
hs_color = kwargs[ATTR_HS_COLOR] hs_color = kwargs[ATTR_HS_COLOR]
attributes["color_hs"] = [hs_color[0], hs_color[1]] attributes["color_hs"] = [hs_color[0], hs_color[1]]
if ATTR_WHITE in kwargs and COLOR_MODE_WHITE in supported_color_modes: if ATTR_WHITE in kwargs and ColorMode.WHITE in supported_color_modes:
attributes["white_value"] = scale_brightness(kwargs[ATTR_WHITE]) attributes["white_value"] = scale_brightness(kwargs[ATTR_WHITE])
if ATTR_TRANSITION in kwargs: if ATTR_TRANSITION in kwargs:
@ -269,7 +265,7 @@ class TasmotaLight(
if ATTR_BRIGHTNESS in kwargs and brightness_supported(supported_color_modes): if ATTR_BRIGHTNESS in kwargs and brightness_supported(supported_color_modes):
attributes["brightness"] = scale_brightness(kwargs[ATTR_BRIGHTNESS]) attributes["brightness"] = scale_brightness(kwargs[ATTR_BRIGHTNESS])
if ATTR_COLOR_TEMP in kwargs and COLOR_MODE_COLOR_TEMP in supported_color_modes: if ATTR_COLOR_TEMP in kwargs and ColorMode.COLOR_TEMP in supported_color_modes:
attributes["color_temp"] = int(kwargs[ATTR_COLOR_TEMP]) attributes["color_temp"] = int(kwargs[ATTR_COLOR_TEMP])
if ATTR_EFFECT in kwargs: if ATTR_EFFECT in kwargs: