Migrate plum_lightpad light to ColorMode (#70880)

This commit is contained in:
epenet 2022-04-27 16:17:48 +02:00 committed by GitHub
parent 0b40123fd9
commit 25d2c63827
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -8,8 +8,7 @@ from plumlightpad import Plum
from homeassistant.components.light import ( from homeassistant.components.light import (
ATTR_BRIGHTNESS, ATTR_BRIGHTNESS,
ATTR_HS_COLOR, ATTR_HS_COLOR,
SUPPORT_BRIGHTNESS, ColorMode,
SUPPORT_COLOR,
LightEntity, LightEntity,
) )
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
@ -115,11 +114,16 @@ class PlumLight(LightEntity):
return self._brightness > 0 return self._brightness > 0
@property @property
def supported_features(self): def color_mode(self) -> ColorMode:
"""Flag supported features.""" """Flag supported features."""
if self._load.dimmable: if self._load.dimmable:
return SUPPORT_BRIGHTNESS return ColorMode.BRIGHTNESS
return 0 return ColorMode.ONOFF
@property
def supported_color_modes(self) -> set[ColorMode]:
"""Flag supported color modes."""
return {self.color_mode}
async def async_turn_on(self, **kwargs): async def async_turn_on(self, **kwargs):
"""Turn the light on.""" """Turn the light on."""
@ -136,6 +140,9 @@ class PlumLight(LightEntity):
class GlowRing(LightEntity): class GlowRing(LightEntity):
"""Representation of a Plum Lightpad dimmer glow ring.""" """Representation of a Plum Lightpad dimmer glow ring."""
_attr_color_mode = ColorMode.HS
_attr_supported_color_modes = {ColorMode.HS}
def __init__(self, lightpad): def __init__(self, lightpad):
"""Initialize the light.""" """Initialize the light."""
self._lightpad = lightpad self._lightpad = lightpad
@ -215,11 +222,6 @@ class GlowRing(LightEntity):
"""Return the crop-portrait icon representing the glow ring.""" """Return the crop-portrait icon representing the glow ring."""
return "mdi:crop-portrait" return "mdi:crop-portrait"
@property
def supported_features(self):
"""Flag supported features."""
return SUPPORT_BRIGHTNESS | SUPPORT_COLOR
async def async_turn_on(self, **kwargs): async def async_turn_on(self, **kwargs):
"""Turn the light on.""" """Turn the light on."""
if ATTR_BRIGHTNESS in kwargs: if ATTR_BRIGHTNESS in kwargs: