From eeeb21a9f191cab63df14bb0b33200edb13dc405 Mon Sep 17 00:00:00 2001 From: Erik Montnemery Date: Sun, 3 Apr 2022 13:58:28 +0200 Subject: [PATCH] Migrate dynalite light to color_mode (#69177) --- homeassistant/components/dynalite/light.py | 10 ++++------ tests/components/dynalite/test_light.py | 12 ++++++++++-- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/homeassistant/components/dynalite/light.py b/homeassistant/components/dynalite/light.py index ee91df1ae98..922ad0ada1b 100644 --- a/homeassistant/components/dynalite/light.py +++ b/homeassistant/components/dynalite/light.py @@ -1,6 +1,6 @@ """Support for Dynalite channels as lights.""" -from homeassistant.components.light import SUPPORT_BRIGHTNESS, LightEntity +from homeassistant.components.light import COLOR_MODE_BRIGHTNESS, LightEntity from homeassistant.config_entries import ConfigEntry from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddEntitiesCallback @@ -22,6 +22,9 @@ async def async_setup_entry( class DynaliteLight(DynaliteBase, LightEntity): """Representation of a Dynalite Channel as a Home Assistant Light.""" + _attr_color_mode = COLOR_MODE_BRIGHTNESS + _attr_supported_color_modes = {COLOR_MODE_BRIGHTNESS} + @property def brightness(self) -> int: """Return the brightness of this light between 0..255.""" @@ -39,8 +42,3 @@ class DynaliteLight(DynaliteBase, LightEntity): async def async_turn_off(self, **kwargs) -> None: """Turn the light off.""" await self._device.async_turn_off(**kwargs) - - @property - def supported_features(self) -> int: - """Flag supported features.""" - return SUPPORT_BRIGHTNESS diff --git a/tests/components/dynalite/test_light.py b/tests/components/dynalite/test_light.py index 230e7584d70..17ce4dd5f53 100644 --- a/tests/components/dynalite/test_light.py +++ b/tests/components/dynalite/test_light.py @@ -3,7 +3,11 @@ from dynalite_devices_lib.light import DynaliteChannelLightDevice import pytest -from homeassistant.components.light import SUPPORT_BRIGHTNESS +from homeassistant.components.light import ( + ATTR_COLOR_MODE, + ATTR_SUPPORTED_COLOR_MODES, + COLOR_MODE_BRIGHTNESS, +) from homeassistant.const import ( ATTR_FRIENDLY_NAME, ATTR_SUPPORTED_FEATURES, @@ -32,7 +36,11 @@ async def test_light_setup(hass, mock_device): entity_state = hass.states.get("light.name") assert entity_state.attributes[ATTR_FRIENDLY_NAME] == mock_device.name assert entity_state.attributes["brightness"] == mock_device.brightness - assert entity_state.attributes[ATTR_SUPPORTED_FEATURES] == SUPPORT_BRIGHTNESS + assert entity_state.attributes[ATTR_COLOR_MODE] == COLOR_MODE_BRIGHTNESS + assert entity_state.attributes[ATTR_SUPPORTED_COLOR_MODES] == [ + COLOR_MODE_BRIGHTNESS + ] + assert entity_state.attributes[ATTR_SUPPORTED_FEATURES] == 0 await run_service_tests( hass, mock_device,