Skip to content

Commit

Permalink
Fix up missing timezones.
Browse files Browse the repository at this point in the history
  • Loading branch information
twrecked committed Dec 21, 2021
1 parent 220b2de commit edc0955
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 5 deletions.
1 change: 1 addition & 0 deletions changelog
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Update devices from device refresh
Allow old backend to be used.
Quiet down traditional chimes.
Fix up missing timezones.
0.8.0a12: Use new MQTT backend
0.8.0a11: Add random user agent support.
0.8.0a10: Don't request resources for Wirefree doorbells.
Expand Down
8 changes: 4 additions & 4 deletions pyaarlo/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,17 +179,17 @@ def _request(
self._arlo.warning("request-error={}".format(type(e).__name__))
return None

self._arlo.vdebug("request-end={}".format(r.status_code))
if r.status_code != 200:
return None

try:
body = r.json()
self._arlo.vdebug("request-body=\n{}".format(pprint.pformat(body)))
except Exception as e:
self._arlo.warning("body-error={}".format(type(e).__name__))
return None

self._arlo.vdebug("request-end={}".format(r.status_code))
if r.status_code != 200:
return None

if raw:
return body

Expand Down
2 changes: 2 additions & 0 deletions pyaarlo/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
SCHEDULE_KEY,
SIREN_STATE_KEY,
TEMPERATURE_KEY,
TIMEZONE_KEY,
)
from .device import ArloDevice
from .util import time_to_arlotime
Expand Down Expand Up @@ -370,6 +371,7 @@ def update_modes(self, initial=False):
modes = modes.get(self.unique_id, {})
self._parse_modes(modes.get("modes", []))
self._parse_schedules(modes.get("schedules", []))
self._save(TIMEZONE_KEY,modes.get("olsonTimeZone", None))
else:
self._arlo.error("failed to read modes (v2)")

Expand Down
1 change: 1 addition & 0 deletions pyaarlo/constant.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
SIGNAL_STR_KEY = "signalStrength"
SIREN_STATE_KEY = "sirenState"
TEMPERATURE_KEY = "temperature"
TIMEZONE_KEY = "olsonTimeZone"
TRADITIONAL_CHIME_KEY = "traditionalChime"
NIGHTLIGHT_KEY = "nightLight"
MEDIA_PLAYER_KEY = "mediaPlayer"
Expand Down
18 changes: 17 additions & 1 deletion pyaarlo/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
RESOURCE_KEYS,
RESOURCE_UPDATE_KEYS,
SIGNAL_STR_KEY,
TIMEZONE_KEY,
XCLOUD_ID_KEY,
)

Expand Down Expand Up @@ -171,7 +172,10 @@ def hw_version(self):
@property
def timezone(self):
"""Returns the timezone."""
return self._attrs.get("properties", {}).get("olsonTimeZone", None)
time_zone = self._load(TIMEZONE_KEY, None)
if time_zone is None:
return self._attrs.get("properties", {}).get("olsonTimeZone", None)
return time_zone

@property
def user_id(self):
Expand Down Expand Up @@ -388,6 +392,18 @@ def parent_id(self):
return self._parent_id
return self.device_id

@property
def timezone(self):
"""Returns the timezone.
Tries to be clever. If it doesn't have a timezone it will try its
basestation.
"""
time_zone = super().timezone
if time_zone is None:
return self.base_station.timezone
return time_zone

@property
def base_station(self):
"""Returns the base station controlling this device.
Expand Down

0 comments on commit edc0955

Please sign in to comment.