Add travel time attribution/coordinates (#24956)

* add google travel time attribution

* add origin/destination

* update waze origin/destination

* add attribution and origin/destination

* add google attribution
This commit is contained in:
Leonardo Merza 2019-07-15 22:51:51 -04:00 committed by Martin Hjelmare
parent dcb12a992a
commit 64b9102206
2 changed files with 10 additions and 1 deletions

View File

@ -10,13 +10,15 @@ import homeassistant.util.dt as dt_util
from homeassistant.components.sensor import PLATFORM_SCHEMA from homeassistant.components.sensor import PLATFORM_SCHEMA
from homeassistant.const import ( from homeassistant.const import (
CONF_API_KEY, CONF_NAME, EVENT_HOMEASSISTANT_START, ATTR_LATITUDE, CONF_API_KEY, CONF_NAME, EVENT_HOMEASSISTANT_START, ATTR_LATITUDE,
ATTR_LONGITUDE, CONF_MODE) ATTR_LONGITUDE, ATTR_ATTRIBUTION, CONF_MODE)
from homeassistant.helpers import location from homeassistant.helpers import location
from homeassistant.helpers.entity import Entity from homeassistant.helpers.entity import Entity
from homeassistant.util import Throttle from homeassistant.util import Throttle
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
ATTRIBUTION = "Powered by Google"
CONF_DESTINATION = 'destination' CONF_DESTINATION = 'destination'
CONF_OPTIONS = 'options' CONF_OPTIONS = 'options'
CONF_ORIGIN = 'origin' CONF_ORIGIN = 'origin'
@ -181,6 +183,9 @@ class GoogleTravelTimeSensor(Entity):
res['duration'] = _data['duration']['text'] res['duration'] = _data['duration']['text']
if 'distance' in _data: if 'distance' in _data:
res['distance'] = _data['distance']['text'] res['distance'] = _data['distance']['text']
res['origin'] = self._origin
res['destination'] = self._destination
res[ATTR_ATTRIBUTION] = ATTRIBUTION
return res return res
@property @property

View File

@ -16,8 +16,10 @@ from homeassistant.helpers.entity import Entity
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
ATTR_DESTINATION = 'destination'
ATTR_DURATION = 'duration' ATTR_DURATION = 'duration'
ATTR_DISTANCE = 'distance' ATTR_DISTANCE = 'distance'
ATTR_ORIGIN = 'origin'
ATTR_ROUTE = 'route' ATTR_ROUTE = 'route'
ATTRIBUTION = "Powered by Waze" ATTRIBUTION = "Powered by Waze"
@ -147,6 +149,8 @@ class WazeTravelTime(Entity):
res[ATTR_DURATION] = self._waze_data.duration res[ATTR_DURATION] = self._waze_data.duration
res[ATTR_DISTANCE] = self._waze_data.distance res[ATTR_DISTANCE] = self._waze_data.distance
res[ATTR_ROUTE] = self._waze_data.route res[ATTR_ROUTE] = self._waze_data.route
res[ATTR_ORIGIN] = self._waze_data.origin
res[ATTR_DESTINATION] = self._waze_data.destination
return res return res
def _get_location_from_entity(self, entity_id): def _get_location_from_entity(self, entity_id):