From b644e7ed0fb7efb408430e7f647fb55e48052f6c Mon Sep 17 00:00:00 2001 From: Franck Nijhof Date: Sun, 3 Apr 2022 20:38:05 +0200 Subject: [PATCH] Set brand icon as entity picture on update entities (#69200) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Joakim Sørensen --- homeassistant/components/update/__init__.py | 14 +++++++++++ homeassistant/components/wled/update.py | 5 ---- tests/components/demo/test_update.py | 28 ++++++++++++++++++++- tests/components/update/test_init.py | 10 +++++++- tests/components/wled/test_update.py | 2 +- 5 files changed, 51 insertions(+), 8 deletions(-) diff --git a/homeassistant/components/update/__init__.py b/homeassistant/components/update/__init__.py index 6d4b36e3411..90418dbf8b9 100644 --- a/homeassistant/components/update/__init__.py +++ b/homeassistant/components/update/__init__.py @@ -208,6 +208,20 @@ class UpdateEntity(RestoreEntity): return EntityCategory.CONFIG return EntityCategory.DIAGNOSTIC + @property + def entity_picture(self) -> str | None: + """Return the entity picture to use in the frontend. + + Update entities return the brand icon based on the integration + domain by default. + """ + if self.platform is None: + return None + + return ( + f"https://brands.home-assistant.io/_/{self.platform.platform_name}/icon.png" + ) + @property def in_progress(self) -> bool | int | None: """Update installation progress. diff --git a/homeassistant/components/wled/update.py b/homeassistant/components/wled/update.py index c0c099ead65..f0fc532b3b3 100644 --- a/homeassistant/components/wled/update.py +++ b/homeassistant/components/wled/update.py @@ -50,11 +50,6 @@ class WLEDUpdateEntity(WLEDEntity, UpdateEntity): return None return str(version) - @property - def entity_picture(self) -> str: - """Return the entity picture to use in the frontend, if any.""" - return "https://brands.home-assistant.io/wled/icon.png" - @property def latest_version(self) -> str | None: """Latest version available for install.""" diff --git a/tests/components/demo/test_update.py b/tests/components/demo/test_update.py index ebee402049c..35780114f29 100644 --- a/tests/components/demo/test_update.py +++ b/tests/components/demo/test_update.py @@ -12,7 +12,13 @@ from homeassistant.components.update.const import ( ATTR_RELEASE_URL, ATTR_TITLE, ) -from homeassistant.const import ATTR_DEVICE_CLASS, ATTR_ENTITY_ID, STATE_OFF, STATE_ON +from homeassistant.const import ( + ATTR_DEVICE_CLASS, + ATTR_ENTITY_ID, + ATTR_ENTITY_PICTURE, + STATE_OFF, + STATE_ON, +) from homeassistant.core import HomeAssistant, callback from homeassistant.helpers.event import async_track_state_change_event from homeassistant.setup import async_setup_component @@ -37,6 +43,10 @@ def test_setup_params(hass: HomeAssistant) -> None: state.attributes[ATTR_RELEASE_SUMMARY] == "Awesome update, fixing everything!" ) assert state.attributes[ATTR_RELEASE_URL] == "https://www.example.com/release/1.0.1" + assert ( + state.attributes[ATTR_ENTITY_PICTURE] + == "https://brands.home-assistant.io/_/demo/icon.png" + ) state = hass.states.get("update.demo_no_update") assert state @@ -46,6 +56,10 @@ def test_setup_params(hass: HomeAssistant) -> None: assert state.attributes[ATTR_LATEST_VERSION] == "1.0.0" assert state.attributes[ATTR_RELEASE_SUMMARY] is None assert state.attributes[ATTR_RELEASE_URL] is None + assert ( + state.attributes[ATTR_ENTITY_PICTURE] + == "https://brands.home-assistant.io/_/demo/icon.png" + ) state = hass.states.get("update.demo_add_on") assert state @@ -57,6 +71,10 @@ def test_setup_params(hass: HomeAssistant) -> None: state.attributes[ATTR_RELEASE_SUMMARY] == "Awesome update, fixing everything!" ) assert state.attributes[ATTR_RELEASE_URL] == "https://www.example.com/release/1.0.1" + assert ( + state.attributes[ATTR_ENTITY_PICTURE] + == "https://brands.home-assistant.io/_/demo/icon.png" + ) state = hass.states.get("update.demo_living_room_bulb_update") assert state @@ -69,6 +87,10 @@ def test_setup_params(hass: HomeAssistant) -> None: state.attributes[ATTR_RELEASE_URL] == "https://www.example.com/release/1.93.3" ) assert state.attributes[ATTR_DEVICE_CLASS] == UpdateDeviceClass.FIRMWARE + assert ( + state.attributes[ATTR_ENTITY_PICTURE] + == "https://brands.home-assistant.io/_/demo/icon.png" + ) state = hass.states.get("update.demo_update_with_progress") assert state @@ -81,6 +103,10 @@ def test_setup_params(hass: HomeAssistant) -> None: state.attributes[ATTR_RELEASE_URL] == "https://www.example.com/release/1.93.3" ) assert state.attributes[ATTR_DEVICE_CLASS] == UpdateDeviceClass.FIRMWARE + assert ( + state.attributes[ATTR_ENTITY_PICTURE] + == "https://brands.home-assistant.io/_/demo/icon.png" + ) async def test_update_with_progress(hass: HomeAssistant) -> None: diff --git a/tests/components/update/test_init.py b/tests/components/update/test_init.py index 3a40b51cca2..c4078460f57 100644 --- a/tests/components/update/test_init.py +++ b/tests/components/update/test_init.py @@ -39,7 +39,7 @@ from homeassistant.helpers.entity import EntityCategory from homeassistant.helpers.event import async_track_state_change_event from homeassistant.setup import async_setup_component -from tests.common import mock_restore_cache +from tests.common import MockEntityPlatform, mock_restore_cache class MockUpdateEntity(UpdateEntity): @@ -58,6 +58,7 @@ async def test_update(hass: HomeAssistant) -> None: update._attr_title = "Title" assert update.entity_category is EntityCategory.DIAGNOSTIC + assert update.entity_picture is None assert update.installed_version == "1.0.0" assert update.latest_version == "1.0.1" assert update.release_summary == "Summary" @@ -76,6 +77,13 @@ async def test_update(hass: HomeAssistant) -> None: ATTR_TITLE: "Title", } + # Test with platform + update.platform = MockEntityPlatform(hass) + assert ( + update.entity_picture + == "https://brands.home-assistant.io/_/test_platform/icon.png" + ) + # Test no update available update._attr_installed_version = "1.0.0" update._attr_latest_version = "1.0.0" diff --git a/tests/components/wled/test_update.py b/tests/components/wled/test_update.py index e64018aba59..2ddba81ac8b 100644 --- a/tests/components/wled/test_update.py +++ b/tests/components/wled/test_update.py @@ -49,7 +49,7 @@ async def test_update_available( assert state.state == STATE_ON assert ( state.attributes[ATTR_ENTITY_PICTURE] - == "https://brands.home-assistant.io/wled/icon.png" + == "https://brands.home-assistant.io/_/wled/icon.png" ) assert state.attributes[ATTR_INSTALLED_VERSION] == "0.8.5" assert state.attributes[ATTR_LATEST_VERSION] == "0.12.0"