Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 22 additions & 27 deletions homeassistant/components/yeelight/light.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,12 @@
ATTR_KELVIN,
ATTR_RGB_COLOR,
ATTR_TRANSITION,
COLOR_MODE_BRIGHTNESS,
COLOR_MODE_COLOR_TEMP,
COLOR_MODE_HS,
COLOR_MODE_ONOFF,
COLOR_MODE_RGB,
COLOR_MODE_UNKNOWN,
FLASH_LONG,
FLASH_SHORT,
SUPPORT_EFFECT,
SUPPORT_FLASH,
SUPPORT_TRANSITION,
ColorMode,
LightEntity,
)
from homeassistant.config_entries import ConfigEntry
Expand Down Expand Up @@ -413,8 +408,8 @@ async def _async_set_auto_delay_off_scene(entity, service_call):
class YeelightGenericLight(YeelightEntity, LightEntity):
"""Representation of a Yeelight generic light."""

_attr_color_mode: str | None = COLOR_MODE_BRIGHTNESS
_attr_supported_color_modes: set[str] | None = {COLOR_MODE_BRIGHTNESS}
_attr_color_mode = ColorMode.BRIGHTNESS
_attr_supported_color_modes = {ColorMode.BRIGHTNESS}
_attr_should_poll = False

def __init__(self, device, entry, custom_effects=None):
Expand Down Expand Up @@ -640,12 +635,12 @@ async def async_set_hs(self, hs_color, duration) -> None:
if (
not hs_color
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
if (
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
):
_LOGGER.debug("HS already set to: %s", hs_color)
Expand All @@ -665,12 +660,12 @@ async def async_set_rgb(self, rgb, duration) -> None:
if (
not rgb
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
if (
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
):
_LOGGER.debug("RGB already set to: %s", rgb)
Expand All @@ -690,14 +685,14 @@ async def async_set_colortemp(self, colortemp, duration) -> None:
if (
not colortemp
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
temp_in_k = mired_to_kelvin(colortemp)

if (
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
):
_LOGGER.debug("Color temp already set to: %s", temp_in_k)
Expand Down Expand Up @@ -882,31 +877,31 @@ async def async_set_scene(self, scene_class, *args):
class YeelightColorLightSupport(YeelightGenericLight):
"""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
def color_mode(self):
def color_mode(self) -> ColorMode:
"""Return the color mode."""
color_mode = int(self._get_property("color_mode"))
if color_mode == 1: # RGB
return COLOR_MODE_RGB
return ColorMode.RGB
if color_mode == 2: # color temperature
return COLOR_MODE_COLOR_TEMP
return ColorMode.COLOR_TEMP
if color_mode == 3: # hsv
return COLOR_MODE_HS
return ColorMode.HS
_LOGGER.debug("Light reported unknown color mode: %s", color_mode)
return COLOR_MODE_UNKNOWN
return ColorMode.UNKNOWN

@property
def _predefined_effects(self):
return YEELIGHT_COLOR_EFFECT_LIST


class YeelightWhiteTempLightSupport:
class YeelightWhiteTempLightSupport(YeelightGenericLight):
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This inheritance was added to solve mypy issues.

"""Representation of a White temp Yeelight light."""

_attr_color_mode: str | None = COLOR_MODE_COLOR_TEMP
_attr_supported_color_modes: set[str] | None = {COLOR_MODE_COLOR_TEMP}
_attr_color_mode = ColorMode.COLOR_TEMP
_attr_supported_color_modes = {ColorMode.COLOR_TEMP}

@property
def _predefined_effects(self):
Expand Down Expand Up @@ -985,8 +980,8 @@ def is_on(self) -> bool:
class YeelightNightLightMode(YeelightGenericLight):
"""Representation of a Yeelight when in nightlight mode."""

_attr_color_mode = COLOR_MODE_BRIGHTNESS
_attr_supported_color_modes = {COLOR_MODE_BRIGHTNESS}
_attr_color_mode = ColorMode.BRIGHTNESS
_attr_supported_color_modes = {ColorMode.BRIGHTNESS}

@property
def unique_id(self) -> str:
Expand Down Expand Up @@ -1037,8 +1032,8 @@ class YeelightNightLightModeWithoutBrightnessControl(YeelightNightLightMode):
It represents case when nightlight mode brightness control is not supported.
"""

_attr_color_mode = COLOR_MODE_ONOFF
_attr_supported_color_modes = {COLOR_MODE_ONOFF}
_attr_color_mode = ColorMode.ONOFF
_attr_supported_color_modes = {ColorMode.ONOFF}


class YeelightWithAmbientWithoutNightlight(YeelightWhiteTempWithoutNightlightSwitch):
Expand Down