From 6973ec8d1714ee036efe9b32c6152bf9743397ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrius=20=C5=A0tikonas?= Date: Fri, 20 Nov 2020 23:26:45 +0000 Subject: [PATCH] Neohub can return invalid JSON. Assume that command failed. E.g. {"error":"Invalid argument to SET_TEMP_FORMAT, should be "C" or "F" "} Correct JSON would be {"error":"Invalid argument to SET_TEMP_FORMAT, should be \"C\" or \"F\" "} --- neohub.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/neohub.py b/neohub.py index 9f36532..c71568d 100644 --- a/neohub.py +++ b/neohub.py @@ -33,7 +33,13 @@ class NeoHub: writer.close() await writer.wait_closed() - reply = json.loads(json_string) + try: + reply = json.loads(json_string) + except json.decoder.JSONDecodeError: + if expected_reply is None: + raise(e) + else: + return False if expected_reply is None: return reply