Chandge switch from async to realtume update

master
Matthieu DUVAL 5 years ago
parent 750073b8f3
commit cc45b02a3a

@ -183,14 +183,10 @@ class GeorideContext:
self._pending_msg.append(data)
@callback
def on_lock_callback(self, data_string):
def on_lock_callback(self, data):
"""on lock callback"""
_LOGGER.info("On lock received %s", data_string)
data = data_string
_LOGGER.info("On lock received %s", data['trackerId'])
_LOGGER.info("On lock received")
for tracker in self._georide_trackers:
if tracker.tracker_id == data['trackerId']:
tracker.locked_latitude = data['lockedLatitude']
tracker.locked_longitude = data['lockedLongitude']
@ -198,20 +194,18 @@ class GeorideContext:
return
@callback
def on_device_callback(self, data_string):
def on_device_callback(self, data):
"""on device callback"""
_LOGGER.info("On device received")
data = data_string.json()
for tracker in self._georide_trackers:
if tracker.tracker_id == data['trackerId']:
tracker.status = data['status']
return
@callback
def on_position_callback(self, data_string):
def on_position_callback(self, data):
"""on position callback"""
_LOGGER.info("On position received %s", data_string)
data = data_string.json()
_LOGGER.info("On position received")
for tracker in self._georide_trackers:
if tracker.tracker_id == data['trackerId']:
tracker.latitude = data['latitude']

@ -53,39 +53,37 @@ class GeorideLockSwitchEntity(SwitchDevice):
self._state = {}
async def async_turn_on(self, **kwargs):
def turn_on(self, **kwargs):
""" lock the georide tracker """
_LOGGER.info('async_turn_on %s', kwargs)
success = GeorideApi.lock_tracker(self._get_token_callback(), self._tracker_id)
if success:
self._data.is_locked = True
self._is_on = True
async def async_turn_off(self, **kwargs):
def turn_off(self, **kwargs):
""" unlock the georide tracker """
_LOGGER.info('async_turn_off %s', kwargs)
success = GeorideApi.unlock_tracker(self._get_token_callback(), self._tracker_id)
if success:
self._data.is_locked = False
self._is_on = False
async def async_toggle(self, **kwargs):
""" toggle lock the georide tracker """
_LOGGER.info('async_toggle %s', kwargs)
self._is_on = GeorideApi.toogle_lock_tracker(self._get_token_callback(),
self._tracker_id)
result = GeorideApi.toogle_lock_tracker(self._get_token_callback(),
self._tracker_id)
self._data.is_locked = result
self._is_on = result
@property
def should_poll(self):
"""No polling needed."""
return True
async def async_update(self):
def update(self):
""" update the current tracker"""
_LOGGER.info('async_update ')
self._data = self._get_tracker_callback(self._tracker_id)
self._name = self._data.tracker_name
self._is_on = self._data.is_locked
return
@property
def unique_id(self):

Loading…
Cancel
Save