From 6c3edb73f9bf3100542e067777cc47d2ea5d4510 Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Thu, 9 Nov 2023 22:46:54 +0100 Subject: [PATCH] [`music.snapcast`] Fixed message serialization issue. Closes: #338 --- platypush/plugins/music/snapcast/__init__.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/platypush/plugins/music/snapcast/__init__.py b/platypush/plugins/music/snapcast/__init__.py index 6ee54e9dd2..5a22f7645d 100644 --- a/platypush/plugins/music/snapcast/__init__.py +++ b/platypush/plugins/music/snapcast/__init__.py @@ -1,7 +1,7 @@ import json import socket import threading -from typing import Collection, Optional +from typing import Collection, Optional, Union from platypush.config import Config from platypush.context import get_backend @@ -52,18 +52,18 @@ class MusicSnapcastPlugin(Plugin): return sock @classmethod - def _send(cls, sock: socket.socket, req: dict): + def _send(cls, sock: socket.socket, req: Union[dict, str, bytes]): if isinstance(req, dict): - r = json.dumps(req) + req = json.dumps(req) if isinstance(req, str): - r = req.encode() - if not isinstance(r, bytes): + req = req.encode() + if isinstance(req, bytes): + sock.send(req + cls._SOCKET_EOL) + else: raise RuntimeError( f'Unsupported type {type(req)} for Snapcast request: {req}' ) - sock.send(r + cls._SOCKET_EOL) - @classmethod def _recv(cls, sock): buf = b''