diff --git a/custom_components/georide/__init__.py b/custom_components/georide/__init__.py index dcb5acb..2de6c79 100644 --- a/custom_components/georide/__init__.py +++ b/custom_components/georide/__init__.py @@ -85,7 +85,7 @@ async def async_setup_entry(hass, entry): hass.data[DOMAIN]["context"] = context # We add trackers to the context - context.refresh_trackers() + await context.refresh_trackers() hass.async_create_task( hass.config_entries.async_forward_entry_setup(entry, "device_tracker")) @@ -187,13 +187,13 @@ class GeoRideContext: _LOGGER.info("Token exp data: %s", exp_timestamp) return self._token - def get_tracker(self, tracker_id): + async def get_tracker(self, tracker_id): """ here we return last tracker by id""" epoch_min = math.floor(time.time()/60) if (epoch_min % MIN_UNTIL_REFRESH) == 0: if epoch_min != self._previous_refresh: self._previous_refresh = epoch_min - self.refresh_trackers() + await self.refresh_trackers() if not self._thread_started: _LOGGER.info("Start the thread") @@ -206,10 +206,10 @@ class GeoRideContext: return tracker return None - def refresh_trackers(self): + async def refresh_trackers(self): """Used to refresh the tracker list""" _LOGGER.info("Tracker list refresh") - self._georide_trackers = GeoRideApi.get_trackers(self.get_token()) + self._georide_trackers = await GeoRideApi.get_trackers(await self.get_token()) @property def socket(self): diff --git a/custom_components/georide/binary_sensor.py b/custom_components/georide/binary_sensor.py index fa6b025..e4977ad 100644 --- a/custom_components/georide/binary_sensor.py +++ b/custom_components/georide/binary_sensor.py @@ -19,7 +19,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities): # pylint: d if token is None: return False - trackers = GeoRideApi.get_trackers(token) + trackers = await GeoRideApi.get_trackers(token) binary_sensor_entities = [] for tracker in trackers: diff --git a/custom_components/georide/device_tracker.py b/custom_components/georide/device_tracker.py index edbd38c..e3590e9 100644 --- a/custom_components/georide/device_tracker.py +++ b/custom_components/georide/device_tracker.py @@ -23,7 +23,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities): # pylint: d _LOGGER.debug('Current GeoRide token: %s', token) - trackers = GeoRideApi.get_trackers(token) + trackers = await GeoRideApi.get_trackers(token) tracker_entities = [] diff --git a/custom_components/georide/sensor.py b/custom_components/georide/sensor.py index ffb4344..dce133e 100644 --- a/custom_components/georide/sensor.py +++ b/custom_components/georide/sensor.py @@ -21,7 +21,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities): # pylint: d if token is None: return False - trackers = GeoRideApi.get_trackers(token) + trackers = await GeoRideApi.get_trackers(token) odometer_switch_entities = [] for tracker in trackers: