Add effects translation/icon for Demo light (#142862)

This commit is contained in:
karwosts 2025-04-14 06:14:00 -07:00 committed by GitHub
parent 6d74a6aa19
commit 6a95abb831
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 35 additions and 9 deletions

View File

@ -45,6 +45,17 @@
}
}
},
"light": {
"bed_light": {
"state_attributes": {
"effect": {
"state": {
"rainbow": "mdi:looks"
}
}
}
}
},
"number": {
"volume": {
"default": "mdi:volume-high"

View File

@ -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)

View File

@ -78,6 +78,17 @@
}
}
},
"light": {
"bed_light": {
"state_attributes": {
"effect": {
"state": {
"rainbow": "Rainbow"
}
}
}
}
},
"select": {
"speed": {
"state": {

View File

@ -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,

View File

@ -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"]}
],
},
],