Skip to content
This repository has been archived by the owner on Jul 30, 2021. It is now read-only.

Commit

Permalink
Merge pull request #78 from tchellomello/sseclient_none
Browse files Browse the repository at this point in the history
Make sure response is valid before creating Thread
  • Loading branch information
tchellomello authored Jun 5, 2018
2 parents 763116e + 5284bfd commit 05c1c14
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions pyarlo/base_station.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ def thread_function(self):
url = SUBSCRIBE_ENDPOINT + "?token=" + self._session_token

data = self._session.query(url, method='GET', raw=True, stream=True)
if not data or not data.ok:
_LOGGER.debug("Did not receive a valid response. Aborting..")
return None

self.__sseclient = sseclient.SSEClient(data)

for event in (self.__sseclient).events():
Expand All @@ -69,6 +73,7 @@ def thread_function(self):
elif action == "is" and "subscriptions/" not in resource:
self.__events.append(data)
self.__event_handle.set()
return True

def _get_event_stream(self):
"""Spawn a thread and monitor the Arlo Event Stream."""
Expand Down Expand Up @@ -277,13 +282,16 @@ def available_modes_with_ids(self):
all_modes = FIXED_MODES.copy()
self._available_mode_ids = all_modes
modes = self.get_available_modes()
if modes:
simple_modes = dict(
[(m.get("type", m.get("name")), m.get("id"))
for m in modes]
)
all_modes.update(simple_modes)
self._available_mode_ids = all_modes
try:
if modes:
simple_modes = dict(
[(m.get("type", m.get("name")), m.get("id"))
for m in modes]
)
all_modes.update(simple_modes)
self._available_mode_ids = all_modes
except TypeError:
_LOGGER.debug("Did not receive a valid response. Passing..")
return self._available_mode_ids

@property
Expand Down

0 comments on commit 05c1c14

Please sign in to comment.