forked from platypush/platypush
parent
1ec42e11fc
commit
6c3edb73f9
1 changed files with 7 additions and 7 deletions
|
@ -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''
|
||||
|
|
Loading…
Reference in a new issue