mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 20:57:21 +00:00
Set brand icon as entity picture on update entities (#69200)
Co-authored-by: Joakim Sørensen <ludeeus@ludeeus.dev>
This commit is contained in:
parent
bd1d7bdbb7
commit
b644e7ed0f
@ -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.
|
||||
|
@ -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."""
|
||||
|
@ -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:
|
||||
|
@ -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"
|
||||
|
@ -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"
|
||||
|
Loading…
x
Reference in New Issue
Block a user