From 6a95abb831c448557e78bced421c83e75beea3ed Mon Sep 17 00:00:00 2001 From: karwosts <32912880+karwosts@users.noreply.github.com> Date: Mon, 14 Apr 2025 06:14:00 -0700 Subject: [PATCH] Add effects translation/icon for Demo light (#142862) --- homeassistant/components/demo/icons.json | 11 +++++++++++ homeassistant/components/demo/light.py | 6 +++++- homeassistant/components/demo/strings.json | 11 +++++++++++ tests/components/demo/test_light.py | 4 ++-- tests/components/google_assistant/test_smart_home.py | 12 ++++++------ 5 files changed, 35 insertions(+), 9 deletions(-) diff --git a/homeassistant/components/demo/icons.json b/homeassistant/components/demo/icons.json index eafcbb9161a..9a076f47a2d 100644 --- a/homeassistant/components/demo/icons.json +++ b/homeassistant/components/demo/icons.json @@ -45,6 +45,17 @@ } } }, + "light": { + "bed_light": { + "state_attributes": { + "effect": { + "state": { + "rainbow": "mdi:looks" + } + } + } + } + }, "number": { "volume": { "default": "mdi:volume-high" diff --git a/homeassistant/components/demo/light.py b/homeassistant/components/demo/light.py index c00f2b42828..25a7b46bfb6 100644 --- a/homeassistant/components/demo/light.py +++ b/homeassistant/components/demo/light.py @@ -15,6 +15,7 @@ from homeassistant.components.light import ( ATTR_WHITE, DEFAULT_MAX_KELVIN, DEFAULT_MIN_KELVIN, + EFFECT_OFF, ColorMode, LightEntity, LightEntityFeature, @@ -28,7 +29,7 @@ from . import DOMAIN LIGHT_COLORS = [(56, 86), (345, 75)] -LIGHT_EFFECT_LIST = ["rainbow", "none"] +LIGHT_EFFECT_LIST = ["rainbow", EFFECT_OFF] LIGHT_TEMPS = [4166, 2631] @@ -48,6 +49,7 @@ async def async_setup_entry( available=True, effect_list=LIGHT_EFFECT_LIST, effect=LIGHT_EFFECT_LIST[0], + translation_key="bed_light", device_name="Bed Light", state=False, unique_id="light_1", @@ -119,8 +121,10 @@ class DemoLight(LightEntity): rgbw_color: tuple[int, int, int, int] | None = None, rgbww_color: tuple[int, int, int, int, int] | None = None, supported_color_modes: set[ColorMode] | None = None, + translation_key: str | None = None, ) -> None: """Initialize the light.""" + self._attr_translation_key = translation_key self._available = True self._brightness = brightness self._ct = ct or random.choice(LIGHT_TEMPS) diff --git a/homeassistant/components/demo/strings.json b/homeassistant/components/demo/strings.json index da72b33d3ca..d40d3f56a6a 100644 --- a/homeassistant/components/demo/strings.json +++ b/homeassistant/components/demo/strings.json @@ -78,6 +78,17 @@ } } }, + "light": { + "bed_light": { + "state_attributes": { + "effect": { + "state": { + "rainbow": "Rainbow" + } + } + } + } + }, "select": { "speed": { "state": { diff --git a/tests/components/demo/test_light.py b/tests/components/demo/test_light.py index b39b09d9307..af9006f97cc 100644 --- a/tests/components/demo/test_light.py +++ b/tests/components/demo/test_light.py @@ -80,7 +80,7 @@ async def test_state_attributes(hass: HomeAssistant) -> None: SERVICE_TURN_ON, { ATTR_ENTITY_ID: ENTITY_LIGHT, - ATTR_EFFECT: "none", + ATTR_EFFECT: "off", ATTR_COLOR_TEMP_KELVIN: 2500, }, blocking=True, @@ -90,7 +90,7 @@ async def test_state_attributes(hass: HomeAssistant) -> None: assert state.attributes.get(ATTR_COLOR_TEMP_KELVIN) == 2500 assert state.attributes.get(ATTR_MAX_COLOR_TEMP_KELVIN) == 6535 assert state.attributes.get(ATTR_MIN_COLOR_TEMP_KELVIN) == 2000 - assert state.attributes.get(ATTR_EFFECT) == "none" + assert state.attributes.get(ATTR_EFFECT) == "off" await hass.services.async_call( LIGHT_DOMAIN, diff --git a/tests/components/google_assistant/test_smart_home.py b/tests/components/google_assistant/test_smart_home.py index 3b43728988b..2dba083185d 100644 --- a/tests/components/google_assistant/test_smart_home.py +++ b/tests/components/google_assistant/test_smart_home.py @@ -235,11 +235,11 @@ async def test_sync_message(hass: HomeAssistant, registries) -> None: ], }, { - "setting_name": "none", + "setting_name": "off", "setting_values": [ { "lang": "en", - "setting_synonym": ["none"], + "setting_synonym": ["off"], } ], }, @@ -356,9 +356,9 @@ async def test_sync_in_area(area_on_device, hass: HomeAssistant, registries) -> ], }, { - "setting_name": "none", + "setting_name": "off", "setting_values": [ - {"lang": "en", "setting_synonym": ["none"]} + {"lang": "en", "setting_synonym": ["off"]} ], }, ], @@ -957,9 +957,9 @@ async def test_unavailable_state_does_sync(hass: HomeAssistant) -> None: ], }, { - "setting_name": "none", + "setting_name": "off", "setting_values": [ - {"lang": "en", "setting_synonym": ["none"]} + {"lang": "en", "setting_synonym": ["off"]} ], }, ],