Compare commits
14 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 02e1656aab | |||
| 4593c694d5 | |||
| 9b651f933e | |||
| a8274f7fd1 | |||
| ef783db79b | |||
| 18de851e4d | |||
|
|
cbed2cebb3 | ||
| e5bd90ae6f | |||
| a2e65694fc | |||
| 66bd335a8e | |||
| 14300c5278 | |||
| bc3da8f0e5 | |||
| ecf2a23c70 | |||
| 991370fcec |
@@ -1,9 +1,8 @@
|
||||
# Georide Home assistant
|
||||

|
||||
# GeoRide Home assistant
|
||||

|
||||
|
||||
⚠️ 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)
|
||||
|
||||
Official GeoRide website: https://georide.fr/
|
||||
|
||||
@@ -11,11 +11,10 @@ import voluptuous as vol
|
||||
import jwt
|
||||
|
||||
from aiohttp.web import json_response
|
||||
from georideapilib.objects import GeorideAccount
|
||||
import georideapilib.api as GeorideApi
|
||||
|
||||
from georideapilib.socket import GeorideSocket
|
||||
from georideapilib.objects import GeorideAccount as GeoRideAccount
|
||||
import georideapilib.api as GeoRideApi
|
||||
|
||||
from georideapilib.socket import GeorideSocket as GeoRideSocket
|
||||
|
||||
from homeassistant import config_entries
|
||||
from homeassistant.const import CONF_WEBHOOK_ID
|
||||
@@ -31,6 +30,7 @@ from .const import (
|
||||
CONF_TOKEN,
|
||||
TRACKER_ID,
|
||||
TOKEN_SAFE_DAY,
|
||||
MIN_UNTIL_REFRESH,
|
||||
DOMAIN
|
||||
)
|
||||
|
||||
@@ -50,7 +50,7 @@ CONFIG_SCHEMA = vol.Schema(
|
||||
|
||||
|
||||
async def async_setup(hass, config):
|
||||
"""Setup Georide component."""
|
||||
"""Setup GeoRide component."""
|
||||
hass.data[DOMAIN] = {"config": config[DOMAIN], "devices": {}, "unsub": None}
|
||||
hass.async_create_task(
|
||||
hass.config_entries.flow.async_init(
|
||||
@@ -66,40 +66,26 @@ async def async_setup(hass, config):
|
||||
return True
|
||||
|
||||
|
||||
def connect_socket(hass, component):
|
||||
"""subscribe to georide socket"""
|
||||
context = hass.data[DOMAIN]["context"]
|
||||
|
||||
socket = GeorideSocket()
|
||||
socket.subscribe_locked(context.on_lock_callback)
|
||||
socket.subscribe_device(context.on_device_callback)
|
||||
socket.subscribe_position(context.on_position_callback)
|
||||
|
||||
context.socket = socket
|
||||
|
||||
socket.init()
|
||||
socket.connect(context.async_get_token())
|
||||
|
||||
|
||||
async def async_setup_entry(hass, entry):
|
||||
"""Set up Georide entry."""
|
||||
"""Set up GeoRide entry."""
|
||||
config = hass.data[DOMAIN]["config"]
|
||||
email = config.get(CONF_EMAIL) or entry.data[CONF_EMAIL]
|
||||
password = config.get(CONF_PASSWORD) or entry.data[CONF_PASSWORD]
|
||||
token = config.get(CONF_TOKEN) or entry.data[CONF_TOKEN]
|
||||
context = GeorideContext(
|
||||
context = GeoRideContext(
|
||||
hass,
|
||||
email,
|
||||
password,
|
||||
token
|
||||
)
|
||||
|
||||
_LOGGER.info("Context-setup and start the thread")
|
||||
_LOGGER.info("Thread started")
|
||||
|
||||
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"))
|
||||
@@ -108,14 +94,11 @@ async def async_setup_entry(hass, entry):
|
||||
hass.async_create_task(
|
||||
hass.config_entries.async_forward_entry_setup(entry, "sensor"))
|
||||
|
||||
thread = Thread(target=connect_socket, args=(hass, entry))
|
||||
thread.start()
|
||||
|
||||
|
||||
return True
|
||||
|
||||
|
||||
async def async_unload_entry(hass, entry):
|
||||
"""Unload an Georide config entry."""
|
||||
"""Unload an GeoRide config entry."""
|
||||
|
||||
await hass.config_entries.async_forward_entry_unload(entry, "device_tracker")
|
||||
await hass.config_entries.async_forward_entry_unload(entry, "switch")
|
||||
@@ -128,19 +111,33 @@ async def async_unload_entry(hass, entry):
|
||||
|
||||
return True
|
||||
|
||||
def connect_socket(context):
|
||||
"""subscribe to GeoRide socket"""
|
||||
_LOGGER.info("GeoRide socket connexion")
|
||||
socket = GeoRideSocket()
|
||||
socket.subscribe_locked(context.on_lock_callback)
|
||||
socket.subscribe_device(context.on_device_callback)
|
||||
socket.subscribe_position(context.on_position_callback)
|
||||
|
||||
class GeorideContext:
|
||||
"""Hold the current Georide context."""
|
||||
context.socket = socket
|
||||
|
||||
socket.init()
|
||||
socket.connect(context.get_token())
|
||||
|
||||
|
||||
class GeoRideContext:
|
||||
"""Hold the current GeoRide context."""
|
||||
|
||||
def __init__(self, hass, email, password, token):
|
||||
"""Initialize an Georide context."""
|
||||
"""Initialize an GeoRide context."""
|
||||
self._hass = hass
|
||||
self._email = email
|
||||
self._password = password
|
||||
self._georide_trackers = defaultdict(set)
|
||||
self._token = token
|
||||
self._socket = None
|
||||
|
||||
self._thread_started = False
|
||||
self._previous_refresh = math.floor(time.time()/60)
|
||||
@property
|
||||
def hass(self):
|
||||
""" hass """
|
||||
@@ -163,12 +160,12 @@ class GeorideContext:
|
||||
|
||||
@property
|
||||
def georide_trackers(self):
|
||||
""" georide tracker list """
|
||||
""" GeoRide tracker list """
|
||||
return self._georide_trackers
|
||||
|
||||
@georide_trackers.setter
|
||||
def georide_trackers(self, trackers):
|
||||
""" georide tracker list """
|
||||
""" GeoRide tracker list """
|
||||
self._georide_trackers = trackers
|
||||
|
||||
def get_token(self):
|
||||
@@ -177,10 +174,9 @@ class GeorideContext:
|
||||
exp_timestamp = jwt_data['exp']
|
||||
|
||||
epoch = math.ceil(time.time())
|
||||
|
||||
if (exp_timestamp - TOKEN_SAFE_DAY) < epoch:
|
||||
_LOGGER.info("Time reached, renew token")
|
||||
account = GeorideApi.get_authorisation_token(self._email, self._password)
|
||||
account = GeoRideApi.get_authorisation_token(self._email, self._password)
|
||||
config = self._hass.data[DOMAIN]["config"]
|
||||
config[CONF_TOKEN] = account.auth_token
|
||||
self._token = account.auth_token
|
||||
@@ -191,22 +187,39 @@ class GeorideContext:
|
||||
|
||||
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()
|
||||
|
||||
if not self._thread_started:
|
||||
_LOGGER.info("Start the thread")
|
||||
self._hass.async_add_executor_job(connect_socket, self)
|
||||
# We refresh the tracker list each hours
|
||||
self._thread_started = True
|
||||
|
||||
for tracker in self._georide_trackers:
|
||||
if tracker.tracker_id == tracker_id:
|
||||
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 """
|
||||
""" hold the GeoRide socket """
|
||||
return self._socket
|
||||
|
||||
@socket.setter
|
||||
def socket(self, socket):
|
||||
"""set the georide socket"""
|
||||
"""set the GeoRide socket"""
|
||||
self._socket = socket
|
||||
|
||||
|
||||
@callback
|
||||
def on_lock_callback(self, data):
|
||||
"""on lock callback"""
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
import logging
|
||||
from homeassistant import config_entries
|
||||
import voluptuous as vol
|
||||
import georideapilib.api as GeorideApi
|
||||
import georideapilib.exception as GeorideException
|
||||
import georideapilib.api as GeoRideApi
|
||||
import georideapilib.exception as GeoRideException
|
||||
|
||||
|
||||
from .const import CONF_EMAIL, CONF_PASSWORD, CONF_TOKEN
|
||||
@@ -13,11 +13,11 @@ from .const import CONF_EMAIL, CONF_PASSWORD, CONF_TOKEN
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
@config_entries.HANDLERS.register("georide")
|
||||
class GeorideConfigFlow(config_entries.ConfigFlow):
|
||||
"""Georide config flow """
|
||||
class GeoRideConfigFlow(config_entries.ConfigFlow):
|
||||
"""GeoRide config flow """
|
||||
|
||||
async def async_step_user(self, user_input=None): #pylint: disable=W0613
|
||||
""" handle info to help to configure georide """
|
||||
""" handle info to help to configure GeoRide """
|
||||
|
||||
if self._async_current_entries():
|
||||
return self.async_abort(reason="one_instance_allowed")
|
||||
@@ -41,27 +41,32 @@ class GeorideConfigFlow(config_entries.ConfigFlow):
|
||||
|
||||
async def async_step_georide_login(self, user_input):
|
||||
""" try to seupt GeoRide Account """
|
||||
errors = {}
|
||||
|
||||
schema = vol.Schema({
|
||||
vol.Required(CONF_EMAIL): vol.All(str, vol.Length(min=3)),
|
||||
vol.Required(CONF_PASSWORD): vol.All(str)
|
||||
})
|
||||
|
||||
if user_input is None:
|
||||
return self.async_show_form(step_id='georide_login', data_schema=schema)
|
||||
|
||||
email = user_input[CONF_EMAIL]
|
||||
password = user_input[CONF_PASSWORD]
|
||||
|
||||
try:
|
||||
account = GeorideApi.get_authorisation_token(
|
||||
user_input[CONF_EMAIL],
|
||||
user_input[CONF_PASSWORD])
|
||||
return self.async_create_entry(
|
||||
title=user_input[CONF_EMAIL],
|
||||
data={
|
||||
CONF_EMAIL: user_input[CONF_EMAIL],
|
||||
CONF_PASSWORD: user_input[CONF_PASSWORD],
|
||||
CONF_TOKEN: account.auth_token
|
||||
}
|
||||
)
|
||||
except (GeorideException.SeverException, GeorideException.LoginException):
|
||||
account = GeoRideApi.get_authorisation_token(email, password)
|
||||
data = {
|
||||
CONF_EMAIL: email,
|
||||
CONF_PASSWORD: password,
|
||||
CONF_TOKEN: account.auth_token
|
||||
}
|
||||
return self.async_create_entry(title=email, data=data)
|
||||
except (GeoRideException.SeverException, GeoRideException.LoginException):
|
||||
_LOGGER.error("Invalid credentials provided, config not created")
|
||||
errors["base"] = "faulty_credentials"
|
||||
return self.async_show_form(step_id="georide_login", errors=errors)
|
||||
errors = {"base": "faulty_credentials"}
|
||||
return self.async_show_form(step_id="georide_login", data_schema=schema, errors=errors)
|
||||
except:
|
||||
_LOGGER.error("Unknown error")
|
||||
errors["base"] = "faulty_credentials"
|
||||
return self.async_show_form(step_id="georide_login", errors=errors)
|
||||
|
||||
|
||||
errors = {"base": "unkonwn"}
|
||||
return self.async_show_form(step_id="georide_login", data_schema=schema, errors=errors)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
""" Georide const file """
|
||||
""" GeoRide const file """
|
||||
DOMAIN = "georide"
|
||||
|
||||
CONF_EMAIL = "email"
|
||||
@@ -8,4 +8,6 @@ CONF_TOKEN = "token"
|
||||
|
||||
TRACKER_ID = "trackerId"
|
||||
|
||||
MIN_UNTIL_REFRESH = 10
|
||||
|
||||
TOKEN_SAFE_DAY = 432000 # five days
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
""" device tracker for Georide object """
|
||||
""" device tracker for GeoRide object """
|
||||
|
||||
import logging
|
||||
|
||||
from homeassistant.components.device_tracker.const import ENTITY_ID_FORMAT, SOURCE_TYPE_GPS
|
||||
from homeassistant.components.device_tracker.const import DOMAIN, SOURCE_TYPE_GPS
|
||||
from homeassistant.components.device_tracker.config_entry import TrackerEntity
|
||||
|
||||
import georideapilib.api as GeorideApi
|
||||
import georideapilib.api as GeoRideApi
|
||||
|
||||
from .const import DOMAIN as GEORIDE_DOMAIN
|
||||
|
||||
@@ -20,15 +20,15 @@ async def async_setup_entry(hass, config_entry, async_add_entities): # pylint: d
|
||||
if georide_context.get_token() is None:
|
||||
return False
|
||||
|
||||
_LOGGER.info('Current georide token: %s', georide_context.get_token())
|
||||
_LOGGER.debug('Current GeoRide token: %s', georide_context.get_token())
|
||||
|
||||
|
||||
trackers = GeorideApi.get_trackers(georide_context.get_token())
|
||||
trackers = GeoRideApi.get_trackers(georide_context.get_token())
|
||||
|
||||
|
||||
tracker_entities = []
|
||||
for tracker in trackers:
|
||||
entity = GeorideTrackerEntity(tracker.tracker_id, georide_context.get_token,
|
||||
entity = GeoRideTrackerEntity(tracker.tracker_id, georide_context.get_token,
|
||||
georide_context.get_tracker, tracker)
|
||||
|
||||
|
||||
@@ -40,17 +40,17 @@ async def async_setup_entry(hass, config_entry, async_add_entities): # pylint: d
|
||||
return True
|
||||
|
||||
|
||||
class GeorideTrackerEntity(TrackerEntity):
|
||||
class GeoRideTrackerEntity(TrackerEntity):
|
||||
"""Represent a tracked device."""
|
||||
|
||||
def __init__(self, tracker_id, get_token_callback, get_tracker_callback, tracker):
|
||||
"""Set up Georide entity."""
|
||||
"""Set up GeoRide entity."""
|
||||
self._tracker_id = tracker_id
|
||||
self._get_token_callback = get_token_callback
|
||||
self._get_tracker_callback = get_tracker_callback
|
||||
self._name = tracker.tracker_name
|
||||
self._data = tracker or {}
|
||||
self.entity_id = ENTITY_ID_FORMAT.format(tracker_id)
|
||||
self.entity_id = DOMAIN + ".{}".format(tracker_id)
|
||||
|
||||
@property
|
||||
def unique_id(self):
|
||||
@@ -88,6 +88,7 @@ class GeorideTrackerEntity(TrackerEntity):
|
||||
|
||||
@property
|
||||
def icon(self):
|
||||
"""return the entity icon"""
|
||||
return "mdi:map-marker"
|
||||
|
||||
|
||||
@@ -117,9 +118,9 @@ class GeorideTrackerEntity(TrackerEntity):
|
||||
"""No polling needed."""
|
||||
return True
|
||||
|
||||
async def async_update(self):
|
||||
def update(self):
|
||||
""" update the current tracker"""
|
||||
_LOGGER.info('update')
|
||||
self._data = self._get_tracker_callback(self._tracker_id)
|
||||
self._name = self._data.tracker_name
|
||||
return
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"domain": "georide",
|
||||
"name": "Georide",
|
||||
"name": "GeoRide",
|
||||
"config_flow": true,
|
||||
"documentation": "https://git.tontontux.fr/mduval/GeorideHA",
|
||||
"documentation": "https://github.com/ptimatth/GeorideHA",
|
||||
"requirements": [
|
||||
"georideapilib>=0.4.3",
|
||||
"georideapilib>=0.4.4",
|
||||
"pyjwt>=1.7.1"
|
||||
],
|
||||
"dependencies": [],
|
||||
"codeowners": ["@ptimatth"]
|
||||
"codeowners": ["ptimatth"]
|
||||
}
|
||||
@@ -1,12 +1,12 @@
|
||||
""" odometter sensor for Georide object """
|
||||
""" odometter sensor for GeoRide object """
|
||||
|
||||
import logging
|
||||
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.components.switch import SwitchDevice
|
||||
from homeassistant.components.switch import SwitchEntity
|
||||
from homeassistant.components.switch import ENTITY_ID_FORMAT
|
||||
|
||||
import georideapilib.api as GeorideApi
|
||||
import georideapilib.api as GeoRideApi
|
||||
|
||||
from .const import DOMAIN as GEORIDE_DOMAIN
|
||||
|
||||
@@ -15,17 +15,17 @@ _LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
async def async_setup_entry(hass, config_entry, async_add_entities): # pylint: disable=W0613
|
||||
"""Set up Georide tracker based off an entry."""
|
||||
"""Set up GeoRide tracker based off an entry."""
|
||||
georide_context = hass.data[GEORIDE_DOMAIN]["context"]
|
||||
|
||||
if georide_context.get_token() is None:
|
||||
return False
|
||||
|
||||
trackers = GeorideApi.get_trackers(georide_context.get_token())
|
||||
trackers = GeoRideApi.get_trackers(georide_context.get_token())
|
||||
|
||||
odometer_switch_entities = []
|
||||
for tracker in trackers:
|
||||
entity = GeorideOdometerSensorEntity(tracker.tracker_id, georide_context.get_token,
|
||||
entity = GeoRideOdometerSensorEntity(tracker.tracker_id, georide_context.get_token,
|
||||
georide_context.get_tracker, data=tracker)
|
||||
hass.data[GEORIDE_DOMAIN]["devices"][tracker.tracker_id] = entity
|
||||
odometer_switch_entities.append(entity)
|
||||
@@ -34,7 +34,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities): # pylint: d
|
||||
|
||||
return True
|
||||
|
||||
class GeorideOdometerSensorEntity(SwitchDevice):
|
||||
class GeoRideOdometerSensorEntity(SwitchEntity):
|
||||
"""Represent a tracked device."""
|
||||
|
||||
def __init__(self, tracker_id, get_token_callback, get_tracker_callback, data):
|
||||
@@ -52,7 +52,7 @@ class GeorideOdometerSensorEntity(SwitchDevice):
|
||||
|
||||
def update(self):
|
||||
""" update the current tracker"""
|
||||
_LOGGER.info('async_update ')
|
||||
_LOGGER.info('update')
|
||||
self._data = self._get_tracker_callback(self._tracker_id)
|
||||
self._name = self._data.tracker_name
|
||||
self._state = self._data.odometer
|
||||
@@ -64,7 +64,7 @@ class GeorideOdometerSensorEntity(SwitchDevice):
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
""" Georide switch name """
|
||||
""" GeoRide odometer name """
|
||||
return self._name
|
||||
|
||||
@property
|
||||
@@ -77,12 +77,12 @@ class GeorideOdometerSensorEntity(SwitchDevice):
|
||||
|
||||
@property
|
||||
def get_token_callback(self):
|
||||
""" Georide switch token callback method """
|
||||
""" GeoRide switch token callback method """
|
||||
return self._get_token_callback
|
||||
|
||||
@property
|
||||
def get_tracker_callback(self):
|
||||
""" Georide switch token callback method """
|
||||
""" GeoRide switch token callback method """
|
||||
return self._get_tracker_callback
|
||||
|
||||
@property
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
"step": {
|
||||
"georide_login": {
|
||||
"title": "Set up GeoRide",
|
||||
"description": "Sign-in to georide",
|
||||
"description": "Sign-in to GeoRide",
|
||||
"data": {
|
||||
"email": "email",
|
||||
"password": "password"
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
""" device tracker for Georide object """
|
||||
""" device tracker for GeoRide object """
|
||||
|
||||
import logging
|
||||
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.components.switch import SwitchDevice
|
||||
from homeassistant.components.switch import SwitchEntity
|
||||
from homeassistant.components.switch import ENTITY_ID_FORMAT
|
||||
|
||||
import georideapilib.api as GeorideApi
|
||||
import georideapilib.api as GeoRideApi
|
||||
|
||||
from .const import DOMAIN as GEORIDE_DOMAIN
|
||||
|
||||
@@ -15,7 +15,7 @@ _LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
async def async_setup_entry(hass, config_entry, async_add_entities): # pylint: disable=W0613
|
||||
"""Set up Georide tracker based off an entry."""
|
||||
"""Set up GeoRide tracker based off an entry."""
|
||||
georide_context = hass.data[GEORIDE_DOMAIN]["context"]
|
||||
|
||||
if georide_context.get_token() is None:
|
||||
@@ -23,11 +23,11 @@ async def async_setup_entry(hass, config_entry, async_add_entities): # pylint: d
|
||||
|
||||
|
||||
_LOGGER.info('Current georide token: %s', georide_context.get_token())
|
||||
trackers = GeorideApi.get_trackers(georide_context.get_token())
|
||||
trackers = GeoRideApi.get_trackers(georide_context.get_token())
|
||||
|
||||
lock_switch_entities = []
|
||||
for tracker in trackers:
|
||||
entity = GeorideLockSwitchEntity(tracker.tracker_id, georide_context.get_token,
|
||||
entity = GeoRideLockSwitchEntity(tracker.tracker_id, georide_context.get_token,
|
||||
georide_context.get_tracker, data=tracker)
|
||||
hass.data[GEORIDE_DOMAIN]["devices"][tracker.tracker_id] = entity
|
||||
lock_switch_entities.append(entity)
|
||||
@@ -38,11 +38,11 @@ async def async_setup_entry(hass, config_entry, async_add_entities): # pylint: d
|
||||
|
||||
|
||||
|
||||
class GeorideLockSwitchEntity(SwitchDevice):
|
||||
class GeoRideLockSwitchEntity(SwitchEntity):
|
||||
"""Represent a tracked device."""
|
||||
|
||||
def __init__(self, tracker_id, get_token_callback, get_tracker_callback, data):
|
||||
"""Set up Georide entity."""
|
||||
"""Set up GeoRide entity."""
|
||||
self._tracker_id = tracker_id
|
||||
self._data = data or {}
|
||||
self._get_token_callback = get_token_callback
|
||||
@@ -54,17 +54,17 @@ class GeorideLockSwitchEntity(SwitchDevice):
|
||||
|
||||
|
||||
def turn_on(self, **kwargs):
|
||||
""" lock the georide tracker """
|
||||
""" lock the GeoRide tracker """
|
||||
_LOGGER.info('async_turn_on %s', kwargs)
|
||||
success = GeorideApi.lock_tracker(self._get_token_callback(), self._tracker_id)
|
||||
success = GeoRideApi.lock_tracker(self._get_token_callback(), self._tracker_id)
|
||||
if success:
|
||||
self._data.is_locked = True
|
||||
self._is_on = True
|
||||
|
||||
def turn_off(self, **kwargs):
|
||||
""" unlock the georide tracker """
|
||||
""" unlock the GeoRide tracker """
|
||||
_LOGGER.info('async_turn_off %s', kwargs)
|
||||
success = GeorideApi.unlock_tracker(self._get_token_callback(), self._tracker_id)
|
||||
success = GeoRideApi.unlock_tracker(self._get_token_callback(), self._tracker_id)
|
||||
if success:
|
||||
self._data.is_locked = False
|
||||
self._is_on = False
|
||||
@@ -72,7 +72,7 @@ class GeorideLockSwitchEntity(SwitchDevice):
|
||||
async def async_toggle(self, **kwargs):
|
||||
""" toggle lock the georide tracker """
|
||||
_LOGGER.info('async_toggle %s', kwargs)
|
||||
result = GeorideApi.toogle_lock_tracker(self._get_token_callback(),
|
||||
result = GeoRideApi.toogle_lock_tracker(self._get_token_callback(),
|
||||
self._tracker_id)
|
||||
self._data.is_locked = result
|
||||
self._is_on = result
|
||||
@@ -80,7 +80,7 @@ class GeorideLockSwitchEntity(SwitchDevice):
|
||||
|
||||
def update(self):
|
||||
""" update the current tracker"""
|
||||
_LOGGER.info('async_update ')
|
||||
_LOGGER.info('update')
|
||||
self._data = self._get_tracker_callback(self._tracker_id)
|
||||
self._name = self._data.tracker_name
|
||||
self._is_on = self._data.is_locked
|
||||
@@ -92,26 +92,27 @@ class GeorideLockSwitchEntity(SwitchDevice):
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
""" Georide switch name """
|
||||
""" GeoRide switch name """
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def is_on(self):
|
||||
""" Georide switch status """
|
||||
""" GeoRide switch status """
|
||||
return self._is_on
|
||||
|
||||
@property
|
||||
def get_token_callback(self):
|
||||
""" Georide switch token callback method """
|
||||
""" GeoRide switch token callback method """
|
||||
return self._get_token_callback
|
||||
|
||||
@property
|
||||
def get_tracker_callback(self):
|
||||
""" Georide switch token callback method """
|
||||
""" GeoRide switch token callback method """
|
||||
return self._get_tracker_callback
|
||||
|
||||
@property
|
||||
def icon(self):
|
||||
"""return the entity icon"""
|
||||
if self._is_on:
|
||||
return "mdi:lock"
|
||||
return "mdi:lock-open"
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
"step": {
|
||||
"georide_login": {
|
||||
"title": "Set up GeoRide",
|
||||
"description": "Sign-in to georide",
|
||||
"description": "Sign-in to GeoRide",
|
||||
"data": {
|
||||
"email": "email",
|
||||
"password": "password"
|
||||
@@ -16,10 +16,10 @@
|
||||
"unknown": "Unknown error"
|
||||
},
|
||||
"abort": {
|
||||
"one_instance_allowed": "Only a single instance is allowed."
|
||||
"one_instance_allowed": "Only one instance is allowed."
|
||||
},
|
||||
"create_entry": {
|
||||
"default": "\n\nLogin succes"
|
||||
"default": "\n\nLogin success"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,7 @@
|
||||
"step": {
|
||||
"georide_login": {
|
||||
"title": "Configuration de GeoRide",
|
||||
"description": "T'es un mortard ! V",
|
||||
"description": "T'es un motard ! V",
|
||||
"data": {
|
||||
"email": "email",
|
||||
"password": "password"
|
||||
@@ -12,14 +12,14 @@
|
||||
}
|
||||
},
|
||||
"error": {
|
||||
"faulty_credentials": "Connexion \u00e9chou\u00e9",
|
||||
"unkonwn": "Erreur inconue"
|
||||
"faulty_credentials": "Connexion \u00e9chou\u00e9e",
|
||||
"unkonwn": "Erreur inconnue"
|
||||
},
|
||||
"abort": {
|
||||
"one_instance_allowed": "Seulement un instance est authoris\u00e9e"
|
||||
"one_instance_allowed": "Seulement une instance est autoris\u00e9e"
|
||||
},
|
||||
"create_entry": {
|
||||
"default": "\n\nConnexion r\u00e9ussie!"
|
||||
"default": "\n\nConnexion r\u00e9ussie !"
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user