Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert WebSocket messages to bytes before passing them to send_message #129300

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 17 additions & 9 deletions homeassistant/components/websocket_api/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@
from homeassistant.util.json import JsonValueType

from . import const, messages
from .messages import (
error_message,
event_message,
message_to_json_bytes,
result_message,
)
from .util import describe_request

if TYPE_CHECKING:
Expand Down Expand Up @@ -126,12 +132,12 @@ def unsub() -> None:
@callback
def send_result(self, msg_id: int, result: Any | None = None) -> None:
"""Send a result message."""
self.send_message(messages.result_message(msg_id, result))
self.send_message(message_to_json_bytes(result_message(msg_id, result)))

@callback
def send_event(self, msg_id: int, event: Any | None = None) -> None:
"""Send a event message."""
self.send_message(messages.event_message(msg_id, event))
self.send_message(message_to_json_bytes(event_message(msg_id, event)))

@callback
def send_error(
Expand All @@ -145,13 +151,15 @@ def send_error(
) -> None:
"""Send an error message."""
self.send_message(
messages.error_message(
msg_id,
code,
message,
translation_key=translation_key,
translation_domain=translation_domain,
translation_placeholders=translation_placeholders,
message_to_json_bytes(
error_message(
msg_id,
code,
message,
translation_key=translation_key,
translation_domain=translation_domain,
translation_placeholders=translation_placeholders,
)
)
)

Expand Down
Loading