Add support to entity registry for overriding device_class (#59985)

This commit is contained in:
Erik Montnemery 2021-11-22 17:38:06 +01:00 committed by GitHub
parent 67e13b35db
commit 49a27e12ad
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
31 changed files with 136 additions and 69 deletions

View file

@ -127,7 +127,7 @@ def get_device_class(hass: HomeAssistant, entity_id: str) -> str | None:
if not (entry := entity_registry.async_get(entity_id)):
raise HomeAssistantError(f"Unknown entity {entity_id}")
return entry.device_class
return entry.device_class or entry.original_device_class
def get_supported_features(hass: HomeAssistant, entity_id: str) -> int:
@ -540,7 +540,9 @@ class Entity(ABC):
if (attribution := self.attribution) is not None:
attr[ATTR_ATTRIBUTION] = attribution
if (device_class := self.device_class) is not None:
if (
device_class := (entry and entry.device_class) or self.device_class
) is not None:
attr[ATTR_DEVICE_CLASS] = str(device_class)
if (entity_picture := self.entity_picture) is not None: