mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 21:06:19 +00:00
Load/unload locative entities correctly between component and platform (#20498)
* Embed device_tracker in locative * Load/unload locative entities correctly between component and platform * Await the coroutine directly * Await the correct coroutine
This commit is contained in:
committed by
Fabian Affolter
parent
f575d1d3a6
commit
0c87fb421e
41
homeassistant/components/locative/device_tracker.py
Normal file
41
homeassistant/components/locative/device_tracker.py
Normal file
@@ -0,0 +1,41 @@
|
||||
"""
|
||||
Support for the Locative platform.
|
||||
|
||||
For more details about this platform, please refer to the documentation at
|
||||
https://home-assistant.io/components/device_tracker.locative/
|
||||
"""
|
||||
import logging
|
||||
|
||||
from homeassistant.components.device_tracker import \
|
||||
DOMAIN as DEVICE_TRACKER_DOMAIN
|
||||
from homeassistant.components.locative import DOMAIN as LOCATIVE_DOMAIN
|
||||
from homeassistant.components.locative import TRACKER_UPDATE
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
DEPENDENCIES = ['locative']
|
||||
|
||||
DATA_KEY = '{}.{}'.format(LOCATIVE_DOMAIN, DEVICE_TRACKER_DOMAIN)
|
||||
|
||||
|
||||
async def async_setup_entry(hass, entry, async_see):
|
||||
"""Configure a dispatcher connection based on a config entry."""
|
||||
async def _set_location(device, gps_location, location_name):
|
||||
"""Fire HA event to set location."""
|
||||
await async_see(
|
||||
dev_id=device,
|
||||
gps=gps_location,
|
||||
location_name=location_name
|
||||
)
|
||||
|
||||
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]()
|
||||
return True
|
||||
Reference in New Issue
Block a user