mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 19:27:45 +00:00
If we have duration_in_traffic use that as the state, otherwise use duration
This commit is contained in:
parent
b3afb386b7
commit
c96f73d1be
@ -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):
|
||||
|
Loading…
x
Reference in New Issue
Block a user