Use ColorMode enum in wiz (#70554)
This commit is contained in:
parent
5a0bbedef8
commit
753a13d68d
1 changed files with 16 additions and 18 deletions
|
@ -13,11 +13,8 @@ from homeassistant.components.light import (
|
||||||
ATTR_EFFECT,
|
ATTR_EFFECT,
|
||||||
ATTR_RGBW_COLOR,
|
ATTR_RGBW_COLOR,
|
||||||
ATTR_RGBWW_COLOR,
|
ATTR_RGBWW_COLOR,
|
||||||
COLOR_MODE_BRIGHTNESS,
|
|
||||||
COLOR_MODE_COLOR_TEMP,
|
|
||||||
COLOR_MODE_RGBW,
|
|
||||||
COLOR_MODE_RGBWW,
|
|
||||||
SUPPORT_EFFECT,
|
SUPPORT_EFFECT,
|
||||||
|
ColorMode,
|
||||||
LightEntity,
|
LightEntity,
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
|
@ -32,7 +29,7 @@ from .const import DOMAIN
|
||||||
from .entity import WizToggleEntity
|
from .entity import WizToggleEntity
|
||||||
from .models import WizData
|
from .models import WizData
|
||||||
|
|
||||||
RGB_WHITE_CHANNELS_COLOR_MODE = {1: COLOR_MODE_RGBW, 2: COLOR_MODE_RGBWW}
|
RGB_WHITE_CHANNELS_COLOR_MODE = {1: ColorMode.RGBW, 2: ColorMode.RGBWW}
|
||||||
|
|
||||||
|
|
||||||
def _async_pilot_builder(**kwargs: Any) -> PilotBuilder:
|
def _async_pilot_builder(**kwargs: Any) -> PilotBuilder:
|
||||||
|
@ -79,14 +76,15 @@ class WizBulbEntity(WizToggleEntity, LightEntity):
|
||||||
super().__init__(wiz_data, name)
|
super().__init__(wiz_data, name)
|
||||||
bulb_type: BulbType = self._device.bulbtype
|
bulb_type: BulbType = self._device.bulbtype
|
||||||
features: Features = bulb_type.features
|
features: Features = bulb_type.features
|
||||||
color_modes = set()
|
self._attr_supported_color_modes: set[ColorMode | str] = set()
|
||||||
if features.color:
|
if features.color:
|
||||||
color_modes.add(RGB_WHITE_CHANNELS_COLOR_MODE[bulb_type.white_channels])
|
self._attr_supported_color_modes.add(
|
||||||
|
RGB_WHITE_CHANNELS_COLOR_MODE[bulb_type.white_channels]
|
||||||
|
)
|
||||||
if features.color_tmp:
|
if features.color_tmp:
|
||||||
color_modes.add(COLOR_MODE_COLOR_TEMP)
|
self._attr_supported_color_modes.add(ColorMode.COLOR_TEMP)
|
||||||
if not color_modes and features.brightness:
|
if not self._attr_supported_color_modes and features.brightness:
|
||||||
color_modes.add(COLOR_MODE_BRIGHTNESS)
|
self._attr_supported_color_modes.add(ColorMode.BRIGHTNESS)
|
||||||
self._attr_supported_color_modes = color_modes
|
|
||||||
self._attr_effect_list = wiz_data.scenes
|
self._attr_effect_list = wiz_data.scenes
|
||||||
if bulb_type.bulb_type != BulbClass.DW:
|
if bulb_type.bulb_type != BulbClass.DW:
|
||||||
kelvin = bulb_type.kelvin_range
|
kelvin = bulb_type.kelvin_range
|
||||||
|
@ -104,21 +102,21 @@ class WizBulbEntity(WizToggleEntity, LightEntity):
|
||||||
assert color_modes is not None
|
assert color_modes is not None
|
||||||
if (brightness := state.get_brightness()) is not None:
|
if (brightness := state.get_brightness()) is not None:
|
||||||
self._attr_brightness = max(0, min(255, brightness))
|
self._attr_brightness = max(0, min(255, brightness))
|
||||||
if COLOR_MODE_COLOR_TEMP in color_modes and (
|
if ColorMode.COLOR_TEMP in color_modes and (
|
||||||
color_temp := state.get_colortemp()
|
color_temp := state.get_colortemp()
|
||||||
):
|
):
|
||||||
self._attr_color_mode = COLOR_MODE_COLOR_TEMP
|
self._attr_color_mode = ColorMode.COLOR_TEMP
|
||||||
self._attr_color_temp = color_temperature_kelvin_to_mired(color_temp)
|
self._attr_color_temp = color_temperature_kelvin_to_mired(color_temp)
|
||||||
elif (
|
elif (
|
||||||
COLOR_MODE_RGBWW in color_modes and (rgbww := state.get_rgbww()) is not None
|
ColorMode.RGBWW in color_modes and (rgbww := state.get_rgbww()) is not None
|
||||||
):
|
):
|
||||||
self._attr_rgbww_color = rgbww
|
self._attr_rgbww_color = rgbww
|
||||||
self._attr_color_mode = COLOR_MODE_RGBWW
|
self._attr_color_mode = ColorMode.RGBWW
|
||||||
elif COLOR_MODE_RGBW in color_modes and (rgbw := state.get_rgbw()) is not None:
|
elif ColorMode.RGBW in color_modes and (rgbw := state.get_rgbw()) is not None:
|
||||||
self._attr_rgbw_color = rgbw
|
self._attr_rgbw_color = rgbw
|
||||||
self._attr_color_mode = COLOR_MODE_RGBW
|
self._attr_color_mode = ColorMode.RGBW
|
||||||
else:
|
else:
|
||||||
self._attr_color_mode = COLOR_MODE_BRIGHTNESS
|
self._attr_color_mode = ColorMode.BRIGHTNESS
|
||||||
self._attr_effect = state.get_scene()
|
self._attr_effect = state.get_scene()
|
||||||
super()._async_update_attrs()
|
super()._async_update_attrs()
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue