Skip to content

Commit

Permalink
fix bugs in google travel time (home-assistant#2069)
Browse files Browse the repository at this point in the history
  • Loading branch information
Danielhiversen authored and robbiet480 committed May 14, 2016
1 parent 630b737 commit 8656bbb
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions homeassistant/components/sensor/google_travel_time.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
vol.Required(CONF_DESTINATION): vol.Coerce(str),
vol.Optional(CONF_TRAVEL_MODE):
vol.In(["driving", "walking", "bicycling", "transit"]),
vol.Optional(CONF_OPTIONS): vol.All(
vol.Optional(CONF_OPTIONS, default=dict()): vol.All(
dict, vol.Schema({
vol.Optional(CONF_MODE, default='driving'):
vol.In(["driving", "walking", "bicycling", "transit"]),
Expand Down Expand Up @@ -136,7 +136,11 @@ def __init__(self, name, api_key, origin, destination, options):
@property
def state(self):
"""Return the state of the sensor."""
return self._matrix['rows'][0]['elements'][0]['duration']['value']/60.0
try:
res = self._matrix['rows'][0]['elements'][0]['duration']['value']
return res/60.0
except KeyError:
return None

@property
def name(self):
Expand Down Expand Up @@ -175,15 +179,6 @@ def update(self):
if atime is not None and ':' in atime:
options_copy['arrival_time'] = convert_time_to_utc(atime)

departure_time = options_copy.get('departure_time')
arrival_time = options_copy.get('arrival_time')
if departure_time is not None and arrival_time is not None:
wstr = ("Google Travel Time: You can not provide both arrival "
"and departure times! Deleting the arrival time...")
_LOGGER.warning(wstr)
del options_copy['arrival_time']
del self._options['arrival_time']

self._matrix = self._client.distance_matrix(self._origin,
self._destination,
**options_copy)

0 comments on commit 8656bbb

Please sign in to comment.