mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
Fix light color mode in zwave_js (#108783)
This commit is contained in:
parent
fabf8802f5
commit
da7d2ef228
@ -151,7 +151,7 @@ class ZwaveLight(ZWaveBaseEntity, LightEntity):
|
||||
add_to_watched_value_ids=False,
|
||||
)
|
||||
|
||||
self._calculate_color_values()
|
||||
self._calculate_color_support()
|
||||
if self._supports_rgbw:
|
||||
self._supported_color_modes.add(ColorMode.RGBW)
|
||||
elif self._supports_color:
|
||||
@ -160,6 +160,7 @@ class ZwaveLight(ZWaveBaseEntity, LightEntity):
|
||||
self._supported_color_modes.add(ColorMode.COLOR_TEMP)
|
||||
if not self._supported_color_modes:
|
||||
self._supported_color_modes.add(ColorMode.BRIGHTNESS)
|
||||
self._calculate_color_values()
|
||||
|
||||
# Entity class attributes
|
||||
self.supports_brightness_transition = bool(
|
||||
@ -374,8 +375,8 @@ class ZwaveLight(ZWaveBaseEntity, LightEntity):
|
||||
self.async_write_ha_state()
|
||||
|
||||
@callback
|
||||
def _calculate_color_values(self) -> None:
|
||||
"""Calculate light colors."""
|
||||
def _get_color_values(self) -> tuple[Value | None, ...]:
|
||||
"""Get light colors."""
|
||||
# NOTE: We lookup all values here (instead of relying on the multicolor one)
|
||||
# to find out what colors are supported
|
||||
# as this is a simple lookup by key, this not heavy
|
||||
@ -404,6 +405,30 @@ class ZwaveLight(ZWaveBaseEntity, LightEntity):
|
||||
CommandClass.SWITCH_COLOR,
|
||||
value_property_key=ColorComponent.COLD_WHITE.value,
|
||||
)
|
||||
return (red_val, green_val, blue_val, ww_val, cw_val)
|
||||
|
||||
@callback
|
||||
def _calculate_color_support(self) -> None:
|
||||
"""Calculate light colors."""
|
||||
(red_val, green_val, blue_val, ww_val, cw_val) = self._get_color_values()
|
||||
# RGB support
|
||||
if red_val and green_val and blue_val:
|
||||
self._supports_color = True
|
||||
# color temperature support
|
||||
if ww_val and cw_val:
|
||||
self._supports_color_temp = True
|
||||
# only one white channel (warm white) = rgbw support
|
||||
elif red_val and green_val and blue_val and ww_val:
|
||||
self._supports_rgbw = True
|
||||
# only one white channel (cool white) = rgbw support
|
||||
elif cw_val:
|
||||
self._supports_rgbw = True
|
||||
|
||||
@callback
|
||||
def _calculate_color_values(self) -> None:
|
||||
"""Calculate light colors."""
|
||||
(red_val, green_val, blue_val, ww_val, cw_val) = self._get_color_values()
|
||||
|
||||
# prefer the (new) combined color property
|
||||
# https://github.com/zwave-js/node-zwave-js/pull/1782
|
||||
combined_color_val = self.get_zwave_value(
|
||||
@ -416,8 +441,11 @@ class ZwaveLight(ZWaveBaseEntity, LightEntity):
|
||||
else:
|
||||
multi_color = {}
|
||||
|
||||
# Default: Brightness (no color)
|
||||
self._color_mode = ColorMode.BRIGHTNESS
|
||||
# Default: Brightness (no color) or Unknown
|
||||
if self.supported_color_modes == {ColorMode.BRIGHTNESS}:
|
||||
self._color_mode = ColorMode.BRIGHTNESS
|
||||
else:
|
||||
self._color_mode = ColorMode.UNKNOWN
|
||||
|
||||
# RGB support
|
||||
if red_val and green_val and blue_val:
|
||||
@ -425,7 +453,6 @@ class ZwaveLight(ZWaveBaseEntity, LightEntity):
|
||||
red = multi_color.get(COLOR_SWITCH_COMBINED_RED, red_val.value)
|
||||
green = multi_color.get(COLOR_SWITCH_COMBINED_GREEN, green_val.value)
|
||||
blue = multi_color.get(COLOR_SWITCH_COMBINED_BLUE, blue_val.value)
|
||||
self._supports_color = True
|
||||
if None not in (red, green, blue):
|
||||
# convert to HS
|
||||
self._hs_color = color_util.color_RGB_to_hs(red, green, blue)
|
||||
@ -434,7 +461,6 @@ class ZwaveLight(ZWaveBaseEntity, LightEntity):
|
||||
|
||||
# color temperature support
|
||||
if ww_val and cw_val:
|
||||
self._supports_color_temp = True
|
||||
warm_white = multi_color.get(COLOR_SWITCH_COMBINED_WARM_WHITE, ww_val.value)
|
||||
cold_white = multi_color.get(COLOR_SWITCH_COMBINED_COLD_WHITE, cw_val.value)
|
||||
# Calculate color temps based on whites
|
||||
@ -449,7 +475,6 @@ class ZwaveLight(ZWaveBaseEntity, LightEntity):
|
||||
self._color_temp = None
|
||||
# only one white channel (warm white) = rgbw support
|
||||
elif red_val and green_val and blue_val and ww_val:
|
||||
self._supports_rgbw = True
|
||||
white = multi_color.get(COLOR_SWITCH_COMBINED_WARM_WHITE, ww_val.value)
|
||||
self._rgbw_color = (red, green, blue, white)
|
||||
# Light supports rgbw, set color mode to rgbw
|
||||
|
Loading…
x
Reference in New Issue
Block a user