diff --git a/.gitignore b/.gitignore index 86c42d3..8d7bfeb 100644 --- a/.gitignore +++ b/.gitignore @@ -3,12 +3,12 @@ events/ devices/ cred* envsinric/ -test*.py +tes*.py sinricpro_logfile* tests/ test_bulb.py credential.py -test_eve* +venv/ localdata* dist/ build/ diff --git a/sinric/_sinricpro_constants.py b/sinric/_sinricpro_constants.py index 2b28580..1162081 100644 --- a/sinric/_sinricpro_constants.py +++ b/sinric/_sinricpro_constants.py @@ -57,7 +57,7 @@ class SinricProConstants(object): NAME = 'name' BANDS = 'bands' THERMOSTATMODE = 'thermostatMode' - MODE: 'mode', + MODE = 'mode', # values diff --git a/sinric/_sinricpro_websocket.py b/sinric/_sinricpro_websocket.py index d882946..0c01fd2 100644 --- a/sinric/_sinricpro_websocket.py +++ b/sinric/_sinricpro_websocket.py @@ -8,6 +8,8 @@ from websockets import client from websockets.exceptions import ConnectionClosed import json + +from .helpers.wait import waitAsync from ._queues import queue from ._callback_handler import CallBackHandler from ._signature import Signature @@ -54,7 +56,9 @@ async def connect(self): # Producer async def receive_message(self, connection): while True: try: - message = await connection.recv() + message = await waitAsync(connection.recv()) + if message is None: + continue if self.enableTrace: self.logger.info(f"Request : {message}") request = json.loads(message) diff --git a/sinric/helpers/wait.py b/sinric/helpers/wait.py new file mode 100644 index 0000000..cd7b04a --- /dev/null +++ b/sinric/helpers/wait.py @@ -0,0 +1,11 @@ + + +import asyncio + + +async def waitAsync(aysncAction): + try: + val = await asyncio.wait_for(aysncAction, timeout=1) + return val + except Exception: + return None \ No newline at end of file