Change update default entity category based on features (#68455)

This commit is contained in:
Franck Nijhof 2022-03-21 14:35:40 +01:00 committed by GitHub
parent add741d789
commit 2424564d2c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 2 deletions

View File

@ -186,7 +186,9 @@ class UpdateEntity(RestoreEntity):
return self._attr_entity_category
if hasattr(self, "entity_description"):
return self.entity_description.entity_category
return EntityCategory.CONFIG
if self.supported_features & UpdateEntityFeature.INSTALL:
return EntityCategory.CONFIG
return EntityCategory.DIAGNOSTIC
@property
def in_progress(self) -> bool | int | None:

View File

@ -21,6 +21,7 @@ from homeassistant.components.update.const import (
ATTR_RELEASE_URL,
ATTR_SKIPPED_VERSION,
ATTR_TITLE,
UpdateEntityFeature,
)
from homeassistant.const import (
ATTR_ENTITY_ID,
@ -53,7 +54,7 @@ async def test_update(hass: HomeAssistant) -> None:
update._attr_release_url = "https://example.com"
update._attr_title = "Title"
assert update.entity_category is EntityCategory.CONFIG
assert update.entity_category is EntityCategory.DIAGNOSTIC
assert update.current_version == "1.0.0"
assert update.latest_version == "1.0.1"
assert update.release_summary == "Summary"
@ -86,7 +87,12 @@ async def test_update(hass: HomeAssistant) -> None:
update._attr_latest_version = None
assert update.state is None
# Test entity category becomes config when its possible to install
update._attr_supported_features = UpdateEntityFeature.INSTALL
assert update.entity_category is EntityCategory.CONFIG
# UpdateEntityDescription was set
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