Add tracker polling support

This commit is contained in:
2019-10-28 01:15:29 +01:00
parent f5f448dcc4
commit 7f64e7c7d7
3 changed files with 46 additions and 58 deletions

View File

@@ -52,8 +52,6 @@ async def async_setup(hass, config):
_LOGGER.info("Georide-setup ")
# Return boolean to indicate that initialization was successful.
return True
@@ -62,20 +60,14 @@ async def async_setup(hass, config):
async def async_setup_entry(hass, entry):
"""Set up Georide entry."""
def georide_update(event):
"""Update tracker info"""
nonlocal hass
_LOGGER.info('Georide update event %s', event)
georide_context = hass.data[DOMAIN]["context"]
token = georide_context.async_get_token()
trackers = GeorideApi.get_trackers(token)
georide_context.georide_trackers = trackers
hass.helpers.dispatcher.async_dispatcher_send(DOMAIN, hass, georide_context, json_response([]))
ha_event.async_track_time_interval(hass, georide_update, timedelta(seconds=30))
@@ -98,11 +90,12 @@ async def async_setup_entry(hass, entry):
account.auth_token
)
hass.data[DOMAIN]["context"] = context
# We add trackers to the context
trackers = GeorideApi.get_trackers(account.auth_token)
context.georide_trackers = trackers
hass.async_create_task(hass.config_entries.async_forward_entry_setup(entry, "device_tracker"))
hass.async_create_task(hass.config_entries.async_forward_entry_setup(entry, "switch"))
@@ -176,7 +169,6 @@ class GeorideContext:
return tracker
return None
@callback
def async_see(self, **data):
"""Send a see message to the device tracker."""