Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions pyvera/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,31 +243,31 @@ def get_changed_devices(self, timestamp):
payload.update({
'id': 'lu_sdata',
})

LOG.debug("get_changed_devices() requesting payload %s", str(payload))
r = self.data_request(payload, TIMEOUT*2)
r.raise_for_status()

# If the Vera disconnects before writing a full response (as lu_sdata
# will do when interrupted by a Luup reload), the requests module will
# If the Vera disconnects before writing a full response (as lu_sdata
# will do when interrupted by a Luup reload), the requests module will
# happily return 200 with an empty string. So, test for empty response,
# so we don't rely on the JSON parser to throw an exception.
if r.text == "":
raise PyveraError("Empty response from Vera")

# Catch a wide swath of what the JSON parser might throw, within
# reason. Unfortunately, some parsers don't specifically return
# reason. Unfortunately, some parsers don't specifically return
# json.decode.JSONDecodeError, but so far most seem to derive what
# they do throw from ValueError, so that's helpful.
try:
result = r.json()
except ValueError as ex:
raise PyveraError("JSON decode error: " + str(ex))

if not ( type(result) is dict
if not ( type(result) is dict
and 'loadtime' in result and 'dataversion' in result ):
raise PyveraError("Unexpected/garbled response from Vera")

# At this point, all good. Update timestamp and return change data.
device_data = result.get('devices')
timestamp = {
Expand Down
8 changes: 5 additions & 3 deletions pyvera/subscribe.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

class PyveraError(Exception):
pass

class SubscriptionRegistry(object):
"""Class for subscribing to wemo events."""

Expand Down Expand Up @@ -140,7 +140,7 @@ def _run_poll_server(self):
LOG.debug("Non-fatal error in poll: %s", str(ex))
pass
except Exception as ex:
LOG.exception("Vera poll thread general exception: %s",
LOG.exception("Vera poll thread general exception: %s",
str(ex))
raise
else:
Expand All @@ -151,9 +151,11 @@ def _run_poll_server(self):
else:
LOG.debug("No changes in poll interval")
time.sleep(1)

continue

# After error, discard timestamp for fresh update. pyvera issue #89
timestamp = None
LOG.info("Could not poll Vera - will retry in %ss",
SUBSCRIPTION_RETRY)
time.sleep(SUBSCRIPTION_RETRY)
Expand Down