mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
Create abstraction for Generic YeeLight (#97939)
* Create abstraction for Generic YeeLight * Update light.py
This commit is contained in:
parent
91faa53843
commit
732dac6f05
@ -238,7 +238,7 @@ def _parse_custom_effects(effects_config) -> dict[str, dict[str, Any]]:
|
|||||||
def _async_cmd(func):
|
def _async_cmd(func):
|
||||||
"""Define a wrapper to catch exceptions from the bulb."""
|
"""Define a wrapper to catch exceptions from the bulb."""
|
||||||
|
|
||||||
async def _async_wrap(self: YeelightGenericLight, *args, **kwargs):
|
async def _async_wrap(self: YeelightBaseLight, *args, **kwargs):
|
||||||
for attempts in range(2):
|
for attempts in range(2):
|
||||||
try:
|
try:
|
||||||
_LOGGER.debug("Calling %s with %s %s", func, args, kwargs)
|
_LOGGER.debug("Calling %s with %s %s", func, args, kwargs)
|
||||||
@ -403,8 +403,8 @@ def _async_setup_services(hass: HomeAssistant):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class YeelightGenericLight(YeelightEntity, LightEntity):
|
class YeelightBaseLight(YeelightEntity, LightEntity):
|
||||||
"""Representation of a Yeelight generic light."""
|
"""Abstract Yeelight light."""
|
||||||
|
|
||||||
_attr_color_mode = ColorMode.BRIGHTNESS
|
_attr_color_mode = ColorMode.BRIGHTNESS
|
||||||
_attr_supported_color_modes = {ColorMode.BRIGHTNESS}
|
_attr_supported_color_modes = {ColorMode.BRIGHTNESS}
|
||||||
@ -861,7 +861,13 @@ class YeelightGenericLight(YeelightEntity, LightEntity):
|
|||||||
await self._bulb.async_set_scene(scene_class, *args)
|
await self._bulb.async_set_scene(scene_class, *args)
|
||||||
|
|
||||||
|
|
||||||
class YeelightColorLightSupport(YeelightGenericLight):
|
class YeelightGenericLight(YeelightBaseLight):
|
||||||
|
"""Representation of a generic Yeelight."""
|
||||||
|
|
||||||
|
_attr_name = None
|
||||||
|
|
||||||
|
|
||||||
|
class YeelightColorLightSupport(YeelightBaseLight):
|
||||||
"""Representation of a Color Yeelight light support."""
|
"""Representation of a Color Yeelight light support."""
|
||||||
|
|
||||||
_attr_supported_color_modes = {ColorMode.COLOR_TEMP, ColorMode.HS, ColorMode.RGB}
|
_attr_supported_color_modes = {ColorMode.COLOR_TEMP, ColorMode.HS, ColorMode.RGB}
|
||||||
@ -884,7 +890,7 @@ class YeelightColorLightSupport(YeelightGenericLight):
|
|||||||
return YEELIGHT_COLOR_EFFECT_LIST
|
return YEELIGHT_COLOR_EFFECT_LIST
|
||||||
|
|
||||||
|
|
||||||
class YeelightWhiteTempLightSupport(YeelightGenericLight):
|
class YeelightWhiteTempLightSupport(YeelightBaseLight):
|
||||||
"""Representation of a White temp Yeelight light."""
|
"""Representation of a White temp Yeelight light."""
|
||||||
|
|
||||||
_attr_name = None
|
_attr_name = None
|
||||||
@ -904,7 +910,7 @@ class YeelightNightLightSupport:
|
|||||||
return PowerMode.NORMAL
|
return PowerMode.NORMAL
|
||||||
|
|
||||||
|
|
||||||
class YeelightWithoutNightlightSwitchMixIn(YeelightGenericLight):
|
class YeelightWithoutNightlightSwitchMixIn(YeelightBaseLight):
|
||||||
"""A mix-in for yeelights without a nightlight switch."""
|
"""A mix-in for yeelights without a nightlight switch."""
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@ -940,7 +946,7 @@ class YeelightColorLightWithoutNightlightSwitchLight(
|
|||||||
|
|
||||||
|
|
||||||
class YeelightColorLightWithNightlightSwitch(
|
class YeelightColorLightWithNightlightSwitch(
|
||||||
YeelightNightLightSupport, YeelightColorLightSupport, YeelightGenericLight
|
YeelightNightLightSupport, YeelightColorLightSupport, YeelightBaseLight
|
||||||
):
|
):
|
||||||
"""Representation of a Yeelight with rgb support and nightlight.
|
"""Representation of a Yeelight with rgb support and nightlight.
|
||||||
|
|
||||||
@ -964,7 +970,7 @@ class YeelightWhiteTempWithoutNightlightSwitch(
|
|||||||
|
|
||||||
|
|
||||||
class YeelightWithNightLight(
|
class YeelightWithNightLight(
|
||||||
YeelightNightLightSupport, YeelightWhiteTempLightSupport, YeelightGenericLight
|
YeelightNightLightSupport, YeelightWhiteTempLightSupport, YeelightBaseLight
|
||||||
):
|
):
|
||||||
"""Representation of a Yeelight with temp only support and nightlight.
|
"""Representation of a Yeelight with temp only support and nightlight.
|
||||||
|
|
||||||
@ -979,7 +985,7 @@ class YeelightWithNightLight(
|
|||||||
return super().is_on and not self.device.is_nightlight_enabled
|
return super().is_on and not self.device.is_nightlight_enabled
|
||||||
|
|
||||||
|
|
||||||
class YeelightNightLightMode(YeelightGenericLight):
|
class YeelightNightLightMode(YeelightBaseLight):
|
||||||
"""Representation of a Yeelight when in nightlight mode."""
|
"""Representation of a Yeelight when in nightlight mode."""
|
||||||
|
|
||||||
_attr_color_mode = ColorMode.BRIGHTNESS
|
_attr_color_mode = ColorMode.BRIGHTNESS
|
||||||
|
Loading…
x
Reference in New Issue
Block a user