Improve performance of calculating state (#138832)

```
print(timeit.timeit("x.update(y)", setup=x={a:b}
This commit is contained in:
J. Nick Koston 2025-02-19 02:43:41 -06:00 committed by GitHub
parent b6cb2bfe5b
commit d97194303a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1085,9 +1085,9 @@ class Entity(
state = self._stringify_state(available) state = self._stringify_state(available)
if available: if available:
if state_attributes := self.state_attributes: if state_attributes := self.state_attributes:
attr.update(state_attributes) attr |= state_attributes
if extra_state_attributes := self.extra_state_attributes: if extra_state_attributes := self.extra_state_attributes:
attr.update(extra_state_attributes) attr |= extra_state_attributes
if (unit_of_measurement := self.unit_of_measurement) is not None: if (unit_of_measurement := self.unit_of_measurement) is not None:
attr[ATTR_UNIT_OF_MEASUREMENT] = unit_of_measurement attr[ATTR_UNIT_OF_MEASUREMENT] = unit_of_measurement
@ -1214,7 +1214,7 @@ class Entity(
else: else:
# Overwrite properties that have been set in the config file. # Overwrite properties that have been set in the config file.
if custom := customize.get(entity_id): if custom := customize.get(entity_id):
attr.update(custom) attr |= custom
if ( if (
self._context_set is not None self._context_set is not None