Add polling off all tracker each hours

This commit is contained in:
2019-11-07 21:40:09 +01:00
parent ecf2a23c70
commit 14300c5278
2 changed files with 12 additions and 7 deletions

View File

@@ -62,9 +62,6 @@ async def async_setup(hass, config):
)
)
# Return boolean to indicate that initialization was successful.
return True
@@ -88,8 +85,7 @@ async def async_setup_entry(hass, entry):
hass.data[DOMAIN]["context"] = context
# We add trackers to the context
trackers = GeorideApi.get_trackers(token)
context.georide_trackers = trackers
context.refresh_trackers()
hass.async_create_task(
hass.config_entries.async_forward_entry_setup(entry, "device_tracker"))
@@ -193,8 +189,11 @@ class GeorideContext:
def get_tracker(self, tracker_id):
""" here we return last tracker by id"""
if not self._thread_started:
_LOGGER.info("Satr the thread")
_LOGGER.info("Start the thread")
self._hass.async_add_executor_job(connect_socket, self)
# We refresh the tracker list each hours
ha_event.async_track_time_interval(
self._hass, self.refresh_trackers(), timedelta(hours=1))
self._thread_started = True
for tracker in self._georide_trackers:
@@ -202,6 +201,12 @@ class GeorideContext:
return tracker
return None
def refresh_trackers(self):
"""Used to refresh the tracker list"""
_LOGGER.info("Tracker list refresh")
self._georide_trackers = GeorideApi.get_trackers(self.get_token())
@property
def socket(self):
""" hold the georide socket """