From 1f8913d6cd45d3ef9992a6fafc33ea88a4dd8173 Mon Sep 17 00:00:00 2001 From: epenet <6771947+epenet@users.noreply.github.com> Date: Fri, 6 Dec 2024 20:29:30 +0100 Subject: [PATCH] Remove deprecated supported features warning in LightEntity (#132371) --- homeassistant/components/light/__init__.py | 81 +---- tests/components/light/common.py | 3 +- tests/components/light/test_init.py | 347 +++------------------ 3 files changed, 50 insertions(+), 381 deletions(-) diff --git a/homeassistant/components/light/__init__.py b/homeassistant/components/light/__init__.py index 60ea34cc754..121732c918f 100644 --- a/homeassistant/components/light/__init__.py +++ b/homeassistant/components/light/__init__.py @@ -331,7 +331,7 @@ def filter_turn_off_params( if not params: return params - supported_features = light.supported_features_compat + supported_features = light.supported_features if LightEntityFeature.FLASH not in supported_features: params.pop(ATTR_FLASH, None) @@ -343,7 +343,7 @@ def filter_turn_off_params( def filter_turn_on_params(light: LightEntity, params: dict[str, Any]) -> dict[str, Any]: """Filter out params not supported by the light.""" - supported_features = light.supported_features_compat + supported_features = light.supported_features if LightEntityFeature.EFFECT not in supported_features: params.pop(ATTR_EFFECT, None) @@ -1006,7 +1006,7 @@ class LightEntity(ToggleEntity, cached_properties=CACHED_PROPERTIES_WITH_ATTR_): def capability_attributes(self) -> dict[str, Any]: """Return capability attributes.""" data: dict[str, Any] = {} - supported_features = self.supported_features_compat + supported_features = self.supported_features supported_color_modes = self._light_internal_supported_color_modes if ColorMode.COLOR_TEMP in supported_color_modes: @@ -1168,12 +1168,11 @@ class LightEntity(ToggleEntity, cached_properties=CACHED_PROPERTIES_WITH_ATTR_): def state_attributes(self) -> dict[str, Any] | None: """Return state attributes.""" data: dict[str, Any] = {} - supported_features = self.supported_features_compat + supported_features = self.supported_features supported_color_modes = self.supported_color_modes legacy_supported_color_modes = ( supported_color_modes or self._light_internal_supported_color_modes ) - supported_features_value = supported_features.value _is_on = self.is_on color_mode = self._light_internal_color_mode if _is_on else None @@ -1192,13 +1191,6 @@ class LightEntity(ToggleEntity, cached_properties=CACHED_PROPERTIES_WITH_ATTR_): data[ATTR_BRIGHTNESS] = self.brightness else: data[ATTR_BRIGHTNESS] = None - elif supported_features_value & _DEPRECATED_SUPPORT_BRIGHTNESS.value: - # Backwards compatibility for ambiguous / incomplete states - # Warning is printed by supported_features_compat, remove in 2025.1 - if _is_on: - data[ATTR_BRIGHTNESS] = self.brightness - else: - data[ATTR_BRIGHTNESS] = None if color_temp_supported(supported_color_modes): if color_mode == ColorMode.COLOR_TEMP: @@ -1213,21 +1205,6 @@ class LightEntity(ToggleEntity, cached_properties=CACHED_PROPERTIES_WITH_ATTR_): else: data[ATTR_COLOR_TEMP_KELVIN] = None data[ATTR_COLOR_TEMP] = None - elif supported_features_value & _DEPRECATED_SUPPORT_COLOR_TEMP.value: - # Backwards compatibility - # Warning is printed by supported_features_compat, remove in 2025.1 - if _is_on: - color_temp_kelvin = self.color_temp_kelvin - data[ATTR_COLOR_TEMP_KELVIN] = color_temp_kelvin - if color_temp_kelvin: - data[ATTR_COLOR_TEMP] = ( - color_util.color_temperature_kelvin_to_mired(color_temp_kelvin) - ) - else: - data[ATTR_COLOR_TEMP] = None - else: - data[ATTR_COLOR_TEMP_KELVIN] = None - data[ATTR_COLOR_TEMP] = None if color_supported(legacy_supported_color_modes) or color_temp_supported( legacy_supported_color_modes @@ -1265,24 +1242,7 @@ class LightEntity(ToggleEntity, cached_properties=CACHED_PROPERTIES_WITH_ATTR_): type(self), report_issue, ) - supported_features = self.supported_features_compat - supported_features_value = supported_features.value - supported_color_modes: set[ColorMode] = set() - - if supported_features_value & _DEPRECATED_SUPPORT_COLOR_TEMP.value: - supported_color_modes.add(ColorMode.COLOR_TEMP) - if supported_features_value & _DEPRECATED_SUPPORT_COLOR.value: - supported_color_modes.add(ColorMode.HS) - if ( - not supported_color_modes - and supported_features_value & _DEPRECATED_SUPPORT_BRIGHTNESS.value - ): - supported_color_modes = {ColorMode.BRIGHTNESS} - - if not supported_color_modes: - supported_color_modes = {ColorMode.ONOFF} - - return supported_color_modes + return {ColorMode.ONOFF} @cached_property def supported_color_modes(self) -> set[ColorMode] | set[str] | None: @@ -1294,37 +1254,6 @@ class LightEntity(ToggleEntity, cached_properties=CACHED_PROPERTIES_WITH_ATTR_): """Flag supported features.""" return self._attr_supported_features - @property - def supported_features_compat(self) -> LightEntityFeature: - """Return the supported features as LightEntityFeature. - - Remove this compatibility shim in 2025.1 or later. - """ - features = self.supported_features - if type(features) is not int: # noqa: E721 - return features - new_features = LightEntityFeature(features) - if self._deprecated_supported_features_reported is True: - return new_features - self._deprecated_supported_features_reported = True - report_issue = self._suggest_report_issue() - report_issue += ( - " and reference " - "https://developers.home-assistant.io/blog/2023/12/28/support-feature-magic-numbers-deprecation" - ) - _LOGGER.warning( - ( - "Entity %s (%s) is using deprecated supported features" - " values which will be removed in HA Core 2025.1. Instead it should use" - " %s and color modes, please %s" - ), - self.entity_id, - type(self), - repr(new_features), - report_issue, - ) - return new_features - def __should_report_light_issue(self) -> bool: """Return if light color mode issues should be reported.""" if not self.platform: diff --git a/tests/components/light/common.py b/tests/components/light/common.py index ba095a03642..147f2336876 100644 --- a/tests/components/light/common.py +++ b/tests/components/light/common.py @@ -25,6 +25,7 @@ from homeassistant.components.light import ( DOMAIN, ColorMode, LightEntity, + LightEntityFeature, ) from homeassistant.const import ( ATTR_ENTITY_ID, @@ -251,7 +252,7 @@ class MockLight(MockToggleEntity, LightEntity): _attr_max_color_temp_kelvin = 6500 _attr_min_color_temp_kelvin = 2000 - supported_features = 0 + supported_features = LightEntityFeature(0) brightness = None color_temp_kelvin = None diff --git a/tests/components/light/test_init.py b/tests/components/light/test_init.py index 280ec569d4d..bf09774073b 100644 --- a/tests/components/light/test_init.py +++ b/tests/components/light/test_init.py @@ -1,7 +1,6 @@ """The tests for the Light component.""" from types import ModuleType -from typing import Literal from unittest.mock import MagicMock, mock_open, patch import pytest @@ -137,13 +136,8 @@ async def test_services( ent3.supported_color_modes = [light.ColorMode.HS] ent1.supported_features = light.LightEntityFeature.TRANSITION ent2.supported_features = ( - light.SUPPORT_COLOR - | light.LightEntityFeature.EFFECT - | light.LightEntityFeature.TRANSITION + light.LightEntityFeature.EFFECT | light.LightEntityFeature.TRANSITION ) - # Set color modes to none to trigger backwards compatibility in LightEntity - ent2.supported_color_modes = None - ent2.color_mode = None ent3.supported_features = ( light.LightEntityFeature.FLASH | light.LightEntityFeature.TRANSITION ) @@ -259,10 +253,7 @@ async def test_services( } _, data = ent2.last_call("turn_on") - assert data == { - light.ATTR_EFFECT: "fun_effect", - light.ATTR_HS_COLOR: (0, 0), - } + assert data == {light.ATTR_EFFECT: "fun_effect"} _, data = ent3.last_call("turn_on") assert data == {light.ATTR_FLASH: "short", light.ATTR_HS_COLOR: (71.059, 100)} @@ -346,8 +337,6 @@ async def test_services( _, data = ent2.last_call("turn_on") assert data == { - light.ATTR_BRIGHTNESS: 100, - light.ATTR_HS_COLOR: profile.hs_color, light.ATTR_TRANSITION: 1, } @@ -925,16 +914,12 @@ async def test_light_brightness_step(hass: HomeAssistant) -> None: setup_test_component_platform(hass, light.DOMAIN, entities) entity0 = entities[0] - entity0.supported_features = light.SUPPORT_BRIGHTNESS - # Set color modes to none to trigger backwards compatibility in LightEntity - entity0.supported_color_modes = None - entity0.color_mode = None + entity0.supported_color_modes = {light.ColorMode.BRIGHTNESS} + entity0.color_mode = light.ColorMode.BRIGHTNESS entity0.brightness = 100 entity1 = entities[1] - entity1.supported_features = light.SUPPORT_BRIGHTNESS - # Set color modes to none to trigger backwards compatibility in LightEntity - entity1.supported_color_modes = None - entity1.color_mode = None + entity1.supported_color_modes = {light.ColorMode.BRIGHTNESS} + entity1.color_mode = light.ColorMode.BRIGHTNESS entity1.brightness = 50 assert await async_setup_component(hass, "light", {"light": {"platform": "test"}}) await hass.async_block_till_done() @@ -995,10 +980,8 @@ async def test_light_brightness_pct_conversion( setup_test_component_platform(hass, light.DOMAIN, mock_light_entities) entity = mock_light_entities[0] - entity.supported_features = light.SUPPORT_BRIGHTNESS - # Set color modes to none to trigger backwards compatibility in LightEntity - entity.supported_color_modes = None - entity.color_mode = None + entity.supported_color_modes = {light.ColorMode.BRIGHTNESS} + entity.color_mode = light.ColorMode.BRIGHTNESS entity.brightness = 100 assert await async_setup_component(hass, "light", {"light": {"platform": "test"}}) await hass.async_block_till_done() @@ -1147,167 +1130,6 @@ invalid_no_brightness_no_color_no_transition,,, assert invalid_profile_name not in profiles.data -@pytest.mark.parametrize("light_state", [STATE_ON, STATE_OFF]) -async def test_light_backwards_compatibility_supported_color_modes( - hass: HomeAssistant, light_state: Literal["on", "off"] -) -> None: - """Test supported_color_modes if not implemented by the entity.""" - entities = [ - MockLight("Test_0", light_state), - MockLight("Test_1", light_state), - MockLight("Test_2", light_state), - MockLight("Test_3", light_state), - MockLight("Test_4", light_state), - ] - - entity0 = entities[0] - - entity1 = entities[1] - entity1.supported_features = light.SUPPORT_BRIGHTNESS - # Set color modes to none to trigger backwards compatibility in LightEntity - entity1.supported_color_modes = None - entity1.color_mode = None - - entity2 = entities[2] - entity2.supported_features = light.SUPPORT_BRIGHTNESS | light.SUPPORT_COLOR_TEMP - # Set color modes to none to trigger backwards compatibility in LightEntity - entity2.supported_color_modes = None - entity2.color_mode = None - - entity3 = entities[3] - entity3.supported_features = light.SUPPORT_BRIGHTNESS | light.SUPPORT_COLOR - # Set color modes to none to trigger backwards compatibility in LightEntity - entity3.supported_color_modes = None - entity3.color_mode = None - - entity4 = entities[4] - entity4.supported_features = ( - light.SUPPORT_BRIGHTNESS | light.SUPPORT_COLOR | light.SUPPORT_COLOR_TEMP - ) - # Set color modes to none to trigger backwards compatibility in LightEntity - entity4.supported_color_modes = None - entity4.color_mode = None - - setup_test_component_platform(hass, light.DOMAIN, entities) - - assert await async_setup_component(hass, "light", {"light": {"platform": "test"}}) - await hass.async_block_till_done() - - state = hass.states.get(entity0.entity_id) - assert state.attributes["supported_color_modes"] == [light.ColorMode.ONOFF] - if light_state == STATE_OFF: - assert state.attributes["color_mode"] is None - else: - assert state.attributes["color_mode"] == light.ColorMode.ONOFF - - state = hass.states.get(entity1.entity_id) - assert state.attributes["supported_color_modes"] == [light.ColorMode.BRIGHTNESS] - if light_state == STATE_OFF: - assert state.attributes["color_mode"] is None - else: - assert state.attributes["color_mode"] == light.ColorMode.UNKNOWN - - state = hass.states.get(entity2.entity_id) - assert state.attributes["supported_color_modes"] == [light.ColorMode.COLOR_TEMP] - if light_state == STATE_OFF: - assert state.attributes["color_mode"] is None - else: - assert state.attributes["color_mode"] == light.ColorMode.UNKNOWN - - state = hass.states.get(entity3.entity_id) - assert state.attributes["supported_color_modes"] == [light.ColorMode.HS] - if light_state == STATE_OFF: - assert state.attributes["color_mode"] is None - else: - assert state.attributes["color_mode"] == light.ColorMode.UNKNOWN - - state = hass.states.get(entity4.entity_id) - assert state.attributes["supported_color_modes"] == [ - light.ColorMode.COLOR_TEMP, - light.ColorMode.HS, - ] - if light_state == STATE_OFF: - assert state.attributes["color_mode"] is None - else: - assert state.attributes["color_mode"] == light.ColorMode.UNKNOWN - - -async def test_light_backwards_compatibility_color_mode(hass: HomeAssistant) -> None: - """Test color_mode if not implemented by the entity.""" - entities = [ - MockLight("Test_0", STATE_ON), - MockLight("Test_1", STATE_ON), - MockLight("Test_2", STATE_ON), - MockLight("Test_3", STATE_ON), - MockLight("Test_4", STATE_ON), - ] - - entity0 = entities[0] - - entity1 = entities[1] - entity1.supported_features = light.SUPPORT_BRIGHTNESS - # Set color modes to none to trigger backwards compatibility in LightEntity - entity1.supported_color_modes = None - entity1.color_mode = None - entity1.brightness = 100 - - entity2 = entities[2] - entity2.supported_features = light.SUPPORT_BRIGHTNESS | light.SUPPORT_COLOR_TEMP - # Set color modes to none to trigger backwards compatibility in LightEntity - entity2.supported_color_modes = None - entity2.color_mode = None - entity2.color_temp_kelvin = 10000 - - entity3 = entities[3] - entity3.supported_features = light.SUPPORT_BRIGHTNESS | light.SUPPORT_COLOR - # Set color modes to none to trigger backwards compatibility in LightEntity - entity3.supported_color_modes = None - entity3.color_mode = None - entity3.hs_color = (240, 100) - - entity4 = entities[4] - entity4.supported_features = ( - light.SUPPORT_BRIGHTNESS | light.SUPPORT_COLOR | light.SUPPORT_COLOR_TEMP - ) - # Set color modes to none to trigger backwards compatibility in LightEntity - entity4.supported_color_modes = None - entity4.color_mode = None - entity4.hs_color = (240, 100) - entity4.color_temp_kelvin = 10000 - - setup_test_component_platform(hass, light.DOMAIN, entities) - - assert await async_setup_component(hass, "light", {"light": {"platform": "test"}}) - await hass.async_block_till_done() - - state = hass.states.get(entity0.entity_id) - assert state.attributes["supported_color_modes"] == [light.ColorMode.ONOFF] - assert state.attributes["color_mode"] == light.ColorMode.ONOFF - - state = hass.states.get(entity1.entity_id) - assert state.attributes["supported_color_modes"] == [light.ColorMode.BRIGHTNESS] - assert state.attributes["color_mode"] == light.ColorMode.BRIGHTNESS - - state = hass.states.get(entity2.entity_id) - assert state.attributes["supported_color_modes"] == [light.ColorMode.COLOR_TEMP] - assert state.attributes["color_mode"] == light.ColorMode.COLOR_TEMP - assert state.attributes["rgb_color"] == (202, 218, 255) - assert state.attributes["hs_color"] == (221.575, 20.9) - assert state.attributes["xy_color"] == (0.278, 0.287) - - state = hass.states.get(entity3.entity_id) - assert state.attributes["supported_color_modes"] == [light.ColorMode.HS] - assert state.attributes["color_mode"] == light.ColorMode.HS - - state = hass.states.get(entity4.entity_id) - assert state.attributes["supported_color_modes"] == [ - light.ColorMode.COLOR_TEMP, - light.ColorMode.HS, - ] - # hs color prioritized over color_temp, light should report mode ColorMode.HS - assert state.attributes["color_mode"] == light.ColorMode.HS - - async def test_light_service_call_rgbw(hass: HomeAssistant) -> None: """Test rgbw functionality in service calls.""" entity0 = MockLight("Test_rgbw", STATE_ON) @@ -1363,7 +1185,7 @@ async def test_light_state_off(hass: HomeAssistant) -> None: "color_mode": None, "friendly_name": "Test_onoff", "supported_color_modes": [light.ColorMode.ONOFF], - "supported_features": 0, + "supported_features": light.LightEntityFeature(0), } state = hass.states.get(entity1.entity_id) @@ -1371,7 +1193,7 @@ async def test_light_state_off(hass: HomeAssistant) -> None: "color_mode": None, "friendly_name": "Test_brightness", "supported_color_modes": [light.ColorMode.BRIGHTNESS], - "supported_features": 0, + "supported_features": light.LightEntityFeature(0), "brightness": None, } @@ -1380,7 +1202,7 @@ async def test_light_state_off(hass: HomeAssistant) -> None: "color_mode": None, "friendly_name": "Test_ct", "supported_color_modes": [light.ColorMode.COLOR_TEMP], - "supported_features": 0, + "supported_features": light.LightEntityFeature(0), "brightness": None, "color_temp": None, "color_temp_kelvin": None, @@ -1398,7 +1220,7 @@ async def test_light_state_off(hass: HomeAssistant) -> None: "color_mode": None, "friendly_name": "Test_rgbw", "supported_color_modes": [light.ColorMode.RGBW], - "supported_features": 0, + "supported_features": light.LightEntityFeature(0), "brightness": None, "rgbw_color": None, "hs_color": None, @@ -1429,7 +1251,7 @@ async def test_light_state_rgbw(hass: HomeAssistant) -> None: "color_mode": light.ColorMode.RGBW, "friendly_name": "Test_rgbw", "supported_color_modes": [light.ColorMode.RGBW], - "supported_features": 0, + "supported_features": light.LightEntityFeature(0), "hs_color": (240.0, 25.0), "rgb_color": (3, 3, 4), "rgbw_color": (1, 2, 3, 4), @@ -1460,7 +1282,7 @@ async def test_light_state_rgbww(hass: HomeAssistant) -> None: "color_mode": light.ColorMode.RGBWW, "friendly_name": "Test_rgbww", "supported_color_modes": [light.ColorMode.RGBWW], - "supported_features": 0, + "supported_features": light.LightEntityFeature(0), "hs_color": (60.0, 20.0), "rgb_color": (5, 5, 4), "rgbww_color": (1, 2, 3, 4, 5), @@ -1476,7 +1298,6 @@ async def test_light_service_call_color_conversion(hass: HomeAssistant) -> None: MockLight("Test_rgb", STATE_ON), MockLight("Test_xy", STATE_ON), MockLight("Test_all", STATE_ON), - MockLight("Test_legacy", STATE_ON), MockLight("Test_rgbw", STATE_ON), MockLight("Test_rgbww", STATE_ON), MockLight("Test_temperature", STATE_ON), @@ -1500,19 +1321,13 @@ async def test_light_service_call_color_conversion(hass: HomeAssistant) -> None: } entity4 = entities[4] - entity4.supported_features = light.SUPPORT_COLOR - # Set color modes to none to trigger backwards compatibility in LightEntity - entity4.supported_color_modes = None - entity4.color_mode = None + entity4.supported_color_modes = {light.ColorMode.RGBW} entity5 = entities[5] - entity5.supported_color_modes = {light.ColorMode.RGBW} + entity5.supported_color_modes = {light.ColorMode.RGBWW} entity6 = entities[6] - entity6.supported_color_modes = {light.ColorMode.RGBWW} - - entity7 = entities[7] - entity7.supported_color_modes = {light.ColorMode.COLOR_TEMP} + entity6.supported_color_modes = {light.ColorMode.COLOR_TEMP} assert await async_setup_component(hass, "light", {"light": {"platform": "test"}}) await hass.async_block_till_done() @@ -1534,15 +1349,12 @@ async def test_light_service_call_color_conversion(hass: HomeAssistant) -> None: ] state = hass.states.get(entity4.entity_id) - assert state.attributes["supported_color_modes"] == [light.ColorMode.HS] - - state = hass.states.get(entity5.entity_id) assert state.attributes["supported_color_modes"] == [light.ColorMode.RGBW] - state = hass.states.get(entity6.entity_id) + state = hass.states.get(entity5.entity_id) assert state.attributes["supported_color_modes"] == [light.ColorMode.RGBWW] - state = hass.states.get(entity7.entity_id) + state = hass.states.get(entity6.entity_id) assert state.attributes["supported_color_modes"] == [light.ColorMode.COLOR_TEMP] await hass.services.async_call( @@ -1557,7 +1369,6 @@ async def test_light_service_call_color_conversion(hass: HomeAssistant) -> None: entity4.entity_id, entity5.entity_id, entity6.entity_id, - entity7.entity_id, ], "brightness_pct": 100, "hs_color": (240, 100), @@ -1573,12 +1384,10 @@ async def test_light_service_call_color_conversion(hass: HomeAssistant) -> None: _, data = entity3.last_call("turn_on") assert data == {"brightness": 255, "hs_color": (240.0, 100.0)} _, data = entity4.last_call("turn_on") - assert data == {"brightness": 255, "hs_color": (240.0, 100.0)} - _, data = entity5.last_call("turn_on") assert data == {"brightness": 255, "rgbw_color": (0, 0, 255, 0)} - _, data = entity6.last_call("turn_on") + _, data = entity5.last_call("turn_on") assert data == {"brightness": 255, "rgbww_color": (0, 0, 255, 0, 0)} - _, data = entity7.last_call("turn_on") + _, data = entity6.last_call("turn_on") assert data == {"brightness": 255, "color_temp_kelvin": 1739, "color_temp": 575} await hass.services.async_call( @@ -1593,7 +1402,6 @@ async def test_light_service_call_color_conversion(hass: HomeAssistant) -> None: entity4.entity_id, entity5.entity_id, entity6.entity_id, - entity7.entity_id, ], "brightness_pct": 100, "hs_color": (240, 0), @@ -1609,13 +1417,11 @@ async def test_light_service_call_color_conversion(hass: HomeAssistant) -> None: _, data = entity3.last_call("turn_on") assert data == {"brightness": 255, "hs_color": (240.0, 0.0)} _, data = entity4.last_call("turn_on") - assert data == {"brightness": 255, "hs_color": (240.0, 0.0)} - _, data = entity5.last_call("turn_on") assert data == {"brightness": 255, "rgbw_color": (0, 0, 0, 255)} - _, data = entity6.last_call("turn_on") + _, data = entity5.last_call("turn_on") # The midpoint of the white channels is warm, compensated by adding green + blue assert data == {"brightness": 255, "rgbww_color": (0, 76, 141, 255, 255)} - _, data = entity7.last_call("turn_on") + _, data = entity6.last_call("turn_on") assert data == {"brightness": 255, "color_temp_kelvin": 5962, "color_temp": 167} await hass.services.async_call( @@ -1630,7 +1436,6 @@ async def test_light_service_call_color_conversion(hass: HomeAssistant) -> None: entity4.entity_id, entity5.entity_id, entity6.entity_id, - entity7.entity_id, ], "brightness_pct": 50, "rgb_color": (128, 0, 0), @@ -1645,13 +1450,12 @@ async def test_light_service_call_color_conversion(hass: HomeAssistant) -> None: assert data == {"brightness": 128, "xy_color": (0.701, 0.299)} _, data = entity3.last_call("turn_on") assert data == {"brightness": 128, "rgb_color": (128, 0, 0)} + _, data = entity4.last_call("turn_on") - assert data == {"brightness": 128, "hs_color": (0.0, 100.0)} - _, data = entity5.last_call("turn_on") assert data == {"brightness": 128, "rgbw_color": (128, 0, 0, 0)} - _, data = entity6.last_call("turn_on") + _, data = entity5.last_call("turn_on") assert data == {"brightness": 128, "rgbww_color": (128, 0, 0, 0, 0)} - _, data = entity7.last_call("turn_on") + _, data = entity6.last_call("turn_on") assert data == {"brightness": 128, "color_temp_kelvin": 6279, "color_temp": 159} await hass.services.async_call( @@ -1666,7 +1470,6 @@ async def test_light_service_call_color_conversion(hass: HomeAssistant) -> None: entity4.entity_id, entity5.entity_id, entity6.entity_id, - entity7.entity_id, ], "brightness_pct": 50, "rgb_color": (255, 255, 255), @@ -1682,13 +1485,11 @@ async def test_light_service_call_color_conversion(hass: HomeAssistant) -> None: _, data = entity3.last_call("turn_on") assert data == {"brightness": 128, "rgb_color": (255, 255, 255)} _, data = entity4.last_call("turn_on") - assert data == {"brightness": 128, "hs_color": (0.0, 0.0)} - _, data = entity5.last_call("turn_on") assert data == {"brightness": 128, "rgbw_color": (0, 0, 0, 255)} - _, data = entity6.last_call("turn_on") + _, data = entity5.last_call("turn_on") # The midpoint the white channels is warm, compensated by adding green + blue assert data == {"brightness": 128, "rgbww_color": (0, 76, 141, 255, 255)} - _, data = entity7.last_call("turn_on") + _, data = entity6.last_call("turn_on") assert data == {"brightness": 128, "color_temp_kelvin": 5962, "color_temp": 167} await hass.services.async_call( @@ -1703,7 +1504,6 @@ async def test_light_service_call_color_conversion(hass: HomeAssistant) -> None: entity4.entity_id, entity5.entity_id, entity6.entity_id, - entity7.entity_id, ], "brightness_pct": 50, "xy_color": (0.1, 0.8), @@ -1719,12 +1519,10 @@ async def test_light_service_call_color_conversion(hass: HomeAssistant) -> None: _, data = entity3.last_call("turn_on") assert data == {"brightness": 128, "xy_color": (0.1, 0.8)} _, data = entity4.last_call("turn_on") - assert data == {"brightness": 128, "hs_color": (125.176, 100.0)} - _, data = entity5.last_call("turn_on") assert data == {"brightness": 128, "rgbw_color": (0, 255, 22, 0)} - _, data = entity6.last_call("turn_on") + _, data = entity5.last_call("turn_on") assert data == {"brightness": 128, "rgbww_color": (0, 255, 22, 0, 0)} - _, data = entity7.last_call("turn_on") + _, data = entity6.last_call("turn_on") assert data == {"brightness": 128, "color_temp_kelvin": 8645, "color_temp": 115} await hass.services.async_call( @@ -1739,7 +1537,6 @@ async def test_light_service_call_color_conversion(hass: HomeAssistant) -> None: entity4.entity_id, entity5.entity_id, entity6.entity_id, - entity7.entity_id, ], "brightness_pct": 50, "xy_color": (0.323, 0.329), @@ -1755,13 +1552,11 @@ async def test_light_service_call_color_conversion(hass: HomeAssistant) -> None: _, data = entity3.last_call("turn_on") assert data == {"brightness": 128, "xy_color": (0.323, 0.329)} _, data = entity4.last_call("turn_on") - assert data == {"brightness": 128, "hs_color": (0.0, 0.392)} - _, data = entity5.last_call("turn_on") assert data == {"brightness": 128, "rgbw_color": (1, 0, 0, 255)} - _, data = entity6.last_call("turn_on") + _, data = entity5.last_call("turn_on") # The midpoint the white channels is warm, compensated by adding green + blue assert data == {"brightness": 128, "rgbww_color": (0, 75, 140, 255, 255)} - _, data = entity7.last_call("turn_on") + _, data = entity6.last_call("turn_on") assert data == {"brightness": 128, "color_temp_kelvin": 5962, "color_temp": 167} await hass.services.async_call( @@ -1776,7 +1571,6 @@ async def test_light_service_call_color_conversion(hass: HomeAssistant) -> None: entity4.entity_id, entity5.entity_id, entity6.entity_id, - entity7.entity_id, ], "brightness_pct": 50, "rgbw_color": (128, 0, 0, 64), @@ -1792,13 +1586,11 @@ async def test_light_service_call_color_conversion(hass: HomeAssistant) -> None: _, data = entity3.last_call("turn_on") assert data == {"brightness": 128, "rgb_color": (128, 43, 43)} _, data = entity4.last_call("turn_on") - assert data == {"brightness": 128, "hs_color": (0.0, 66.406)} - _, data = entity5.last_call("turn_on") assert data == {"brightness": 128, "rgbw_color": (128, 0, 0, 64)} - _, data = entity6.last_call("turn_on") + _, data = entity5.last_call("turn_on") # The midpoint the white channels is warm, compensated by adding green + blue assert data == {"brightness": 128, "rgbww_color": (128, 0, 30, 117, 117)} - _, data = entity7.last_call("turn_on") + _, data = entity6.last_call("turn_on") assert data == {"brightness": 128, "color_temp_kelvin": 3011, "color_temp": 332} await hass.services.async_call( @@ -1813,7 +1605,6 @@ async def test_light_service_call_color_conversion(hass: HomeAssistant) -> None: entity4.entity_id, entity5.entity_id, entity6.entity_id, - entity7.entity_id, ], "brightness_pct": 50, "rgbw_color": (255, 255, 255, 255), @@ -1829,13 +1620,11 @@ async def test_light_service_call_color_conversion(hass: HomeAssistant) -> None: _, data = entity3.last_call("turn_on") assert data == {"brightness": 128, "rgb_color": (255, 255, 255)} _, data = entity4.last_call("turn_on") - assert data == {"brightness": 128, "hs_color": (0.0, 0.0)} - _, data = entity5.last_call("turn_on") assert data == {"brightness": 128, "rgbw_color": (255, 255, 255, 255)} - _, data = entity6.last_call("turn_on") + _, data = entity5.last_call("turn_on") # The midpoint the white channels is warm, compensated by adding green + blue assert data == {"brightness": 128, "rgbww_color": (0, 76, 141, 255, 255)} - _, data = entity7.last_call("turn_on") + _, data = entity6.last_call("turn_on") assert data == {"brightness": 128, "color_temp_kelvin": 5962, "color_temp": 167} await hass.services.async_call( @@ -1850,7 +1639,6 @@ async def test_light_service_call_color_conversion(hass: HomeAssistant) -> None: entity4.entity_id, entity5.entity_id, entity6.entity_id, - entity7.entity_id, ], "brightness_pct": 50, "rgbww_color": (128, 0, 0, 64, 32), @@ -1866,12 +1654,10 @@ async def test_light_service_call_color_conversion(hass: HomeAssistant) -> None: _, data = entity3.last_call("turn_on") assert data == {"brightness": 128, "rgb_color": (128, 33, 26)} _, data = entity4.last_call("turn_on") - assert data == {"brightness": 128, "hs_color": (4.118, 79.688)} - _, data = entity5.last_call("turn_on") assert data == {"brightness": 128, "rgbw_color": (128, 9, 0, 33)} - _, data = entity6.last_call("turn_on") + _, data = entity5.last_call("turn_on") assert data == {"brightness": 128, "rgbww_color": (128, 0, 0, 64, 32)} - _, data = entity7.last_call("turn_on") + _, data = entity6.last_call("turn_on") assert data == {"brightness": 128, "color_temp_kelvin": 3845, "color_temp": 260} await hass.services.async_call( @@ -1886,7 +1672,6 @@ async def test_light_service_call_color_conversion(hass: HomeAssistant) -> None: entity4.entity_id, entity5.entity_id, entity6.entity_id, - entity7.entity_id, ], "brightness_pct": 50, "rgbww_color": (255, 255, 255, 255, 255), @@ -1902,13 +1687,11 @@ async def test_light_service_call_color_conversion(hass: HomeAssistant) -> None: _, data = entity3.last_call("turn_on") assert data == {"brightness": 128, "rgb_color": (255, 217, 185)} _, data = entity4.last_call("turn_on") - assert data == {"brightness": 128, "hs_color": (27.429, 27.451)} - _, data = entity5.last_call("turn_on") # The midpoint the white channels is warm, compensated by decreasing green + blue assert data == {"brightness": 128, "rgbw_color": (96, 44, 0, 255)} - _, data = entity6.last_call("turn_on") + _, data = entity5.last_call("turn_on") assert data == {"brightness": 128, "rgbww_color": (255, 255, 255, 255, 255)} - _, data = entity7.last_call("turn_on") + _, data = entity6.last_call("turn_on") assert data == {"brightness": 128, "color_temp_kelvin": 3451, "color_temp": 289} @@ -1921,7 +1704,6 @@ async def test_light_service_call_color_conversion_named_tuple( MockLight("Test_rgb", STATE_ON), MockLight("Test_xy", STATE_ON), MockLight("Test_all", STATE_ON), - MockLight("Test_legacy", STATE_ON), MockLight("Test_rgbw", STATE_ON), MockLight("Test_rgbww", STATE_ON), ] @@ -1944,16 +1726,10 @@ async def test_light_service_call_color_conversion_named_tuple( } entity4 = entities[4] - entity4.supported_features = light.SUPPORT_COLOR - # Set color modes to none to trigger backwards compatibility in LightEntity - entity4.supported_color_modes = None - entity4.color_mode = None + entity4.supported_color_modes = {light.ColorMode.RGBW} entity5 = entities[5] - entity5.supported_color_modes = {light.ColorMode.RGBW} - - entity6 = entities[6] - entity6.supported_color_modes = {light.ColorMode.RGBWW} + entity5.supported_color_modes = {light.ColorMode.RGBWW} assert await async_setup_component(hass, "light", {"light": {"platform": "test"}}) await hass.async_block_till_done() @@ -1969,7 +1745,6 @@ async def test_light_service_call_color_conversion_named_tuple( entity3.entity_id, entity4.entity_id, entity5.entity_id, - entity6.entity_id, ], "brightness_pct": 25, "rgb_color": color_util.RGBColor(128, 0, 0), @@ -1985,10 +1760,8 @@ async def test_light_service_call_color_conversion_named_tuple( _, data = entity3.last_call("turn_on") assert data == {"brightness": 64, "rgb_color": (128, 0, 0)} _, data = entity4.last_call("turn_on") - assert data == {"brightness": 64, "hs_color": (0.0, 100.0)} - _, data = entity5.last_call("turn_on") assert data == {"brightness": 64, "rgbw_color": (128, 0, 0, 0)} - _, data = entity6.last_call("turn_on") + _, data = entity5.last_call("turn_on") assert data == {"brightness": 64, "rgbww_color": (128, 0, 0, 0, 0)} @@ -2357,13 +2130,6 @@ async def test_light_state_color_conversion(hass: HomeAssistant) -> None: entity2.rgb_color = "Invalid" # Should be ignored entity2.xy_color = (0.1, 0.8) - entity3 = entities[3] - entity3.hs_color = (240, 100) - entity3.supported_features = light.SUPPORT_COLOR - # Set color modes to none to trigger backwards compatibility in LightEntity - entity3.supported_color_modes = None - entity3.color_mode = None - assert await async_setup_component(hass, "light", {"light": {"platform": "test"}}) await hass.async_block_till_done() @@ -2385,12 +2151,6 @@ async def test_light_state_color_conversion(hass: HomeAssistant) -> None: assert state.attributes["rgb_color"] == (0, 255, 22) assert state.attributes["xy_color"] == (0.1, 0.8) - state = hass.states.get(entity3.entity_id) - assert state.attributes["color_mode"] == light.ColorMode.HS - assert state.attributes["hs_color"] == (240, 100) - assert state.attributes["rgb_color"] == (0, 0, 255) - assert state.attributes["xy_color"] == (0.136, 0.04) - async def test_services_filter_parameters( hass: HomeAssistant, @@ -2625,27 +2385,6 @@ def test_filter_supported_color_modes() -> None: assert light.filter_supported_color_modes(supported) == {light.ColorMode.BRIGHTNESS} -def test_deprecated_supported_features_ints(caplog: pytest.LogCaptureFixture) -> None: - """Test deprecated supported features ints.""" - - class MockLightEntityEntity(light.LightEntity): - @property - def supported_features(self) -> int: - """Return supported features.""" - return 1 - - entity = MockLightEntityEntity() - assert entity.supported_features_compat is light.LightEntityFeature(1) - assert "MockLightEntityEntity" in caplog.text - assert "is using deprecated supported features values" in caplog.text - assert "Instead it should use" in caplog.text - assert "LightEntityFeature" in caplog.text - assert "and color modes" in caplog.text - caplog.clear() - assert entity.supported_features_compat is light.LightEntityFeature(1) - assert "is using deprecated supported features values" not in caplog.text - - @pytest.mark.parametrize( ("color_mode", "supported_color_modes", "warning_expected"), [