|
|
|
@ -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):
|
|
|
|
|