forked from home-assistant/core
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Load/unload gpslogger entities correctly between component and platfo…
…rm (home-assistant#20448) * Embed device_tracker in gpslogger * Load/unload gpslogger entities correctly between component and platform * Await the coroutine directly
- Loading branch information
1 parent
0c87fb4
commit d179686
Showing
4 changed files
with
74 additions
and
39 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
""" | ||
Support for the GPSLogger platform. | ||
For more details about this platform, please refer to the documentation at | ||
https://home-assistant.io/components/device_tracker.gpslogger/ | ||
""" | ||
import logging | ||
|
||
from homeassistant.components.device_tracker import DOMAIN as \ | ||
DEVICE_TRACKER_DOMAIN | ||
from homeassistant.components.gpslogger import DOMAIN as GPSLOGGER_DOMAIN, \ | ||
TRACKER_UPDATE | ||
from homeassistant.helpers.dispatcher import async_dispatcher_connect | ||
from homeassistant.helpers.typing import HomeAssistantType | ||
|
||
_LOGGER = logging.getLogger(__name__) | ||
|
||
DEPENDENCIES = ['gpslogger'] | ||
|
||
DATA_KEY = '{}.{}'.format(GPSLOGGER_DOMAIN, DEVICE_TRACKER_DOMAIN) | ||
|
||
|
||
async def async_setup_entry(hass: HomeAssistantType, entry, async_see): | ||
"""Configure a dispatcher connection based on a config entry.""" | ||
async def _set_location(device, gps_location, battery, accuracy, attrs): | ||
"""Fire HA event to set location.""" | ||
await async_see( | ||
dev_id=device, | ||
gps=gps_location, | ||
battery=battery, | ||
gps_accuracy=accuracy, | ||
attributes=attrs | ||
) | ||
|
||
hass.data[DATA_KEY] = async_dispatcher_connect( | ||
hass, TRACKER_UPDATE, _set_location | ||
) | ||
return True | ||
|
||
|
||
async def async_unload_entry(hass: HomeAssistantType, entry): | ||
"""Unload the config entry and remove the dispatcher connection.""" | ||
hass.data[DATA_KEY]() | ||
return True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters