From 68310a426b3a5d1043f8d02010d85e0cfcc5e649 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sat, 12 Mar 2022 02:07:01 -1000 Subject: [PATCH] Small code quality improvements for subscribe_entities (#68026) --- homeassistant/components/websocket_api/messages.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/homeassistant/components/websocket_api/messages.py b/homeassistant/components/websocket_api/messages.py index 0695b279361..eac40c9510b 100644 --- a/homeassistant/components/websocket_api/messages.py +++ b/homeassistant/components/websocket_api/messages.py @@ -175,18 +175,16 @@ def compressed_state_dict_add(state: State) -> dict[str, Any]: Sends c (context) as a string if it only contains an id. """ if state.context.parent_id is None and state.context.user_id is None: - context: dict[str, Any] | str = state.context.id # type: ignore[unreachable] + context: dict[str, Any] | str = state.context.id else: context = state.context.as_dict() compressed_state: dict[str, Any] = { COMPRESSED_STATE_STATE: state.state, COMPRESSED_STATE_ATTRIBUTES: state.attributes, COMPRESSED_STATE_CONTEXT: context, + COMPRESSED_STATE_LAST_CHANGED: state.last_changed.timestamp(), } - if state.last_changed == state.last_updated: - compressed_state[COMPRESSED_STATE_LAST_CHANGED] = state.last_changed.timestamp() - else: - compressed_state[COMPRESSED_STATE_LAST_CHANGED] = state.last_changed.timestamp() + if state.last_changed != state.last_updated: compressed_state[COMPRESSED_STATE_LAST_UPDATED] = state.last_updated.timestamp() return compressed_state