From c96f73d1be946b5e0311c396a92aeeb3fde1fa7b Mon Sep 17 00:00:00 2001 From: Robbie Trencheny Date: Mon, 23 May 2016 14:05:12 -0700 Subject: [PATCH] If we have duration_in_traffic use that as the state, otherwise use duration --- homeassistant/components/sensor/google_travel_time.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/homeassistant/components/sensor/google_travel_time.py b/homeassistant/components/sensor/google_travel_time.py index a2f5e317aec..c4415cc2cef 100644 --- a/homeassistant/components/sensor/google_travel_time.py +++ b/homeassistant/components/sensor/google_travel_time.py @@ -136,11 +136,12 @@ class GoogleTravelTimeSensor(Entity): @property def state(self): """Return the state of the sensor.""" - try: - res = self._matrix['rows'][0]['elements'][0]['duration']['value'] - return round(res/60) - except KeyError: - return None + _data = self._matrix['rows'][0]['elements'][0] + if 'duration_in_traffic' in _data: + return round(_data['duration_in_traffic']['value']/60) + if 'duration' in _data: + return round(_data['duration']['value']/60) + return None @property def name(self):