Compare commits
2 Commits
0.4.4
...
c9b4774c89
| Author | SHA1 | Date | |
|---|---|---|---|
| c9b4774c89 | |||
| a013277cf6 |
@@ -3,8 +3,6 @@
|
||||
|
||||
⚠️ this is not an official implementation
|
||||
|
||||
[](https://pypi.org/project/georideapilib/)
|
||||
|
||||
Official georide website: https://georide.fr/
|
||||
|
||||
This library can control your georide tracker tracker
|
||||
@@ -12,7 +10,7 @@ This library can control your georide tracker tracker
|
||||
|
||||
Some code have been taken from @alexmohr https://github.com/alexmohr/sonyapilib
|
||||
|
||||
This library is used as communication interface in a home assistant component to control media players, which can be found here: https://github.com/ptimatth/GeorideHA
|
||||
This library is used as communication interface in a home assistant component to control media players, which can be found here:(Not ready yet ;))
|
||||
|
||||
At the moment not all functions offered by the api are implemented. If you miss a function feel free to create a pull request or open a feature request.
|
||||
|
||||
@@ -30,4 +28,5 @@ This library has been tested with python 3.7 and above, functionality for older
|
||||
- https://github.com/ptimatth/pyGeoride
|
||||
|
||||
## Todo
|
||||
- [ ] Add support of SocketIO connection
|
||||
- [ ] Add support of "Get a shared trip" endpoint
|
||||
|
||||
@@ -4,92 +4,69 @@
|
||||
import time
|
||||
import datetime
|
||||
|
||||
logging.config.fileConfig('logging.conf')
|
||||
from georideapilib.objects import GeorideAccount
|
||||
import georideapilib.api as GeorideApi
|
||||
from georideapilib.socket import GeorideSocket
|
||||
|
||||
from threading import Thread
|
||||
|
||||
_LOGGER = logging.getLogger('example')
|
||||
|
||||
|
||||
def example():
|
||||
""" simple example function """
|
||||
# token = "<your_token>"# pylint: disable=C0301
|
||||
# account = GeorideAccount(0, "<your_email>", False, token)
|
||||
token = "<your_token>"# pylint: disable=C0301
|
||||
"""account = GeorideAccount(0, "<your_email>", False, token)"""
|
||||
|
||||
|
||||
account = GeorideApi.get_authorisation_token("<your_email>", "<your_password>")
|
||||
print("token 1: ", account.auth_token)
|
||||
_LOGGER.info("token 1: %s", account.auth_token)
|
||||
# pylint: disable=W0105
|
||||
|
||||
def locked_locked(data):
|
||||
_LOGGER.info("Locke received")
|
||||
|
||||
|
||||
def connect_socket(account):
|
||||
socket = GeorideSocket()
|
||||
socket.subscribe_locked(locked_locked)
|
||||
socket.init()
|
||||
socket.connect(account.auth_token)
|
||||
time.sleep(10)
|
||||
socket.disconnect()
|
||||
|
||||
thread = Thread(target=connect_socket, args=(account))
|
||||
thread.start()
|
||||
|
||||
"""
|
||||
account.auth_token = GeorideApi.renewToken(account.auth_token)
|
||||
account.auth_token = GeorideApi.renew_token(account.auth_token)
|
||||
print("token 2: ", account.auth_token)
|
||||
""" # pylint: disable=W0105
|
||||
|
||||
user = GeorideApi.get_user(account.auth_token)
|
||||
_LOGGER.info("User: %s", user.first_name)
|
||||
print("User: ", user.first_name)
|
||||
|
||||
trackers = GeorideApi.get_trackers(account.auth_token)
|
||||
tracker = trackers[0]
|
||||
_LOGGER.info("Tracker name: %s", tracker.tracker_name)
|
||||
print("Tracker name: ", tracker.tracker_name)
|
||||
|
||||
trips = GeorideApi.get_trips(account.auth_token, tracker.tracker_id, "2019-10-10", "2019-10-24")
|
||||
trip = trips[0]
|
||||
trip_date = datetime.datetime.strptime("2019-10-10T06:45:34.000Z", '%Y-%m-%dT%H:%M:%S.%fZ')
|
||||
_LOGGER.info("Trip date: %s, from: %s, to: %s", trip_date, trip.nice_start_address,
|
||||
trip.nice_end_address)
|
||||
print("Trip date: {}, from: {}, to: {}".format(trip_date, trip.nice_start_address,
|
||||
trip.nice_end_address))
|
||||
|
||||
positions = GeorideApi.get_positions(account.auth_token, tracker.tracker_id,
|
||||
"2019-10-10", "2019-10-24")
|
||||
position = positions[0]
|
||||
_LOGGER.info("Position speed: %s, lon: %s, lat: %s", position.speed, position.longitude,
|
||||
position.latitude)
|
||||
print("Position speed: {}, lon: {}, lat: {}".format(position.speed, position.longitude,
|
||||
position.latitude))
|
||||
|
||||
|
||||
trip_shared = GeorideApi.share_a_trip_by_date(account.auth_token, tracker.tracker_id,
|
||||
"2019-10-10", "2019-10-24")
|
||||
_LOGGER.info("tripShared url: %s, id: %s", trip_shared.url, trip_shared.share_id)
|
||||
print("tripShared url: {}, id: {}".format(trip_shared.url, trip_shared.share_id))
|
||||
|
||||
time.sleep(10)
|
||||
have_been_locked = GeorideApi.lock_tracker(account.auth_token, tracker.tracker_id)
|
||||
_LOGGER.info("Tracker have been locked: %s", have_been_locked)
|
||||
print("Tracker have been locked: ", have_been_locked)
|
||||
|
||||
time.sleep(10)
|
||||
have_been_unlocked = GeorideApi.unlock_tracker(account.auth_token, tracker.tracker_id)
|
||||
_LOGGER.info("Tracker have been unlocked: %s", have_been_unlocked)
|
||||
print("Tracker have been unlocked: ", have_been_unlocked)
|
||||
|
||||
time.sleep(10)
|
||||
is_locked = GeorideApi.toogle_lock_tracker(account.auth_token, tracker.tracker_id)
|
||||
_LOGGER.info("Tracker is locked: %s", is_locked)
|
||||
print("Tracker is locked: ", is_locked)
|
||||
|
||||
time.sleep(10)
|
||||
trackers = GeorideApi.get_trackers(account.auth_token)
|
||||
tracker = trackers[0]
|
||||
_LOGGER.info("Tracker name: %s is locked: %s", tracker.tracker_name, tracker.is_locked)
|
||||
|
||||
|
||||
|
||||
print("Tracker name: ", tracker.tracker_name, " is locked: ", tracker.is_locked)
|
||||
|
||||
"""
|
||||
GeorideApi.revokeToken(account.auth_token)
|
||||
""" # pylint: disable=W0105
|
||||
|
||||
example()
|
||||
|
||||
@@ -53,12 +53,11 @@ def get_authorisation_token(email, password):
|
||||
response_data = response.json()
|
||||
account = GeorideAccount.from_json(response_data)
|
||||
elif response.status_code == 403:
|
||||
_LOGGER.warning("Login failed")
|
||||
raise LoginException(get_authorisation_token, "Login failed")
|
||||
_LOGGER.warnning("Login failed")
|
||||
raise LoginException("Login failed")
|
||||
else:
|
||||
_LOGGER.error("Georide login, http error code: %s", response.status_code)
|
||||
raise SeverException(get_authorisation_token,
|
||||
"Georide login, http error code: {}".format(response.status_code))
|
||||
raise SeverException("Georide login, http error code: {}".format(response.status_code))
|
||||
return account
|
||||
|
||||
|
||||
@@ -74,11 +73,10 @@ def renew_token(token):
|
||||
new_token = response_data['authToken']
|
||||
elif response.status_code == 401:
|
||||
_LOGGER.warnning("Renew token refused")
|
||||
raise UnauthorizedException(renew_token, "Renew token refused")
|
||||
raise UnauthorizedException("Renew token refused")
|
||||
else:
|
||||
_LOGGER.error("Georide login, http error code: %s", response.status_code)
|
||||
raise SeverException(renew_token,
|
||||
"Georide login, http error code: {}".format(response.status_code))
|
||||
raise SeverException("Georide login, http error code: {}".format(response.status_code))
|
||||
return new_token
|
||||
|
||||
def revoke_token(token):
|
||||
@@ -89,7 +87,7 @@ def revoke_token(token):
|
||||
headers=headers)
|
||||
if response.status_code == 401:
|
||||
_LOGGER.warnning("Token allready revoked")
|
||||
raise UnauthorizedException(revoke_token, "Token allready revoked")
|
||||
raise UnauthorizedException("Token allready revoked")
|
||||
if response.status_code == 401:
|
||||
_LOGGER.warnning("Token allready revoked")
|
||||
return False
|
||||
|
||||
@@ -297,11 +297,6 @@ class GeorideTracker: # pylint: disable=R0904,R0902
|
||||
""" fixtime """
|
||||
return self._fixtime
|
||||
|
||||
@fixtime.setter
|
||||
def fixtime(self, fixtime):
|
||||
""" fixtime """
|
||||
self._fixtime = fixtime
|
||||
|
||||
@property
|
||||
def role(self):
|
||||
""" role """
|
||||
@@ -352,21 +347,11 @@ class GeorideTracker: # pylint: disable=R0904,R0902
|
||||
""" speed """
|
||||
return self._speed
|
||||
|
||||
@speed.setter
|
||||
def speed(self, speed):
|
||||
""" speed """
|
||||
self._speed = speed
|
||||
|
||||
@property
|
||||
def moving(self):
|
||||
""" moving """
|
||||
return self._moving
|
||||
|
||||
@moving.setter
|
||||
def moving(self, moving):
|
||||
""" moving """
|
||||
self._moving = moving
|
||||
|
||||
@property
|
||||
def position_id(self):
|
||||
""" position_id """
|
||||
@@ -377,21 +362,11 @@ class GeorideTracker: # pylint: disable=R0904,R0902
|
||||
""" latitude """
|
||||
return self._latitude
|
||||
|
||||
@latitude.setter
|
||||
def latitude(self, latitude):
|
||||
""" latitude """
|
||||
self._latitude = latitude
|
||||
|
||||
@property
|
||||
def longitude(self):
|
||||
""" longitude """
|
||||
return self._longitude
|
||||
|
||||
@longitude.setter
|
||||
def longitude(self, longitude):
|
||||
""" longitude """
|
||||
self._longitude = longitude
|
||||
|
||||
@property
|
||||
def altitude(self):
|
||||
""" altitude """
|
||||
@@ -407,31 +382,16 @@ class GeorideTracker: # pylint: disable=R0904,R0902
|
||||
""" locked_latitude """
|
||||
return self._locked_latitude
|
||||
|
||||
@locked_latitude.setter
|
||||
def locked_latitude(self, locked_latitude):
|
||||
""" locked_latitude """
|
||||
self._locked_latitude = locked_latitude
|
||||
|
||||
@property
|
||||
def locked_longitude(self):
|
||||
""" locked_longitude """
|
||||
return self._locked_longitude
|
||||
|
||||
@locked_longitude.setter
|
||||
def locked_longitude(self, locked_longitude):
|
||||
""" locked_longitude """
|
||||
self._locked_longitude = locked_longitude
|
||||
|
||||
|
||||
@property
|
||||
def is_locked(self):
|
||||
""" is_locked """
|
||||
return self._is_locked
|
||||
|
||||
@is_locked.setter
|
||||
def is_locked(self, is_locked):
|
||||
""" is_locked """
|
||||
self._is_locked = is_locked
|
||||
|
||||
@property
|
||||
def can_see_position(self):
|
||||
""" can_see_position """
|
||||
@@ -482,11 +442,6 @@ class GeorideTracker: # pylint: disable=R0904,R0902
|
||||
""" status """
|
||||
return self._status
|
||||
|
||||
@status.setter
|
||||
def status(self, status):
|
||||
""" status """
|
||||
self._status = status
|
||||
|
||||
@staticmethod
|
||||
def from_json(json):
|
||||
"""return new object fromjson"""
|
||||
|
||||
@@ -5,8 +5,12 @@ import socketio
|
||||
from georideapilib.api import GEORIDE_API_HOST
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
_LOGGER.setLevel(logging.DEBUG)
|
||||
# create console handler and set level to debug
|
||||
CH = logging.StreamHandler()
|
||||
CH.setLevel(logging.DEBUG)
|
||||
|
||||
sio = socketio.Client(reconnection=True) # pylint: disable=C0103
|
||||
sio = socketio.Client(reconnection=True)
|
||||
|
||||
@sio.on('connect')
|
||||
def on_connect():
|
||||
@@ -61,48 +65,50 @@ class GeorideSocket():
|
||||
@sio.on('message')
|
||||
def on_message(data):
|
||||
""" on_message """
|
||||
_LOGGER.debug('Message received: %s', data)
|
||||
_LOGGER.debug('Message recieved: %s', data)
|
||||
if self._on_message_callback is not None:
|
||||
self._on_message_callback(data)
|
||||
self._on_message_callback()
|
||||
|
||||
@sio.on('device')
|
||||
def on_device(data):
|
||||
""" on_device """
|
||||
_LOGGER.debug('Device received: %s', data)
|
||||
_LOGGER.debug('Device recieved: %s', data)
|
||||
if self._on_device_callback is not None:
|
||||
self._on_device_callback(data)
|
||||
self._on_device_callback()
|
||||
|
||||
@sio.on('position')
|
||||
def on_position(data):
|
||||
""" on_position """
|
||||
_LOGGER.debug('Position received:%s', data)
|
||||
_LOGGER.debug('Position recieved:%s', data)
|
||||
if self._on_position_callback is not None:
|
||||
self._on_position_callback(data)
|
||||
self._on_position_callback()
|
||||
|
||||
@sio.on('alarm')
|
||||
def on_alarm(data):
|
||||
""" on_alarm """
|
||||
_LOGGER.debug('Alarm received: %s', data)
|
||||
_LOGGER.debug('Alarm recieved: %s', data)
|
||||
if self._on_alarm_callback is not None:
|
||||
self._on_alarm_callback(data)
|
||||
|
||||
@sio.on('refreshTrackersInstruction')
|
||||
def on_refresh_tracker():
|
||||
""" on_refresh_tracker """
|
||||
_LOGGER.debug('Refresh tracker received')
|
||||
_LOGGER.debug('Refresh tracker recieved')
|
||||
if self._on_refresh_tracker_callback is not None:
|
||||
self._on_refresh_tracker_callback()
|
||||
|
||||
@sio.on('lockedPosition')
|
||||
def on_locked(data):
|
||||
""" on_locked """
|
||||
_LOGGER.debug('Locked received: %s', data)
|
||||
_LOGGER.debug('Locked recieved: %s', data)
|
||||
if self._on_locked_callback is not None:
|
||||
self._on_locked_callback(data)
|
||||
self._on_locked_callback()
|
||||
|
||||
self._initialised = True
|
||||
|
||||
def connect(self, auth_token):
|
||||
""" connect to the georide socket"""
|
||||
_LOGGER.info("Start conection")
|
||||
if self._initialised is not False:
|
||||
sio.connect(GEORIDE_API_HOST, headers={'token': auth_token})
|
||||
sio.wait()
|
||||
|
||||
29
logging.conf
29
logging.conf
@@ -1,29 +0,0 @@
|
||||
[loggers]
|
||||
keys=root,example
|
||||
|
||||
[handlers]
|
||||
keys=consoleHandler
|
||||
|
||||
[formatters]
|
||||
keys=simpleFormatter
|
||||
|
||||
[logger_root]
|
||||
level=DEBUG
|
||||
handlers=consoleHandler
|
||||
|
||||
[logger_example]
|
||||
level=DEBUG
|
||||
handlers=consoleHandler
|
||||
qualname=simpleExample
|
||||
propagate=0
|
||||
|
||||
|
||||
[handler_consoleHandler]
|
||||
class=StreamHandler
|
||||
level=DEBUG
|
||||
formatter=simpleFormatter
|
||||
args=(sys.stdout,)
|
||||
|
||||
[formatter_simpleFormatter]
|
||||
format=%(asctime)s - %(name)s - %(levelname)s - %(message)s
|
||||
datefmt=
|
||||
2
setup.py
2
setup.py
@@ -19,7 +19,7 @@ CURRENT_DIR = os.path.dirname(__file__)
|
||||
setup(
|
||||
name='georideapilib',
|
||||
packages=['georideapilib'], # this must be the same as the name above
|
||||
version='0.4.4',
|
||||
version='0.3.0',
|
||||
description='Lib to control georide tracker devices with their rest api',
|
||||
author='Matthieu DUVAL',
|
||||
author_email='georideapilib@duval-dev.fr',
|
||||
|
||||
Reference in New Issue
Block a user