mirror of
https://github.com/home-assistant/core.git
synced 2025-11-16 14:30:22 +00:00
Cache entity properties that are never expected to change in the base class (#95315)
This commit is contained in:
@@ -59,11 +59,13 @@ class MockUpdateEntity(UpdateEntity):
|
||||
"""Mock UpdateEntity to use in tests."""
|
||||
|
||||
|
||||
async def test_update(hass: HomeAssistant) -> None:
|
||||
"""Test getting data from the mocked update entity."""
|
||||
def _create_mock_update_entity(
|
||||
hass: HomeAssistant,
|
||||
) -> MockUpdateEntity:
|
||||
mock_platform = MockEntityPlatform(hass)
|
||||
update = MockUpdateEntity()
|
||||
update.hass = hass
|
||||
update.platform = MockEntityPlatform(hass)
|
||||
update.platform = mock_platform
|
||||
|
||||
update._attr_installed_version = "1.0.0"
|
||||
update._attr_latest_version = "1.0.1"
|
||||
@@ -71,6 +73,13 @@ async def test_update(hass: HomeAssistant) -> None:
|
||||
update._attr_release_url = "https://example.com"
|
||||
update._attr_title = "Title"
|
||||
|
||||
return update
|
||||
|
||||
|
||||
async def test_update(hass: HomeAssistant) -> None:
|
||||
"""Test getting data from the mocked update entity."""
|
||||
update = _create_mock_update_entity(hass)
|
||||
|
||||
assert update.entity_category is EntityCategory.DIAGNOSTIC
|
||||
assert (
|
||||
update.entity_picture
|
||||
@@ -93,7 +102,6 @@ async def test_update(hass: HomeAssistant) -> None:
|
||||
ATTR_SKIPPED_VERSION: None,
|
||||
ATTR_TITLE: "Title",
|
||||
}
|
||||
|
||||
# Test no update available
|
||||
update._attr_installed_version = "1.0.0"
|
||||
update._attr_latest_version = "1.0.0"
|
||||
@@ -120,14 +128,19 @@ async def test_update(hass: HomeAssistant) -> None:
|
||||
assert update.state is STATE_ON
|
||||
|
||||
# Test entity category becomes config when its possible to install
|
||||
update = _create_mock_update_entity(hass)
|
||||
update._attr_supported_features = UpdateEntityFeature.INSTALL
|
||||
assert update.entity_category is EntityCategory.CONFIG
|
||||
|
||||
# UpdateEntityDescription was set
|
||||
update = _create_mock_update_entity(hass)
|
||||
update._attr_supported_features = 0
|
||||
update.entity_description = UpdateEntityDescription(key="F5 - Its very refreshing")
|
||||
assert update.device_class is None
|
||||
assert update.entity_category is EntityCategory.CONFIG
|
||||
|
||||
update = _create_mock_update_entity(hass)
|
||||
update._attr_supported_features = 0
|
||||
update.entity_description = UpdateEntityDescription(
|
||||
key="F5 - Its very refreshing",
|
||||
device_class=UpdateDeviceClass.FIRMWARE,
|
||||
@@ -137,14 +150,24 @@ async def test_update(hass: HomeAssistant) -> None:
|
||||
assert update.entity_category is None
|
||||
|
||||
# Device class via attribute (override entity description)
|
||||
update = _create_mock_update_entity(hass)
|
||||
update._attr_supported_features = 0
|
||||
update._attr_device_class = None
|
||||
assert update.device_class is None
|
||||
|
||||
update = _create_mock_update_entity(hass)
|
||||
update._attr_supported_features = 0
|
||||
update._attr_device_class = UpdateDeviceClass.FIRMWARE
|
||||
assert update.device_class is UpdateDeviceClass.FIRMWARE
|
||||
|
||||
# Entity Attribute via attribute (override entity description)
|
||||
update = _create_mock_update_entity(hass)
|
||||
update._attr_supported_features = 0
|
||||
update._attr_entity_category = None
|
||||
assert update.entity_category is None
|
||||
|
||||
update = _create_mock_update_entity(hass)
|
||||
update._attr_supported_features = 0
|
||||
update._attr_entity_category = EntityCategory.DIAGNOSTIC
|
||||
assert update.entity_category is EntityCategory.DIAGNOSTIC
|
||||
|
||||
|
||||
Reference in New Issue
Block a user