Name unnamed sensors by their device class (#94646)

This commit is contained in:
Erik Montnemery 2023-06-20 23:09:24 +02:00 committed by GitHub
parent b857dc8d94
commit 446a820cbb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 109 additions and 0 deletions

View file

@ -257,6 +257,13 @@ class SensorEntity(Entity):
self._async_read_entity_options()
self._update_suggested_precision()
def _default_to_device_class_name(self) -> bool:
"""Return True if an unnamed entity should be named by its device class.
For sensors this is True if the entity has a device class.
"""
return self.device_class not in (None, SensorDeviceClass.ENUM)
@property
def device_class(self) -> SensorDeviceClass | None:
"""Return the class of this entity."""