Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set brand icon as entity picture on update entities #69200

Merged
merged 4 commits into from
Apr 3, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions homeassistant/components/update/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,20 @@ def entity_category(self) -> EntityCategory | None:
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.
Expand Down
5 changes: 0 additions & 5 deletions homeassistant/components/wled/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,6 @@ def installed_version(self) -> str | None:
return None
return str(version)

@property
def entity_picture(self) -> str:
ludeeus marked this conversation as resolved.
Show resolved Hide resolved
"""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."""
Expand Down
28 changes: 27 additions & 1 deletion tests/components/demo/test_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@
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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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:
Expand Down
10 changes: 9 additions & 1 deletion tests/components/update/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
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):
Expand All @@ -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"
Expand All @@ -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"
Expand Down