From ed21adad2c8ca304650c0f2537d76a630dbd65c8 Mon Sep 17 00:00:00 2001 From: Erik Date: Sun, 28 Jan 2024 15:07:23 +0100 Subject: [PATCH] Revert "Correct generating cast messages" This reverts commit f85879c5e007c79124d11425ecd66de7005f1426. --- pychromecast/socket_client.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pychromecast/socket_client.py b/pychromecast/socket_client.py index 642a71254..7d742bc9b 100644 --- a/pychromecast/socket_client.py +++ b/pychromecast/socket_client.py @@ -105,6 +105,11 @@ def _message_to_string(message, data=None): ) +def _json_to_payload(data: dict) -> bytes: + """Encodes a python value into JSON format.""" + return json.dumps(data, ensure_ascii=False).encode("utf8") + + @dataclass(frozen=True) class NetworkAddress: """Network address container.""" @@ -872,7 +877,7 @@ def send_message( cast_channel_pb2.CastMessage.STRING # pylint: disable=no-member ) msg.namespace = namespace - msg.payload_utf8 = json.dumps(data, ensure_ascii=False) + msg.payload_utf8 = _json_to_payload(data) # prepend message with Big-Endian 4 byte payload size be_size = pack(">I", msg.ByteSize())