Add polling off all tracker each hours

master
Matthieu DUVAL 5 years ago
parent ecf2a23c70
commit 14300c5278

@ -1,5 +1,5 @@
# Georide Home assistant
![Logo Georide](./georide-logo.png)
![Logo Georide](/georide-logo.png)
⚠️ This is not an official implementation

@ -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 """

Loading…
Cancel
Save