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-02-19 01:09:25 +00:00
|
|
|
from homeassistant.components.volvooncall import DOMAIN
|
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-02-19 01:09:25 +00:00
|
|
|
vehicle = hass.data[DOMAIN].vehicles[vin]
|
2016-11-02 05:01:00 +00:00
|
|
|
|
2017-02-19 01:09:25 +00:00
|
|
|
host_name = vehicle.registration_number
|
|
|
|
dev_id = 'volvo_' + slugify(host_name)
|
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."""
|
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'],
|
|
|
|
vehicle.position['longitude']))
|
2016-11-02 05:01:00 +00:00
|
|
|
|
2017-02-19 01:09:25 +00:00
|
|
|
hass.data[DOMAIN].entities[vin].append(see_vehicle)
|
2017-02-22 08:24:42 +00:00
|
|
|
see_vehicle(vehicle)
|
2016-10-02 06:00:01 +00:00
|
|
|
|
2017-02-19 01:09:25 +00:00
|
|
|
return True
|