From 0c86667ad2f86a62c3bfd9535e3f80809996652e Mon Sep 17 00:00:00 2001 From: Marcelo Moreira de Mello Date: Tue, 5 Jun 2018 00:08:38 -0400 Subject: [PATCH] Fixed NoneType sseclient error --- pyarlo/base_station.py | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/pyarlo/base_station.py b/pyarlo/base_station.py index a70d1fa..57ec94b 100644 --- a/pyarlo/base_station.py +++ b/pyarlo/base_station.py @@ -57,22 +57,28 @@ def thread_function(self): self.__sseclient = sseclient.SSEClient(data) - for event in (self.__sseclient).events(): - if not self.__subscribed: - break - data = json.loads(event.data) - if data.get('status') == "connected": - _LOGGER.debug("Successfully subscribed this base station") - elif data.get('action'): - action = data.get('action') - resource = data.get('resource') - if action == "logout": - _LOGGER.debug("Logged out by some other entity") - self.__subscribed = False + try: + for event in (self.__sseclient).events(): + if not self.__subscribed: break - elif action == "is" and "subscriptions/" not in resource: - self.__events.append(data) - self.__event_handle.set() + data = json.loads(event.data) + if data.get('status') == "connected": + _LOGGER.debug("Successfully subscribed this base station") + elif data.get('action'): + action = data.get('action') + resource = data.get('resource') + if action == "logout": + _LOGGER.debug("Logged out by some other entity") + self.__subscribed = False + break + elif action == "is" and "subscriptions/" not in resource: + self.__events.append(data) + self.__event_handle.set() + + except TypeError as error: + _LOGGER.debug("Got unexpected error: %s", error) + return None + return True def _get_event_stream(self):