mirror of
https://github.com/home-assistant/core.git
synced 2025-07-28 23:57:06 +00:00
Tweak typing of Entity.platform (#88321)
* Tweak typing of Entity.platform * Fix mypy errors * Fix update test * Improve comments
This commit is contained in:
parent
41022fdce4
commit
4085c4f6d8
@ -323,7 +323,6 @@ class RflinkDevice(Entity):
|
||||
Contains the common logic for Rflink entities.
|
||||
"""
|
||||
|
||||
platform = None
|
||||
_state: bool | None = None
|
||||
_available = True
|
||||
_attr_should_poll = False
|
||||
|
@ -236,9 +236,6 @@ class UpdateEntity(RestoreEntity):
|
||||
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"
|
||||
)
|
||||
|
@ -235,13 +235,15 @@ class Entity(ABC):
|
||||
# this class. These may be used to customize the behavior of the entity.
|
||||
entity_id: str = None # type: ignore[assignment]
|
||||
|
||||
# Owning hass instance. Will be set by EntityPlatform
|
||||
# Owning hass instance. Set by EntityPlatform by calling add_to_platform_start
|
||||
# While not purely typed, it makes typehinting more useful for us
|
||||
# and removes the need for constant None checks or asserts.
|
||||
hass: HomeAssistant = None # type: ignore[assignment]
|
||||
|
||||
# Owning platform instance. Will be set by EntityPlatform
|
||||
platform: EntityPlatform | None = None
|
||||
# Owning platform instance. Set by EntityPlatform by calling add_to_platform_start
|
||||
# While not purely typed, it makes typehinting more useful for us
|
||||
# and removes the need for constant None checks or asserts.
|
||||
platform: EntityPlatform = None # type: ignore[assignment]
|
||||
|
||||
# Entity description instance for this Entity
|
||||
entity_description: EntityDescription
|
||||
@ -840,7 +842,7 @@ class Entity(ABC):
|
||||
self._call_on_remove_callbacks()
|
||||
|
||||
self.hass = None # type: ignore[assignment]
|
||||
self.platform = None
|
||||
self.platform = None # type: ignore[assignment]
|
||||
self.parallel_updates = None
|
||||
|
||||
async def add_to_platform_finish(self) -> None:
|
||||
|
@ -49,6 +49,7 @@ async def test_update(hass: HomeAssistant) -> None:
|
||||
"""Test getting data from the mocked update entity."""
|
||||
update = MockUpdateEntity()
|
||||
update.hass = hass
|
||||
update.platform = MockEntityPlatform(hass)
|
||||
|
||||
update._attr_installed_version = "1.0.0"
|
||||
update._attr_latest_version = "1.0.1"
|
||||
@ -57,7 +58,10 @@ 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.entity_picture
|
||||
== "https://brands.home-assistant.io/_/test_platform/icon.png"
|
||||
)
|
||||
assert update.installed_version == "1.0.0"
|
||||
assert update.latest_version == "1.0.1"
|
||||
assert update.release_summary == "Summary"
|
||||
@ -76,13 +80,6 @@ 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"
|
||||
|
Loading…
x
Reference in New Issue
Block a user