Use ColorMode enum in zwave_js (#70559)

This commit is contained in:
epenet 2022-04-23 22:26:09 +02:00 committed by GitHub
parent 677614546a
commit 7d2e75e6ab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -30,12 +30,9 @@ from homeassistant.components.light import (
ATTR_HS_COLOR, ATTR_HS_COLOR,
ATTR_RGBW_COLOR, ATTR_RGBW_COLOR,
ATTR_TRANSITION, ATTR_TRANSITION,
COLOR_MODE_BRIGHTNESS,
COLOR_MODE_COLOR_TEMP,
COLOR_MODE_HS,
COLOR_MODE_RGBW,
DOMAIN as LIGHT_DOMAIN, DOMAIN as LIGHT_DOMAIN,
SUPPORT_TRANSITION, SUPPORT_TRANSITION,
ColorMode,
LightEntity, LightEntity,
) )
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
@ -141,13 +138,13 @@ class ZwaveLight(ZWaveBaseEntity, LightEntity):
self._calculate_color_values() self._calculate_color_values()
if self._supports_rgbw: if self._supports_rgbw:
self._supported_color_modes.add(COLOR_MODE_RGBW) self._supported_color_modes.add(ColorMode.RGBW)
elif self._supports_color: elif self._supports_color:
self._supported_color_modes.add(COLOR_MODE_HS) self._supported_color_modes.add(ColorMode.HS)
if self._supports_color_temp: if self._supports_color_temp:
self._supported_color_modes.add(COLOR_MODE_COLOR_TEMP) self._supported_color_modes.add(ColorMode.COLOR_TEMP)
if not self._supported_color_modes: if not self._supported_color_modes:
self._supported_color_modes.add(COLOR_MODE_BRIGHTNESS) self._supported_color_modes.add(ColorMode.BRIGHTNESS)
# Entity class attributes # Entity class attributes
self._attr_supported_features = 0 self._attr_supported_features = 0
@ -392,7 +389,7 @@ class ZwaveLight(ZWaveBaseEntity, LightEntity):
multi_color = {} multi_color = {}
# Default: Brightness (no color) # Default: Brightness (no color)
self._color_mode = COLOR_MODE_BRIGHTNESS self._color_mode = ColorMode.BRIGHTNESS
# RGB support # RGB support
if red_val and green_val and blue_val: if red_val and green_val and blue_val:
@ -405,7 +402,7 @@ class ZwaveLight(ZWaveBaseEntity, LightEntity):
# convert to HS # convert to HS
self._hs_color = color_util.color_RGB_to_hs(red, green, blue) self._hs_color = color_util.color_RGB_to_hs(red, green, blue)
# Light supports color, set color mode to hs # Light supports color, set color mode to hs
self._color_mode = COLOR_MODE_HS self._color_mode = ColorMode.HS
# color temperature support # color temperature support
if ww_val and cw_val: if ww_val and cw_val:
@ -419,7 +416,7 @@ class ZwaveLight(ZWaveBaseEntity, LightEntity):
- ((cold_white / 255) * (self._max_mireds - self._min_mireds)) - ((cold_white / 255) * (self._max_mireds - self._min_mireds))
) )
# White channels turned on, set color mode to color_temp # White channels turned on, set color mode to color_temp
self._color_mode = COLOR_MODE_COLOR_TEMP self._color_mode = ColorMode.COLOR_TEMP
else: else:
self._color_temp = None self._color_temp = None
# only one white channel (warm white) = rgbw support # only one white channel (warm white) = rgbw support
@ -428,14 +425,14 @@ class ZwaveLight(ZWaveBaseEntity, LightEntity):
white = multi_color.get(COLOR_SWITCH_COMBINED_WARM_WHITE, ww_val.value) white = multi_color.get(COLOR_SWITCH_COMBINED_WARM_WHITE, ww_val.value)
self._rgbw_color = (red, green, blue, white) self._rgbw_color = (red, green, blue, white)
# Light supports rgbw, set color mode to rgbw # Light supports rgbw, set color mode to rgbw
self._color_mode = COLOR_MODE_RGBW self._color_mode = ColorMode.RGBW
# only one white channel (cool white) = rgbw support # only one white channel (cool white) = rgbw support
elif cw_val: elif cw_val:
self._supports_rgbw = True self._supports_rgbw = True
white = multi_color.get(COLOR_SWITCH_COMBINED_COLD_WHITE, cw_val.value) white = multi_color.get(COLOR_SWITCH_COMBINED_COLD_WHITE, cw_val.value)
self._rgbw_color = (red, green, blue, white) self._rgbw_color = (red, green, blue, white)
# Light supports rgbw, set color mode to rgbw # Light supports rgbw, set color mode to rgbw
self._color_mode = COLOR_MODE_RGBW self._color_mode = ColorMode.RGBW
class ZwaveBlackIsOffLight(ZwaveLight): class ZwaveBlackIsOffLight(ZwaveLight):
@ -452,7 +449,7 @@ class ZwaveBlackIsOffLight(ZwaveLight):
super().__init__(config_entry, client, info) super().__init__(config_entry, client, info)
self._last_color: dict[str, int] | None = None self._last_color: dict[str, int] | None = None
self._supported_color_modes.discard(COLOR_MODE_BRIGHTNESS) self._supported_color_modes.discard(ColorMode.BRIGHTNESS)
@property @property
def brightness(self) -> int: def brightness(self) -> int: