mirror of
https://github.com/home-assistant/core.git
synced 2025-07-26 06:37:52 +00:00
Improve websocket throughput of state changes (#86855)
After the start event we tend to get an event storm of state changes which can get the websocket behind. #86854 will help with that a bit, but we can reduce the overhead to build a state diff when the attributes have not changed
This commit is contained in:
parent
799edd90aa
commit
ec3475910f
@ -161,12 +161,14 @@ def _state_diff(
|
|||||||
additions[COMPRESSED_STATE_CONTEXT]["id"] = new_state.context.id
|
additions[COMPRESSED_STATE_CONTEXT]["id"] = new_state.context.id
|
||||||
else:
|
else:
|
||||||
additions[COMPRESSED_STATE_CONTEXT] = new_state.context.id
|
additions[COMPRESSED_STATE_CONTEXT] = new_state.context.id
|
||||||
old_attributes = old_state.attributes
|
if (old_attributes := old_state.attributes) != (
|
||||||
for key, value in new_state.attributes.items():
|
new_attributes := new_state.attributes
|
||||||
if old_attributes.get(key) != value:
|
):
|
||||||
additions.setdefault(COMPRESSED_STATE_ATTRIBUTES, {})[key] = value
|
for key, value in new_attributes.items():
|
||||||
if removed := set(old_attributes).difference(new_state.attributes):
|
if old_attributes.get(key) != value:
|
||||||
diff[STATE_DIFF_REMOVALS] = {COMPRESSED_STATE_ATTRIBUTES: removed}
|
additions.setdefault(COMPRESSED_STATE_ATTRIBUTES, {})[key] = value
|
||||||
|
if removed := set(old_attributes).difference(new_attributes):
|
||||||
|
diff[STATE_DIFF_REMOVALS] = {COMPRESSED_STATE_ATTRIBUTES: removed}
|
||||||
return {ENTITY_EVENT_CHANGE: {new_state.entity_id: diff}}
|
return {ENTITY_EVENT_CHANGE: {new_state.entity_id: diff}}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user