2019-04-03 15:40:03 +00:00
|
|
|
"""Support for the Locative platform."""
|
2015-12-23 10:52:52 +00:00
|
|
|
import logging
|
|
|
|
|
2019-03-21 05:56:46 +00:00
|
|
|
from homeassistant.components.device_tracker import (
|
|
|
|
DOMAIN as DEVICE_TRACKER_DOMAIN)
|
2019-01-11 23:14:11 +00:00
|
|
|
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
2019-02-06 17:50:48 +00:00
|
|
|
from homeassistant.util import slugify
|
2015-10-11 22:14:05 +00:00
|
|
|
|
2019-03-21 05:56:46 +00:00
|
|
|
from . import DOMAIN as LOCATIVE_DOMAIN, TRACKER_UPDATE
|
|
|
|
|
2015-12-23 10:52:52 +00:00
|
|
|
_LOGGER = logging.getLogger(__name__)
|
2015-10-11 22:14:05 +00:00
|
|
|
|
2019-01-27 22:43:16 +00:00
|
|
|
DATA_KEY = '{}.{}'.format(LOCATIVE_DOMAIN, DEVICE_TRACKER_DOMAIN)
|
2015-10-11 22:14:05 +00:00
|
|
|
|
2019-01-27 22:43:16 +00:00
|
|
|
|
|
|
|
async def async_setup_entry(hass, entry, async_see):
|
|
|
|
"""Configure a dispatcher connection based on a config entry."""
|
2019-01-11 23:14:11 +00:00
|
|
|
async def _set_location(device, gps_location, location_name):
|
|
|
|
"""Fire HA event to set location."""
|
|
|
|
await async_see(
|
2019-02-06 17:50:48 +00:00
|
|
|
dev_id=slugify(device),
|
2019-01-11 23:14:11 +00:00
|
|
|
gps=gps_location,
|
|
|
|
location_name=location_name
|
|
|
|
)
|
2015-10-11 22:14:05 +00:00
|
|
|
|
2019-01-27 22:43:16 +00:00
|
|
|
hass.data[DATA_KEY] = async_dispatcher_connect(
|
|
|
|
hass, TRACKER_UPDATE, _set_location
|
|
|
|
)
|
|
|
|
return True
|
|
|
|
|
|
|
|
|
|
|
|
async def async_unload_entry(hass, entry):
|
|
|
|
"""Unload the config entry and remove the dispatcher connection."""
|
|
|
|
hass.data[DATA_KEY]()
|
2015-10-11 22:14:05 +00:00
|
|
|
return True
|