If we have duration_in_traffic use that as the state, otherwise use duration
This commit is contained in:
parent
b3afb386b7
commit
c96f73d1be
1 changed files with 6 additions and 5 deletions
|
@ -136,11 +136,12 @@ class GoogleTravelTimeSensor(Entity):
|
||||||
@property
|
@property
|
||||||
def state(self):
|
def state(self):
|
||||||
"""Return the state of the sensor."""
|
"""Return the state of the sensor."""
|
||||||
try:
|
_data = self._matrix['rows'][0]['elements'][0]
|
||||||
res = self._matrix['rows'][0]['elements'][0]['duration']['value']
|
if 'duration_in_traffic' in _data:
|
||||||
return round(res/60)
|
return round(_data['duration_in_traffic']['value']/60)
|
||||||
except KeyError:
|
if 'duration' in _data:
|
||||||
return None
|
return round(_data['duration']['value']/60)
|
||||||
|
return None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue