From c16fd0a1ac6529734942ed4793b6301a5461b1a2 Mon Sep 17 00:00:00 2001 From: starkillerOG Date: Tue, 26 Jan 2021 10:46:54 +0100 Subject: [PATCH] Set hyperion icon to lightbulb when off (#45351) Co-authored-by: Dermot Duffy --- homeassistant/components/hyperion/light.py | 14 ++++++-------- tests/components/hyperion/test_light.py | 5 +++++ 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/homeassistant/components/hyperion/light.py b/homeassistant/components/hyperion/light.py index b6d66c9a11a..92c7c1f3c02 100644 --- a/homeassistant/components/hyperion/light.py +++ b/homeassistant/components/hyperion/light.py @@ -318,7 +318,6 @@ class HyperionLight(LightEntity): self._brightness: int = 255 self._rgb_color: Sequence[int] = DEFAULT_COLOR self._effect: str = KEY_EFFECT_SOLID - self._icon: str = ICON_LIGHTBULB self._effect_list: List[str] = [] @@ -350,7 +349,12 @@ class HyperionLight(LightEntity): @property def icon(self) -> str: """Return state specific icon.""" - return self._icon + if self.is_on: + if self.effect in const.KEY_COMPONENTID_EXTERNAL_SOURCES: + return ICON_EXTERNAL_SOURCE + if self.effect != KEY_EFFECT_SOLID: + return ICON_EFFECT + return ICON_LIGHTBULB @property def effect(self) -> str: @@ -516,12 +520,6 @@ class HyperionLight(LightEntity): self._rgb_color = rgb_color if effect is not None: self._effect = effect - if effect == KEY_EFFECT_SOLID: - self._icon = ICON_LIGHTBULB - elif effect in const.KEY_COMPONENTID_EXTERNAL_SOURCES: - self._icon = ICON_EXTERNAL_SOURCE - else: - self._icon = ICON_EFFECT def _update_components(self, _: Optional[Dict[str, Any]] = None) -> None: """Update Hyperion components.""" diff --git a/tests/components/hyperion/test_light.py b/tests/components/hyperion/test_light.py index 36ec29cf2ab..9590d7be760 100644 --- a/tests/components/hyperion/test_light.py +++ b/tests/components/hyperion/test_light.py @@ -629,6 +629,11 @@ async def test_light_async_turn_off(hass: HomeAssistantType) -> None: } ) + _call_registered_callback(client, "components-update") + entity_state = hass.states.get(TEST_ENTITY_ID_1) + assert entity_state + assert entity_state.attributes["icon"] == hyperion_light.ICON_LIGHTBULB + # No calls if no state loaded. client.has_loaded_state = False client.async_send_set_component = AsyncMock(return_value=True)