Add suggested_unit_of_measurement attribute to sensors (#80638)

* Add suggested_unit_of_measurement attribute to sensors

* Lazy calculation of initial entity options

* Add type alias for entity options

* Small tweak

* Add tests

* Store suggested_unit_of_measurement in its own option key

* Adapt to renaming of IMPERIAL_SYSTEM

* Fix rebase mistakes

* Apply suggestions from code review

Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>

Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>
This commit is contained in:
Erik Montnemery 2022-10-24 16:08:02 +02:00 committed by GitHub
parent 0c79a9a33d
commit 6979cd95b0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 380 additions and 48 deletions

View file

@ -340,6 +340,18 @@ class Entity(ABC):
"""
return self._attr_capability_attributes
def get_initial_entity_options(self) -> er.EntityOptionsType | None:
"""Return initial entity options.
These will be stored in the entity registry the first time the entity is seen,
and then never updated.
Implemented by component base class, should not be extended by integrations.
Note: Not a property to avoid calculating unless needed.
"""
return None
@property
def state_attributes(self) -> dict[str, Any] | None:
"""Return the state attributes.