From e8852e0f305e8284c8a05d1a3cb53d54f0979b33 Mon Sep 17 00:00:00 2001 From: Erik Montnemery Date: Thu, 7 Apr 2022 14:49:12 +0200 Subject: [PATCH] Migrate lcn light to color_mode (#69419) --- homeassistant/components/lcn/light.py | 21 +++++++++++++-------- tests/components/lcn/test_light.py | 11 ++++++----- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/homeassistant/components/lcn/light.py b/homeassistant/components/lcn/light.py index 260dd2212ea..255619c14cc 100644 --- a/homeassistant/components/lcn/light.py +++ b/homeassistant/components/lcn/light.py @@ -8,8 +8,9 @@ import pypck from homeassistant.components.light import ( ATTR_BRIGHTNESS, ATTR_TRANSITION, + COLOR_MODE_BRIGHTNESS, + COLOR_MODE_ONOFF, DOMAIN as DOMAIN_LIGHT, - SUPPORT_BRIGHTNESS, SUPPORT_TRANSITION, LightEntity, ) @@ -64,6 +65,8 @@ async def async_setup_entry( class LcnOutputLight(LcnEntity, LightEntity): """Representation of a LCN light for output ports.""" + _attr_supported_features = SUPPORT_TRANSITION + def __init__( self, config: ConfigType, entry_id: str, device_connection: DeviceConnectionType ) -> None: @@ -81,6 +84,12 @@ class LcnOutputLight(LcnEntity, LightEntity): self._is_on = False self._is_dimming_to_zero = False + if self.dimmable: + self._attr_color_mode = COLOR_MODE_BRIGHTNESS + else: + self._attr_color_mode = COLOR_MODE_ONOFF + self._attr_supported_color_modes = {self._attr_color_mode} + async def async_added_to_hass(self) -> None: """Run when entity about to be added to hass.""" await super().async_added_to_hass() @@ -93,13 +102,6 @@ class LcnOutputLight(LcnEntity, LightEntity): if not self.device_connection.is_group: await self.device_connection.cancel_status_request_handler(self.output) - @property - def supported_features(self) -> int: - """Flag supported features.""" - if self.dimmable: - return SUPPORT_TRANSITION | SUPPORT_BRIGHTNESS - return SUPPORT_TRANSITION - @property def brightness(self) -> int | None: """Return the brightness of this light between 0..255.""" @@ -167,6 +169,9 @@ class LcnOutputLight(LcnEntity, LightEntity): class LcnRelayLight(LcnEntity, LightEntity): """Representation of a LCN light for relay ports.""" + _attr_color_mode = COLOR_MODE_ONOFF + _attr_supported_color_modes = {COLOR_MODE_ONOFF} + def __init__( self, config: ConfigType, entry_id: str, device_connection: DeviceConnectionType ) -> None: diff --git a/tests/components/lcn/test_light.py b/tests/components/lcn/test_light.py index 4fd58aab743..3d9d999f0ec 100644 --- a/tests/components/lcn/test_light.py +++ b/tests/components/lcn/test_light.py @@ -8,9 +8,11 @@ from pypck.lcn_defs import RelayStateModifier from homeassistant.components.lcn.helpers import get_device_connection from homeassistant.components.light import ( ATTR_BRIGHTNESS, + ATTR_SUPPORTED_COLOR_MODES, ATTR_TRANSITION, + COLOR_MODE_BRIGHTNESS, + COLOR_MODE_ONOFF, DOMAIN as DOMAIN_LIGHT, - SUPPORT_BRIGHTNESS, SUPPORT_TRANSITION, ) from homeassistant.const import ( @@ -42,14 +44,13 @@ async def test_entity_state(hass, lcn_connection): """Test state of entity.""" state = hass.states.get("light.light_output1") assert state - assert ( - state.attributes[ATTR_SUPPORTED_FEATURES] - == SUPPORT_BRIGHTNESS | SUPPORT_TRANSITION - ) + assert state.attributes[ATTR_SUPPORTED_FEATURES] == SUPPORT_TRANSITION + assert state.attributes[ATTR_SUPPORTED_COLOR_MODES] == [COLOR_MODE_BRIGHTNESS] state = hass.states.get("light.light_output2") assert state assert state.attributes[ATTR_SUPPORTED_FEATURES] == SUPPORT_TRANSITION + assert state.attributes[ATTR_SUPPORTED_COLOR_MODES] == [COLOR_MODE_ONOFF] async def test_entity_attributes(hass, entry, lcn_connection):