Skip to content

Commit

Permalink
If we have duration_in_traffic use that as the state, otherwise use d…
Browse files Browse the repository at this point in the history
…uration
  • Loading branch information
robbiet480 committed May 23, 2016
1 parent b3afb38 commit c96f73d
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions homeassistant/components/sensor/google_travel_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,12 @@ def __init__(self, name, api_key, origin, destination, options):
@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):
Expand Down

0 comments on commit c96f73d

Please sign in to comment.