From a0645b650e73e5c3085f0fa494390ef81ebc3009 Mon Sep 17 00:00:00 2001 From: Chris Boyle Date: Tue, 2 Aug 2022 00:30:35 +0100 Subject: [PATCH] Don't die on "pong" response When we ping_hb() the server pongs. If you sleep long enough for this to happen (152 seconds?) your subsequent operations fail, ultimately due to trying to parse `pong` as JSON. --- ewelink/ws.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/ewelink/ws.py b/ewelink/ws.py index 64bcd3d..66768b3 100644 --- a/ewelink/ws.py +++ b/ewelink/ws.py @@ -1,4 +1,4 @@ -import aiohttp, time, random, asyncio +import aiohttp, time, random, asyncio, json from typing import AnyStr, TypedDict @@ -84,7 +84,10 @@ async def update_device_status(self, deviceid: str, **kwargs: list[dict[str, Any async def poll_event(self): while True: - msg: dict[str, dict[str, bool | AnyStr] | AnyStr] = await self.ws.receive_json() + received = await self.ws.receive_str() + if received == 'pong': + continue + msg: dict[str, dict[str, bool | AnyStr] | AnyStr] = json.loads(received) if action := msg.get('action', None): match action: case "sysmsg":