Use ColorMode enum in nanoleaf (#70527)

pull/70543/head
epenet 2022-04-23 21:25:03 +02:00 committed by GitHub
parent f68764a053
commit 1d5096638e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 6 deletions

View File

@ -12,10 +12,9 @@ from homeassistant.components.light import (
ATTR_EFFECT, ATTR_EFFECT,
ATTR_HS_COLOR, ATTR_HS_COLOR,
ATTR_TRANSITION, ATTR_TRANSITION,
COLOR_MODE_COLOR_TEMP,
COLOR_MODE_HS,
SUPPORT_EFFECT, SUPPORT_EFFECT,
SUPPORT_TRANSITION, SUPPORT_TRANSITION,
ColorMode,
LightEntity, LightEntity,
) )
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
@ -46,7 +45,7 @@ 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_color_modes = {ColorMode.COLOR_TEMP, ColorMode.HS}
_attr_supported_features = SUPPORT_EFFECT | SUPPORT_TRANSITION _attr_supported_features = SUPPORT_EFFECT | SUPPORT_TRANSITION
def __init__(self, nanoleaf: Nanoleaf, coordinator: DataUpdateCoordinator) -> None: def __init__(self, nanoleaf: Nanoleaf, coordinator: DataUpdateCoordinator) -> None:
@ -99,14 +98,14 @@ class NanoleafLight(NanoleafEntity, LightEntity):
return self._nanoleaf.hue, self._nanoleaf.saturation return self._nanoleaf.hue, self._nanoleaf.saturation
@property @property
def color_mode(self) -> str | None: def color_mode(self) -> ColorMode | None:
"""Return the color mode of the light.""" """Return the color mode of the light."""
# According to API docs, color mode is "ct", "effect" or "hs" # According to API docs, color mode is "ct", "effect" or "hs"
# https://forum.nanoleaf.me/docs/openapi#_4qgqrz96f44d # https://forum.nanoleaf.me/docs/openapi#_4qgqrz96f44d
if self._nanoleaf.color_mode == "ct": if self._nanoleaf.color_mode == "ct":
return COLOR_MODE_COLOR_TEMP return ColorMode.COLOR_TEMP
# Home Assistant does not have an "effect" color mode, just report hs # Home Assistant does not have an "effect" color mode, just report hs
return COLOR_MODE_HS return ColorMode.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."""