2016-10-02 06:00:01 +00:00
|
|
|
"""
|
2017-02-19 01:09:25 +00:00
|
|
|
Support for tracking a Volvo.
|
2016-10-02 06:00:01 +00:00
|
|
|
|
|
|
|
For more details about this platform, please refer to the documentation at
|
|
|
|
https://home-assistant.io/components/device_tracker.volvooncall/
|
|
|
|
"""
|
|
|
|
import logging
|
|
|
|
|
2016-10-09 16:15:58 +00:00
|
|
|
from homeassistant.util import slugify
|
2017-06-16 05:28:30 +00:00
|
|
|
from homeassistant.helpers.dispatcher import (
|
|
|
|
dispatcher_connect, dispatcher_send)
|
2017-07-24 14:45:02 +00:00
|
|
|
from homeassistant.components.volvooncall import DATA_KEY, SIGNAL_VEHICLE_SEEN
|
2016-10-02 06:00:01 +00:00
|
|
|
|
|
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
2017-02-07 19:47:11 +00:00
|
|
|
def setup_scanner(hass, config, see, discovery_info=None):
|
2017-04-30 05:04:49 +00:00
|
|
|
"""Set up the Volvo tracker."""
|
2017-02-19 01:09:25 +00:00
|
|
|
if discovery_info is None:
|
|
|
|
return
|
2016-10-02 06:00:01 +00:00
|
|
|
|
2017-02-22 22:39:59 +00:00
|
|
|
vin, _ = discovery_info
|
2017-09-05 16:10:01 +00:00
|
|
|
voc = hass.data[DATA_KEY]
|
|
|
|
vehicle = voc.vehicles[vin]
|
2016-11-18 22:12:51 +00:00
|
|
|
|
2017-02-19 01:09:25 +00:00
|
|
|
def see_vehicle(vehicle):
|
2017-04-30 05:04:49 +00:00
|
|
|
"""Handle the reporting of the vehicle position."""
|
2017-09-05 16:10:01 +00:00
|
|
|
host_name = voc.vehicle_name(vehicle)
|
2017-06-16 05:28:30 +00:00
|
|
|
dev_id = 'volvo_{}'.format(slugify(host_name))
|
2016-11-02 05:01:00 +00:00
|
|
|
see(dev_id=dev_id,
|
|
|
|
host_name=host_name,
|
2017-02-19 01:09:25 +00:00
|
|
|
gps=(vehicle.position['latitude'],
|
2017-06-16 05:28:30 +00:00
|
|
|
vehicle.position['longitude']),
|
|
|
|
icon='mdi:car')
|
2016-11-02 05:01:00 +00:00
|
|
|
|
2017-06-16 05:28:30 +00:00
|
|
|
dispatcher_connect(hass, SIGNAL_VEHICLE_SEEN, see_vehicle)
|
|
|
|
dispatcher_send(hass, SIGNAL_VEHICLE_SEEN, vehicle)
|
2016-10-02 06:00:01 +00:00
|
|
|
|
2017-02-19 01:09:25 +00:00
|
|
|
return True
|