From 09dd3dd5fb9cdb720f48a594d7360e0b40488088 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Fri, 28 Mar 2025 12:21:38 -1000 Subject: [PATCH] Improve performance of websocket_api _state_diff_event We can use last_updated_timestamp for the compare since its always calculated when the state is created and comparing floats is much faster than datetime objects --- homeassistant/components/websocket_api/messages.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/homeassistant/components/websocket_api/messages.py b/homeassistant/components/websocket_api/messages.py index 0a8200c5700649..6ae7de2c4b7e7d 100644 --- a/homeassistant/components/websocket_api/messages.py +++ b/homeassistant/components/websocket_api/messages.py @@ -207,7 +207,7 @@ def _state_diff_event( additions[COMPRESSED_STATE_STATE] = new_state.state if old_state.last_changed != new_state.last_changed: additions[COMPRESSED_STATE_LAST_CHANGED] = new_state.last_changed_timestamp - elif old_state.last_updated != new_state.last_updated: + elif old_state.last_updated_timestamp != new_state.last_updated_timestamp: additions[COMPRESSED_STATE_LAST_UPDATED] = new_state.last_updated_timestamp if old_state_context.parent_id != new_state_context.parent_id: additions[COMPRESSED_STATE_CONTEXT] = {"parent_id": new_state_context.parent_id}