From d3f84ebe0826e535e97d0f15bfb979b91b2d7816 Mon Sep 17 00:00:00 2001 From: Johannes Hoppe Date: Sun, 7 Jan 2018 16:35:10 +0100 Subject: [PATCH] Handel JSON parsing errors --- yeelib/bulbs.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/yeelib/bulbs.py b/yeelib/bulbs.py index 920f81d..5f4fde4 100644 --- a/yeelib/bulbs.py +++ b/yeelib/bulbs.py @@ -71,8 +71,11 @@ def send_command(self, method, params): logger.exception("Connection error") self.socket = None else: - response = yield from reader.readline() + response = (yield from reader.readline()).decode() if response is not None: logger.debug("%s: ... %s", - self.ip, response.decode().strip()) - return json.loads(response.decode()) + self.ip, response.strip()) + try: + return json.loads(response) + except ValueError: + logger.exception("Could not read message: %s", response)