mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Use ColorMode enum in yeelight (#70560)
This commit is contained in:
parent
89200b27f0
commit
1179a88808
@ -21,17 +21,12 @@ from homeassistant.components.light import (
|
|||||||
ATTR_KELVIN,
|
ATTR_KELVIN,
|
||||||
ATTR_RGB_COLOR,
|
ATTR_RGB_COLOR,
|
||||||
ATTR_TRANSITION,
|
ATTR_TRANSITION,
|
||||||
COLOR_MODE_BRIGHTNESS,
|
|
||||||
COLOR_MODE_COLOR_TEMP,
|
|
||||||
COLOR_MODE_HS,
|
|
||||||
COLOR_MODE_ONOFF,
|
|
||||||
COLOR_MODE_RGB,
|
|
||||||
COLOR_MODE_UNKNOWN,
|
|
||||||
FLASH_LONG,
|
FLASH_LONG,
|
||||||
FLASH_SHORT,
|
FLASH_SHORT,
|
||||||
SUPPORT_EFFECT,
|
SUPPORT_EFFECT,
|
||||||
SUPPORT_FLASH,
|
SUPPORT_FLASH,
|
||||||
SUPPORT_TRANSITION,
|
SUPPORT_TRANSITION,
|
||||||
|
ColorMode,
|
||||||
LightEntity,
|
LightEntity,
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
@ -413,8 +408,8 @@ def _async_setup_services(hass: HomeAssistant):
|
|||||||
class YeelightGenericLight(YeelightEntity, LightEntity):
|
class YeelightGenericLight(YeelightEntity, LightEntity):
|
||||||
"""Representation of a Yeelight generic light."""
|
"""Representation of a Yeelight generic light."""
|
||||||
|
|
||||||
_attr_color_mode: str | None = COLOR_MODE_BRIGHTNESS
|
_attr_color_mode = ColorMode.BRIGHTNESS
|
||||||
_attr_supported_color_modes: set[str] | None = {COLOR_MODE_BRIGHTNESS}
|
_attr_supported_color_modes = {ColorMode.BRIGHTNESS}
|
||||||
_attr_should_poll = False
|
_attr_should_poll = False
|
||||||
|
|
||||||
def __init__(self, device, entry, custom_effects=None):
|
def __init__(self, device, entry, custom_effects=None):
|
||||||
@ -640,12 +635,12 @@ class YeelightGenericLight(YeelightEntity, LightEntity):
|
|||||||
if (
|
if (
|
||||||
not hs_color
|
not hs_color
|
||||||
or not self.supported_color_modes
|
or not self.supported_color_modes
|
||||||
or COLOR_MODE_HS not in self.supported_color_modes
|
or ColorMode.HS not in self.supported_color_modes
|
||||||
):
|
):
|
||||||
return
|
return
|
||||||
if (
|
if (
|
||||||
not self.device.is_color_flow_enabled
|
not self.device.is_color_flow_enabled
|
||||||
and self.color_mode == COLOR_MODE_HS
|
and self.color_mode == ColorMode.HS
|
||||||
and self.hs_color == hs_color
|
and self.hs_color == hs_color
|
||||||
):
|
):
|
||||||
_LOGGER.debug("HS already set to: %s", hs_color)
|
_LOGGER.debug("HS already set to: %s", hs_color)
|
||||||
@ -665,12 +660,12 @@ class YeelightGenericLight(YeelightEntity, LightEntity):
|
|||||||
if (
|
if (
|
||||||
not rgb
|
not rgb
|
||||||
or not self.supported_color_modes
|
or not self.supported_color_modes
|
||||||
or COLOR_MODE_RGB not in self.supported_color_modes
|
or ColorMode.RGB not in self.supported_color_modes
|
||||||
):
|
):
|
||||||
return
|
return
|
||||||
if (
|
if (
|
||||||
not self.device.is_color_flow_enabled
|
not self.device.is_color_flow_enabled
|
||||||
and self.color_mode == COLOR_MODE_RGB
|
and self.color_mode == ColorMode.RGB
|
||||||
and self.rgb_color == rgb
|
and self.rgb_color == rgb
|
||||||
):
|
):
|
||||||
_LOGGER.debug("RGB already set to: %s", rgb)
|
_LOGGER.debug("RGB already set to: %s", rgb)
|
||||||
@ -690,14 +685,14 @@ class YeelightGenericLight(YeelightEntity, LightEntity):
|
|||||||
if (
|
if (
|
||||||
not colortemp
|
not colortemp
|
||||||
or not self.supported_color_modes
|
or not self.supported_color_modes
|
||||||
or COLOR_MODE_COLOR_TEMP not in self.supported_color_modes
|
or ColorMode.COLOR_TEMP not in self.supported_color_modes
|
||||||
):
|
):
|
||||||
return
|
return
|
||||||
temp_in_k = mired_to_kelvin(colortemp)
|
temp_in_k = mired_to_kelvin(colortemp)
|
||||||
|
|
||||||
if (
|
if (
|
||||||
not self.device.is_color_flow_enabled
|
not self.device.is_color_flow_enabled
|
||||||
and self.color_mode == COLOR_MODE_COLOR_TEMP
|
and self.color_mode == ColorMode.COLOR_TEMP
|
||||||
and self.color_temp == colortemp
|
and self.color_temp == colortemp
|
||||||
):
|
):
|
||||||
_LOGGER.debug("Color temp already set to: %s", temp_in_k)
|
_LOGGER.debug("Color temp already set to: %s", temp_in_k)
|
||||||
@ -882,31 +877,31 @@ class YeelightGenericLight(YeelightEntity, LightEntity):
|
|||||||
class YeelightColorLightSupport(YeelightGenericLight):
|
class YeelightColorLightSupport(YeelightGenericLight):
|
||||||
"""Representation of a Color Yeelight light support."""
|
"""Representation of a Color Yeelight light support."""
|
||||||
|
|
||||||
_attr_supported_color_modes = {COLOR_MODE_COLOR_TEMP, COLOR_MODE_HS, COLOR_MODE_RGB}
|
_attr_supported_color_modes = {ColorMode.COLOR_TEMP, ColorMode.HS, ColorMode.RGB}
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def color_mode(self):
|
def color_mode(self) -> ColorMode:
|
||||||
"""Return the color mode."""
|
"""Return the color mode."""
|
||||||
color_mode = int(self._get_property("color_mode"))
|
color_mode = int(self._get_property("color_mode"))
|
||||||
if color_mode == 1: # RGB
|
if color_mode == 1: # RGB
|
||||||
return COLOR_MODE_RGB
|
return ColorMode.RGB
|
||||||
if color_mode == 2: # color temperature
|
if color_mode == 2: # color temperature
|
||||||
return COLOR_MODE_COLOR_TEMP
|
return ColorMode.COLOR_TEMP
|
||||||
if color_mode == 3: # hsv
|
if color_mode == 3: # hsv
|
||||||
return COLOR_MODE_HS
|
return ColorMode.HS
|
||||||
_LOGGER.debug("Light reported unknown color mode: %s", color_mode)
|
_LOGGER.debug("Light reported unknown color mode: %s", color_mode)
|
||||||
return COLOR_MODE_UNKNOWN
|
return ColorMode.UNKNOWN
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def _predefined_effects(self):
|
def _predefined_effects(self):
|
||||||
return YEELIGHT_COLOR_EFFECT_LIST
|
return YEELIGHT_COLOR_EFFECT_LIST
|
||||||
|
|
||||||
|
|
||||||
class YeelightWhiteTempLightSupport:
|
class YeelightWhiteTempLightSupport(YeelightGenericLight):
|
||||||
"""Representation of a White temp Yeelight light."""
|
"""Representation of a White temp Yeelight light."""
|
||||||
|
|
||||||
_attr_color_mode: str | None = COLOR_MODE_COLOR_TEMP
|
_attr_color_mode = ColorMode.COLOR_TEMP
|
||||||
_attr_supported_color_modes: set[str] | None = {COLOR_MODE_COLOR_TEMP}
|
_attr_supported_color_modes = {ColorMode.COLOR_TEMP}
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def _predefined_effects(self):
|
def _predefined_effects(self):
|
||||||
@ -985,8 +980,8 @@ class YeelightWithNightLight(
|
|||||||
class YeelightNightLightMode(YeelightGenericLight):
|
class YeelightNightLightMode(YeelightGenericLight):
|
||||||
"""Representation of a Yeelight when in nightlight mode."""
|
"""Representation of a Yeelight when in nightlight mode."""
|
||||||
|
|
||||||
_attr_color_mode = COLOR_MODE_BRIGHTNESS
|
_attr_color_mode = ColorMode.BRIGHTNESS
|
||||||
_attr_supported_color_modes = {COLOR_MODE_BRIGHTNESS}
|
_attr_supported_color_modes = {ColorMode.BRIGHTNESS}
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def unique_id(self) -> str:
|
def unique_id(self) -> str:
|
||||||
@ -1037,8 +1032,8 @@ class YeelightNightLightModeWithoutBrightnessControl(YeelightNightLightMode):
|
|||||||
It represents case when nightlight mode brightness control is not supported.
|
It represents case when nightlight mode brightness control is not supported.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
_attr_color_mode = COLOR_MODE_ONOFF
|
_attr_color_mode = ColorMode.ONOFF
|
||||||
_attr_supported_color_modes = {COLOR_MODE_ONOFF}
|
_attr_supported_color_modes = {ColorMode.ONOFF}
|
||||||
|
|
||||||
|
|
||||||
class YeelightWithAmbientWithoutNightlight(YeelightWhiteTempWithoutNightlightSwitch):
|
class YeelightWithAmbientWithoutNightlight(YeelightWhiteTempWithoutNightlightSwitch):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user