From 9cd83c8b48ff4deb73d766d4487896e4f731ebab Mon Sep 17 00:00:00 2001 From: Erik Montnemery Date: Mon, 4 Apr 2022 18:32:51 +0200 Subject: [PATCH] Migrate homematicip_cloud light to color_mode (#69270) --- .../components/homematicip_cloud/light.py | 21 ++++++---- .../homematicip_cloud/test_light.py | 38 ++++++++++++++++++- 2 files changed, 50 insertions(+), 9 deletions(-) diff --git a/homeassistant/components/homematicip_cloud/light.py b/homeassistant/components/homematicip_cloud/light.py index 457f2fdcd25..42db02eb685 100644 --- a/homeassistant/components/homematicip_cloud/light.py +++ b/homeassistant/components/homematicip_cloud/light.py @@ -20,8 +20,9 @@ from homeassistant.components.light import ( ATTR_COLOR_NAME, ATTR_HS_COLOR, ATTR_TRANSITION, - SUPPORT_BRIGHTNESS, - SUPPORT_COLOR, + COLOR_MODE_BRIGHTNESS, + COLOR_MODE_HS, + COLOR_MODE_ONOFF, SUPPORT_TRANSITION, LightEntity, ) @@ -70,6 +71,9 @@ async def async_setup_entry( class HomematicipLight(HomematicipGenericEntity, LightEntity): """Representation of the HomematicIP light.""" + _attr_color_mode = COLOR_MODE_ONOFF + _attr_supported_color_modes = {COLOR_MODE_ONOFF} + def __init__(self, hap: HomematicipHAP, device) -> None: """Initialize the light entity.""" super().__init__(hap, device) @@ -95,6 +99,9 @@ class HomematicipLightMeasuring(HomematicipLight): class HomematicipMultiDimmer(HomematicipGenericEntity, LightEntity): """Representation of HomematicIP Cloud dimmer.""" + _attr_color_mode = COLOR_MODE_BRIGHTNESS + _attr_supported_color_modes = {COLOR_MODE_BRIGHTNESS} + def __init__( self, hap: HomematicipHAP, @@ -120,11 +127,6 @@ class HomematicipMultiDimmer(HomematicipGenericEntity, LightEntity): (self._device.functionalChannels[self._channel].dimLevel or 0.0) * 255 ) - @property - def supported_features(self) -> int: - """Flag supported features.""" - return SUPPORT_BRIGHTNESS - async def async_turn_on(self, **kwargs) -> None: """Turn the dimmer on.""" if ATTR_BRIGHTNESS in kwargs: @@ -150,6 +152,9 @@ class HomematicipDimmer(HomematicipMultiDimmer, LightEntity): class HomematicipNotificationLight(HomematicipGenericEntity, LightEntity): """Representation of HomematicIP Cloud notification light.""" + _attr_color_mode = COLOR_MODE_HS + _attr_supported_color_modes = {COLOR_MODE_HS} + def __init__(self, hap: HomematicipHAP, device, channel: int) -> None: """Initialize the notification light entity.""" if channel == 2: @@ -207,7 +212,7 @@ class HomematicipNotificationLight(HomematicipGenericEntity, LightEntity): @property def supported_features(self) -> int: """Flag supported features.""" - return SUPPORT_BRIGHTNESS | SUPPORT_COLOR | SUPPORT_TRANSITION + return SUPPORT_TRANSITION @property def unique_id(self) -> str: diff --git a/tests/components/homematicip_cloud/test_light.py b/tests/components/homematicip_cloud/test_light.py index b3feb9586cd..b01b999b447 100644 --- a/tests/components/homematicip_cloud/test_light.py +++ b/tests/components/homematicip_cloud/test_light.py @@ -4,10 +4,16 @@ from homematicip.base.enums import RGBColorState from homeassistant.components.homematicip_cloud import DOMAIN as HMIPC_DOMAIN from homeassistant.components.light import ( ATTR_BRIGHTNESS, + ATTR_COLOR_MODE, ATTR_COLOR_NAME, + ATTR_SUPPORTED_COLOR_MODES, + COLOR_MODE_BRIGHTNESS, + COLOR_MODE_HS, + COLOR_MODE_ONOFF, DOMAIN as LIGHT_DOMAIN, + SUPPORT_TRANSITION, ) -from homeassistant.const import STATE_OFF, STATE_ON +from homeassistant.const import ATTR_SUPPORTED_FEATURES, STATE_OFF, STATE_ON from homeassistant.setup import async_setup_component from .helper import async_manipulate_test_data, get_and_check_entity_basics @@ -35,6 +41,9 @@ async def test_hmip_light(hass, default_mock_hap_factory): ) assert ha_state.state == STATE_ON + assert ha_state.attributes[ATTR_COLOR_MODE] == COLOR_MODE_ONOFF + assert ha_state.attributes[ATTR_SUPPORTED_COLOR_MODES] == [COLOR_MODE_ONOFF] + assert ha_state.attributes[ATTR_SUPPORTED_FEATURES] == 0 service_call_counter = len(hmip_device.mock_calls) await hass.services.async_call( @@ -47,6 +56,9 @@ async def test_hmip_light(hass, default_mock_hap_factory): await async_manipulate_test_data(hass, hmip_device, "on", False) ha_state = hass.states.get(entity_id) assert ha_state.state == STATE_OFF + assert ATTR_COLOR_MODE not in ha_state.attributes + assert ha_state.attributes[ATTR_SUPPORTED_COLOR_MODES] == [COLOR_MODE_ONOFF] + assert ha_state.attributes[ATTR_SUPPORTED_FEATURES] == 0 await hass.services.async_call( "light", "turn_on", {"entity_id": entity_id}, blocking=True @@ -74,6 +86,9 @@ async def test_hmip_notification_light(hass, default_mock_hap_factory): ) assert ha_state.state == STATE_OFF + assert ATTR_COLOR_MODE not in ha_state.attributes + assert ha_state.attributes[ATTR_SUPPORTED_COLOR_MODES] == [COLOR_MODE_HS] + assert ha_state.attributes[ATTR_SUPPORTED_FEATURES] == SUPPORT_TRANSITION service_call_counter = len(hmip_device.mock_calls) # Send all color via service call. @@ -128,6 +143,9 @@ async def test_hmip_notification_light(hass, default_mock_hap_factory): assert ha_state.state == STATE_ON assert ha_state.attributes[ATTR_COLOR_NAME] == RGBColorState.PURPLE assert ha_state.attributes[ATTR_BRIGHTNESS] == 255 + assert ha_state.attributes[ATTR_COLOR_MODE] == COLOR_MODE_HS + assert ha_state.attributes[ATTR_SUPPORTED_COLOR_MODES] == [COLOR_MODE_HS] + assert ha_state.attributes[ATTR_SUPPORTED_FEATURES] == SUPPORT_TRANSITION await hass.services.async_call( "light", "turn_off", {"entity_id": entity_id, "transition": 100}, blocking=True @@ -165,6 +183,9 @@ async def test_hmip_dimmer(hass, default_mock_hap_factory): ) assert ha_state.state == STATE_OFF + assert ATTR_COLOR_MODE not in ha_state.attributes + assert ha_state.attributes[ATTR_SUPPORTED_COLOR_MODES] == [COLOR_MODE_BRIGHTNESS] + assert ha_state.attributes[ATTR_SUPPORTED_FEATURES] == 0 service_call_counter = len(hmip_device.mock_calls) await hass.services.async_call( @@ -186,6 +207,9 @@ async def test_hmip_dimmer(hass, default_mock_hap_factory): ha_state = hass.states.get(entity_id) assert ha_state.state == STATE_ON assert ha_state.attributes[ATTR_BRIGHTNESS] == 255 + assert ha_state.attributes[ATTR_COLOR_MODE] == COLOR_MODE_BRIGHTNESS + assert ha_state.attributes[ATTR_SUPPORTED_COLOR_MODES] == [COLOR_MODE_BRIGHTNESS] + assert ha_state.attributes[ATTR_SUPPORTED_FEATURES] == 0 await hass.services.async_call( "light", "turn_off", {"entity_id": entity_id}, blocking=True @@ -217,6 +241,9 @@ async def test_hmip_light_measuring(hass, default_mock_hap_factory): ) assert ha_state.state == STATE_OFF + assert ATTR_COLOR_MODE not in ha_state.attributes + assert ha_state.attributes[ATTR_SUPPORTED_COLOR_MODES] == [COLOR_MODE_ONOFF] + assert ha_state.attributes[ATTR_SUPPORTED_FEATURES] == 0 service_call_counter = len(hmip_device.mock_calls) await hass.services.async_call( @@ -229,6 +256,9 @@ async def test_hmip_light_measuring(hass, default_mock_hap_factory): await async_manipulate_test_data(hass, hmip_device, "currentPowerConsumption", 50) ha_state = hass.states.get(entity_id) assert ha_state.state == STATE_ON + assert ha_state.attributes[ATTR_COLOR_MODE] == COLOR_MODE_ONOFF + assert ha_state.attributes[ATTR_SUPPORTED_COLOR_MODES] == [COLOR_MODE_ONOFF] + assert ha_state.attributes[ATTR_SUPPORTED_FEATURES] == 0 await hass.services.async_call( "light", "turn_off", {"entity_id": entity_id}, blocking=True @@ -255,6 +285,9 @@ async def test_hmip_wired_multi_dimmer(hass, default_mock_hap_factory): ) assert ha_state.state == STATE_OFF + assert ATTR_COLOR_MODE not in ha_state.attributes + assert ha_state.attributes[ATTR_SUPPORTED_COLOR_MODES] == [COLOR_MODE_BRIGHTNESS] + assert ha_state.attributes[ATTR_SUPPORTED_FEATURES] == 0 service_call_counter = len(hmip_device.mock_calls) await hass.services.async_call( @@ -276,6 +309,9 @@ async def test_hmip_wired_multi_dimmer(hass, default_mock_hap_factory): ha_state = hass.states.get(entity_id) assert ha_state.state == STATE_ON assert ha_state.attributes[ATTR_BRIGHTNESS] == 255 + assert ha_state.attributes[ATTR_COLOR_MODE] == COLOR_MODE_BRIGHTNESS + assert ha_state.attributes[ATTR_SUPPORTED_COLOR_MODES] == [COLOR_MODE_BRIGHTNESS] + assert ha_state.attributes[ATTR_SUPPORTED_FEATURES] == 0 await hass.services.async_call( "light", "turn_off", {"entity_id": entity_id}, blocking=True