Skip to content

Commit

Permalink
🚨 [2024-04-09] 移除警告信息: 解决 User Token 过期的WS 断开报错
Browse files Browse the repository at this point in the history
  • Loading branch information
MapleEve committed Apr 9, 2024
1 parent 34c1d0e commit 2ce5710
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions custom_components/lifesmart/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,12 +348,16 @@ async def data_update_handler(msg):

def on_message(ws, message):
_LOGGER.debug("websocket_msg: %s", str(message))
msg = json.loads(message)
if "type" not in msg:
return
if msg["type"] != "io":
return
asyncio.run(data_update_handler(msg))
if message: # Check if the message is not empty
try:
msg = json.loads(message)
if "type" not in msg:
return
if msg["type"] != "io":
return
asyncio.run(data_update_handler(msg))
except json.JSONDecodeError:
_LOGGER.error("Invalid JSON received: %s", str(message))

def on_error(ws, error):
_LOGGER.error("Websocket_error: %s", str(error))
Expand Down Expand Up @@ -535,7 +539,7 @@ def __init__(self, ws) -> None:
def run(self):
while self._run:
_LOGGER.debug("Lifesmart HACS: starting wss")
if not self._ws.sock or self._ws.sock.closed:
if not self._ws.sock or not self._ws.sock.connected:
try:
self._ws.run_forever()
except websocket._exceptions.WebSocketException as e:
Expand Down

0 comments on commit 2ce5710

Please sign in to comment.