Avoid update calls in state writes when attributes are empty (#115624)

This commit is contained in:
J. Nick Koston 2024-04-15 10:42:18 -05:00 committed by GitHub
parent 9f852c6a58
commit dbc5109fd8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1052,8 +1052,10 @@ class Entity(
available = self.available # only call self.available once per update cycle
state = self._stringify_state(available)
if available:
attr.update(self.state_attributes or {})
attr.update(self.extra_state_attributes or {})
if state_attributes := self.state_attributes:
attr.update(state_attributes)
if extra_state_attributes := self.extra_state_attributes:
attr.update(extra_state_attributes)
if (unit_of_measurement := self.unit_of_measurement) is not None:
attr[ATTR_UNIT_OF_MEASUREMENT] = unit_of_measurement