Add translations to Hue effects (#138990)

* Add translations to Hue effects

* Add translations to Hue effects

* Add more effects

* Fix

* Trigger build
This commit is contained in:
Joost Lekkerkerker 2025-03-25 17:01:25 +01:00 committed by GitHub
parent a2f92b1e28
commit 2cbe8a4a14
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 36 additions and 14 deletions

View File

@ -102,6 +102,28 @@
}
}
},
"light": {
"hue_light": {
"state_attributes": {
"effect": {
"state": {
"candle": "Candle",
"sparkle": "Sparkle",
"glisten": "Glisten",
"sunrise": "Sunrise",
"sunset": "Sunset",
"fire": "Fire",
"prism": "Prism",
"opal": "Opal",
"underwater": "Underwater",
"cosmos": "Cosmos",
"sunbeam": "Sunbeam",
"enchant": "Enchant"
}
}
}
}
},
"sensor": {
"zigbee_connectivity": {
"name": "Zigbee connectivity",

View File

@ -18,6 +18,7 @@ from homeassistant.components.light import (
ATTR_FLASH,
ATTR_TRANSITION,
ATTR_XY_COLOR,
EFFECT_OFF,
FLASH_SHORT,
ColorMode,
LightEntity,
@ -39,7 +40,6 @@ from .helpers import (
normalize_hue_transition,
)
EFFECT_NONE = "None"
FALLBACK_MIN_KELVIN = 6500
FALLBACK_MAX_KELVIN = 2000
FALLBACK_KELVIN = 5800 # halfway
@ -75,7 +75,7 @@ class HueLight(HueBaseEntity, LightEntity):
_fixed_color_mode: ColorMode | None = None
entity_description = LightEntityDescription(
key="hue_light", has_entity_name=True, name=None
key="hue_light", translation_key="hue_light", has_entity_name=True, name=None
)
def __init__(
@ -118,7 +118,7 @@ class HueLight(HueBaseEntity, LightEntity):
if x != TimedEffectStatus.NO_EFFECT
]
if len(self._attr_effect_list) > 0:
self._attr_effect_list.insert(0, EFFECT_NONE)
self._attr_effect_list.insert(0, EFFECT_OFF)
self._attr_supported_features |= LightEntityFeature.EFFECT
@property
@ -211,7 +211,7 @@ class HueLight(HueBaseEntity, LightEntity):
if timed_effects := self.resource.timed_effects:
if timed_effects.status != TimedEffectStatus.NO_EFFECT:
return timed_effects.status.value
return EFFECT_NONE
return EFFECT_OFF
async def async_turn_on(self, **kwargs: Any) -> None:
"""Turn the device on."""
@ -233,12 +233,12 @@ class HueLight(HueBaseEntity, LightEntity):
self._color_temp_active = color_temp is not None
flash = kwargs.get(ATTR_FLASH)
effect = effect_str = kwargs.get(ATTR_EFFECT)
if effect_str in (EFFECT_NONE, EFFECT_NONE.lower()):
# ignore effect if set to "None" and we have no effect active
# the special effect "None" is only used to stop an active effect
if effect_str == EFFECT_OFF:
# ignore effect if set to "off" and we have no effect active
# the special effect "off" is only used to stop an active effect
# but sending it while no effect is active can actually result in issues
# https://github.com/home-assistant/core/issues/122165
effect = None if self.effect == EFFECT_NONE else EffectStatus.NO_EFFECT
effect = None if self.effect == EFFECT_OFF else EffectStatus.NO_EFFECT
elif effect_str is not None:
# work out if we got a regular effect or timed effect
effect = EffectStatus(effect_str)

View File

@ -42,8 +42,8 @@ async def test_lights(
assert light_1.attributes["min_mireds"] == 153
assert light_1.attributes["max_mireds"] == 500
assert light_1.attributes["dynamics"] == "dynamic_palette"
assert light_1.attributes["effect_list"] == ["None", "candle", "fire"]
assert light_1.attributes["effect"] == "None"
assert light_1.attributes["effect_list"] == ["off", "candle", "fire"]
assert light_1.attributes["effect"] == "off"
# test light which supports color temperature only
light_2 = hass.states.get("light.hue_light_with_color_temperature_only")
@ -57,7 +57,7 @@ async def test_lights(
assert light_2.attributes["min_mireds"] == 153
assert light_2.attributes["max_mireds"] == 454
assert light_2.attributes["dynamics"] == "none"
assert light_2.attributes["effect_list"] == ["None", "candle", "sunrise"]
assert light_2.attributes["effect_list"] == ["off", "candle", "sunrise"]
# test light which supports color only
light_3 = hass.states.get("light.hue_light_with_color_only")
@ -201,7 +201,7 @@ async def test_light_turn_on_service(
await hass.services.async_call(
"light",
"turn_on",
{"entity_id": test_light_id, "effect": "None"},
{"entity_id": test_light_id, "effect": "off"},
blocking=True,
)
assert len(mock_bridge_v2.mock_requests) == 8
@ -216,14 +216,14 @@ async def test_light_turn_on_service(
await hass.async_block_till_done()
test_light = hass.states.get(test_light_id)
assert test_light is not None
assert test_light.attributes["effect"] == "None"
assert test_light.attributes["effect"] == "off"
# test turn on with useless effect
# it should send a effect in the request if the device has no effect active
await hass.services.async_call(
"light",
"turn_on",
{"entity_id": test_light_id, "effect": "None"},
{"entity_id": test_light_id, "effect": "off"},
blocking=True,
)
assert len(mock_bridge_v2.mock_requests) == 9