From a5d95dfbdcf0d9ca3da93f44e2cbb5d162ac3272 Mon Sep 17 00:00:00 2001 From: Phil Bruckner Date: Sat, 1 Sep 2018 11:49:03 -0500 Subject: [PATCH] Make last_seen attribute a timezone aware datetime in UTC (#16348) The last_seen attribute was a datetime in the local timezone but with no tzinfo (i.e., a "naive" datetime.) When state changes occurred it would be printed incorrectly in homeassistant.log because homeassistant.util.dt.as_local assumes any datetime without tzinfo is UTC. Also most, if not all, datetime attributes are timezone aware in UTC. So use homeassistant.util.dt.as_utc (which assumes a naive datetime is local) to convert last_seen to a timezone aware datetime in UTC. --- homeassistant/components/device_tracker/google_maps.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/device_tracker/google_maps.py b/homeassistant/components/device_tracker/google_maps.py index 8c21e71bd30..170d3de6800 100644 --- a/homeassistant/components/device_tracker/google_maps.py +++ b/homeassistant/components/device_tracker/google_maps.py @@ -15,7 +15,7 @@ from homeassistant.const import ATTR_ID, CONF_PASSWORD, CONF_USERNAME import homeassistant.helpers.config_validation as cv from homeassistant.helpers.event import track_time_interval from homeassistant.helpers.typing import ConfigType -from homeassistant.util import slugify +from homeassistant.util import slugify, dt as dt_util REQUIREMENTS = ['locationsharinglib==2.0.11'] @@ -92,7 +92,7 @@ class GoogleMapsScanner: ATTR_ADDRESS: person.address, ATTR_FULL_NAME: person.full_name, ATTR_ID: person.id, - ATTR_LAST_SEEN: person.datetime, + ATTR_LAST_SEEN: dt_util.as_utc(person.datetime), ATTR_NICKNAME: person.nickname, } self.see(