mirror of
https://github.com/home-assistant/core.git
synced 2025-07-25 22:27:07 +00:00
Improve performance of generate diffs of state change events (#124601)
dict comps are inlined in cpython 3.12+
This commit is contained in:
parent
0591b5e47b
commit
76ebb0df08
@ -224,9 +224,12 @@ def _state_diff_event(
|
|||||||
if (old_attributes := old_state.attributes) != (
|
if (old_attributes := old_state.attributes) != (
|
||||||
new_attributes := new_state.attributes
|
new_attributes := new_state.attributes
|
||||||
):
|
):
|
||||||
for key, value in new_attributes.items():
|
if added := {
|
||||||
if old_attributes.get(key) != value:
|
key: value
|
||||||
additions.setdefault(COMPRESSED_STATE_ATTRIBUTES, {})[key] = value
|
for key, value in new_attributes.items()
|
||||||
|
if key not in old_attributes or old_attributes[key] != value
|
||||||
|
}:
|
||||||
|
additions[COMPRESSED_STATE_ATTRIBUTES] = added
|
||||||
if removed := old_attributes.keys() - new_attributes:
|
if removed := old_attributes.keys() - new_attributes:
|
||||||
# sets are not JSON serializable by default so we convert to list
|
# sets are not JSON serializable by default so we convert to list
|
||||||
# here if there are any values to avoid jumping into the json_encoder_default
|
# here if there are any values to avoid jumping into the json_encoder_default
|
||||||
|
Loading…
x
Reference in New Issue
Block a user