Random fixes (#1996)

* OwnTracks handle malformed data better

Fixes #1991 .

* Remove dependency for util.dt
This commit is contained in:
Paulus Schoutsen 2016-05-07 10:16:14 -07:00
parent 8a16a7d943
commit 6901e5ea5e
2 changed files with 3 additions and 4 deletions

View File

@ -101,7 +101,7 @@ def setup_scanner(hass, config, see):
"""Execute enter event.""" """Execute enter event."""
zone = hass.states.get("zone.{}".format(location)) zone = hass.states.get("zone.{}".format(location))
with LOCK: with LOCK:
if zone is None and data['t'] == 'b': if zone is None and data.get('t') == 'b':
# Not a HA zone, and a beacon so assume mobile # Not a HA zone, and a beacon so assume mobile
beacons = MOBILE_BEACONS_ACTIVE[dev_id] beacons = MOBILE_BEACONS_ACTIVE[dev_id]
if location not in beacons: if location not in beacons:

View File

@ -1,5 +1,4 @@
"""Provides helper methods to handle the time in HA.""" """Provides helper methods to handle the time in HA."""
import calendar
import datetime as dt import datetime as dt
import re import re
@ -62,13 +61,13 @@ def as_utc(dattim):
def as_timestamp(dt_value): def as_timestamp(dt_value):
"""Convert a date/time into a unix time (seconds since 1970).""" """Convert a date/time into a unix time (seconds since 1970)."""
if hasattr(dt_value, "utctimetuple"): if hasattr(dt_value, "timestamp"):
parsed_dt = dt_value parsed_dt = dt_value
else: else:
parsed_dt = parse_datetime(str(dt_value)) parsed_dt = parse_datetime(str(dt_value))
if not parsed_dt: if not parsed_dt:
raise ValueError("not a valid date/time.") raise ValueError("not a valid date/time.")
return calendar.timegm(parsed_dt.utctimetuple()) return parsed_dt.timestamp()
def as_local(dattim): def as_local(dattim):