diff --git a/README.md b/README.md index 731dd5e..0bb6289 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # Georide Home assistant -![Logo Georide](./georide-logo.png) +![Logo Georide](/georide-logo.png) ⚠️ This is not an official implementation diff --git a/custom_components/georide/__init__.py b/custom_components/georide/__init__.py index 2ff357c..1b12b70 100644 --- a/custom_components/georide/__init__.py +++ b/custom_components/georide/__init__.py @@ -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 """