From 6901e5ea5ede5ba357baab294fdde91f6ef6ce8b Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Sat, 7 May 2016 10:16:14 -0700 Subject: [PATCH] Random fixes (#1996) * OwnTracks handle malformed data better Fixes #1991 . * Remove dependency for util.dt --- homeassistant/components/device_tracker/owntracks.py | 2 +- homeassistant/util/dt.py | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/homeassistant/components/device_tracker/owntracks.py b/homeassistant/components/device_tracker/owntracks.py index e2dbd0185f8..8254285a98b 100644 --- a/homeassistant/components/device_tracker/owntracks.py +++ b/homeassistant/components/device_tracker/owntracks.py @@ -101,7 +101,7 @@ def setup_scanner(hass, config, see): """Execute enter event.""" zone = hass.states.get("zone.{}".format(location)) 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 beacons = MOBILE_BEACONS_ACTIVE[dev_id] if location not in beacons: diff --git a/homeassistant/util/dt.py b/homeassistant/util/dt.py index bbcefa54fac..16e8dfebfd1 100644 --- a/homeassistant/util/dt.py +++ b/homeassistant/util/dt.py @@ -1,5 +1,4 @@ """Provides helper methods to handle the time in HA.""" -import calendar import datetime as dt import re @@ -62,13 +61,13 @@ def as_utc(dattim): def as_timestamp(dt_value): """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 else: parsed_dt = parse_datetime(str(dt_value)) if not parsed_dt: raise ValueError("not a valid date/time.") - return calendar.timegm(parsed_dt.utctimetuple()) + return parsed_dt.timestamp() def as_local(dattim):