Migrate nanoleaf light to color_mode ()

This commit is contained in:
Erik Montnemery 2022-04-15 20:09:47 +02:00 committed by GitHub
parent 5f6a970826
commit 353c091973
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -12,9 +12,8 @@ from homeassistant.components.light import (
ATTR_EFFECT, ATTR_EFFECT,
ATTR_HS_COLOR, ATTR_HS_COLOR,
ATTR_TRANSITION, ATTR_TRANSITION,
SUPPORT_BRIGHTNESS, COLOR_MODE_COLOR_TEMP,
SUPPORT_COLOR, COLOR_MODE_HS,
SUPPORT_COLOR_TEMP,
SUPPORT_EFFECT, SUPPORT_EFFECT,
SUPPORT_TRANSITION, SUPPORT_TRANSITION,
LightEntity, LightEntity,
@ -47,6 +46,9 @@ async def async_setup_entry(
class NanoleafLight(NanoleafEntity, LightEntity): class NanoleafLight(NanoleafEntity, LightEntity):
"""Representation of a Nanoleaf Light.""" """Representation of a Nanoleaf Light."""
_attr_supported_color_modes = {COLOR_MODE_COLOR_TEMP, COLOR_MODE_HS}
_attr_supported_features = SUPPORT_EFFECT | SUPPORT_TRANSITION
def __init__(self, nanoleaf: Nanoleaf, coordinator: DataUpdateCoordinator) -> None: def __init__(self, nanoleaf: Nanoleaf, coordinator: DataUpdateCoordinator) -> None:
"""Initialize the Nanoleaf light.""" """Initialize the Nanoleaf light."""
super().__init__(nanoleaf, coordinator) super().__init__(nanoleaf, coordinator)
@ -97,15 +99,14 @@ class NanoleafLight(NanoleafEntity, LightEntity):
return self._nanoleaf.hue, self._nanoleaf.saturation return self._nanoleaf.hue, self._nanoleaf.saturation
@property @property
def supported_features(self) -> int: def color_mode(self) -> str | None:
"""Flag supported features.""" """Return the color mode of the light."""
return ( # According to API docs, color mode is "ct", "effect" or "hs"
SUPPORT_BRIGHTNESS # https://forum.nanoleaf.me/docs/openapi#_4qgqrz96f44d
| SUPPORT_COLOR_TEMP if self._nanoleaf.color_mode == "ct":
| SUPPORT_EFFECT return COLOR_MODE_COLOR_TEMP
| SUPPORT_COLOR # Home Assistant does not have an "effect" color mode, just report hs
| SUPPORT_TRANSITION return COLOR_MODE_HS
)
async def async_turn_on(self, **kwargs: Any) -> None: async def async_turn_on(self, **kwargs: Any) -> None:
"""Instruct the light to turn on.""" """Instruct the light to turn on."""