diff --git a/homeassistant/components/websocket_api/commands.py b/homeassistant/components/websocket_api/commands.py index b69ff57d015..7d59fd39a0c 100644 --- a/homeassistant/components/websocket_api/commands.py +++ b/homeassistant/components/websocket_api/commands.py @@ -53,7 +53,7 @@ from homeassistant.util.json import format_unserializable_data from . import const, decorators, messages from .connection import ActiveConnection -from .messages import construct_event_message, construct_result_message +from .messages import construct_result_message ALL_SERVICE_DESCRIPTIONS_JSON_CACHE = "websocket_api_all_service_descriptions_json" @@ -294,8 +294,9 @@ def _send_handle_get_states_response( connection: ActiveConnection, msg_id: int, serialized_states: list[str] ) -> None: """Send handle get states response.""" - joined_states = ",".join(serialized_states) - connection.send_message(construct_result_message(msg_id, f"[{joined_states}]")) + connection.send_message( + construct_result_message(msg_id, f'[{",".join(serialized_states)}]') + ) @callback @@ -383,9 +384,8 @@ def _send_handle_entities_init_response( connection: ActiveConnection, msg_id: int, serialized_states: list[str] ) -> None: """Send handle entities init response.""" - joined_states = ",".join(serialized_states) connection.send_message( - construct_event_message(msg_id, f'{{"a":{{{joined_states}}}}}') + f'{{"id":{msg_id},"type":"event","event":{{"a":{{{",".join(serialized_states)}}}}}}}' ) diff --git a/homeassistant/components/websocket_api/http.py b/homeassistant/components/websocket_api/http.py index 238cd6d7465..f2f667368c3 100644 --- a/homeassistant/components/websocket_api/http.py +++ b/homeassistant/components/websocket_api/http.py @@ -159,8 +159,7 @@ class WebSocketHandler: messages.append(message) messages_remaining -= 1 - joined_messages = ",".join(messages) - coalesced_messages = f"[{joined_messages}]" + coalesced_messages = f'[{",".join(messages)}]' if debug_enabled: debug("%s: Sending %s", self.description, coalesced_messages) await send_str(coalesced_messages) diff --git a/homeassistant/components/websocket_api/messages.py b/homeassistant/components/websocket_api/messages.py index e1b038f4222..12e649219bc 100644 --- a/homeassistant/components/websocket_api/messages.py +++ b/homeassistant/components/websocket_api/messages.py @@ -74,11 +74,6 @@ def error_message(iden: int | None, code: str, message: str) -> dict[str, Any]: } -def construct_event_message(iden: int, payload: str) -> str: - """Construct an event message JSON.""" - return f'{{"id":{iden},"type":"event","event":{payload}}}' - - def event_message(iden: int, event: Any) -> dict[str, Any]: """Return an event message.""" return {"id": iden, "type": "event", "event": event}