Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| e5bd90ae6f | |||
| a2e65694fc | |||
| 66bd335a8e | |||
| 14300c5278 |
@@ -1,9 +1,8 @@
|
|||||||
# Georide Home assistant
|
# Georide Home assistant
|
||||||

|

|
||||||
|
|
||||||
⚠️ This is not an official implementation
|
⚠️ This is not an official implementation
|
||||||
|
[](https://github.com/custom-components/hacs)
|
||||||
[](https://github.com/custom-components/hacs)
|
|
||||||
[](https://www.gnu.org/licenses/gpl-3.0)
|
[](https://www.gnu.org/licenses/gpl-3.0)
|
||||||
|
|
||||||
Official GeoRide website: https://georide.fr/
|
Official GeoRide website: https://georide.fr/
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ from .const import (
|
|||||||
CONF_TOKEN,
|
CONF_TOKEN,
|
||||||
TRACKER_ID,
|
TRACKER_ID,
|
||||||
TOKEN_SAFE_DAY,
|
TOKEN_SAFE_DAY,
|
||||||
|
MIN_UNTIL_REFRESH,
|
||||||
DOMAIN
|
DOMAIN
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -62,9 +63,6 @@ async def async_setup(hass, config):
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Return boolean to indicate that initialization was successful.
|
# Return boolean to indicate that initialization was successful.
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@@ -88,8 +86,7 @@ async def async_setup_entry(hass, entry):
|
|||||||
hass.data[DOMAIN]["context"] = context
|
hass.data[DOMAIN]["context"] = context
|
||||||
|
|
||||||
# We add trackers to the context
|
# We add trackers to the context
|
||||||
trackers = GeorideApi.get_trackers(token)
|
context.refresh_trackers()
|
||||||
context.georide_trackers = trackers
|
|
||||||
|
|
||||||
hass.async_create_task(
|
hass.async_create_task(
|
||||||
hass.config_entries.async_forward_entry_setup(entry, "device_tracker"))
|
hass.config_entries.async_forward_entry_setup(entry, "device_tracker"))
|
||||||
@@ -141,7 +138,7 @@ class GeorideContext:
|
|||||||
self._token = token
|
self._token = token
|
||||||
self._socket = None
|
self._socket = None
|
||||||
self._thread_started = False
|
self._thread_started = False
|
||||||
|
self._previous_refresh = math.floor(time.time()/60)
|
||||||
@property
|
@property
|
||||||
def hass(self):
|
def hass(self):
|
||||||
""" hass """
|
""" hass """
|
||||||
@@ -178,7 +175,6 @@ class GeorideContext:
|
|||||||
exp_timestamp = jwt_data['exp']
|
exp_timestamp = jwt_data['exp']
|
||||||
|
|
||||||
epoch = math.ceil(time.time())
|
epoch = math.ceil(time.time())
|
||||||
|
|
||||||
if (exp_timestamp - TOKEN_SAFE_DAY) < epoch:
|
if (exp_timestamp - TOKEN_SAFE_DAY) < epoch:
|
||||||
_LOGGER.info("Time reached, renew token")
|
_LOGGER.info("Time reached, renew token")
|
||||||
account = GeorideApi.get_authorisation_token(self._email, self._password)
|
account = GeorideApi.get_authorisation_token(self._email, self._password)
|
||||||
@@ -192,9 +188,16 @@ class GeorideContext:
|
|||||||
|
|
||||||
def get_tracker(self, tracker_id):
|
def get_tracker(self, tracker_id):
|
||||||
""" here we return last tracker by 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()
|
||||||
|
|
||||||
if not self._thread_started:
|
if not self._thread_started:
|
||||||
_LOGGER.info("Satr the thread")
|
_LOGGER.info("Start the thread")
|
||||||
self._hass.async_add_executor_job(connect_socket, self)
|
self._hass.async_add_executor_job(connect_socket, self)
|
||||||
|
# We refresh the tracker list each hours
|
||||||
self._thread_started = True
|
self._thread_started = True
|
||||||
|
|
||||||
for tracker in self._georide_trackers:
|
for tracker in self._georide_trackers:
|
||||||
@@ -202,6 +205,12 @@ class GeorideContext:
|
|||||||
return tracker
|
return tracker
|
||||||
return None
|
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
|
@property
|
||||||
def socket(self):
|
def socket(self):
|
||||||
""" hold the georide socket """
|
""" hold the georide socket """
|
||||||
|
|||||||
@@ -8,4 +8,6 @@ CONF_TOKEN = "token"
|
|||||||
|
|
||||||
TRACKER_ID = "trackerId"
|
TRACKER_ID = "trackerId"
|
||||||
|
|
||||||
|
MIN_UNTIL_REFRESH = 10
|
||||||
|
|
||||||
TOKEN_SAFE_DAY = 432000 # five days
|
TOKEN_SAFE_DAY = 432000 # five days
|
||||||
|
|||||||
Reference in New Issue
Block a user