Add better polling

Matthieu DUVAL 5 years ago
parent 649c97b8bb
commit 7a80670fd3

@ -1,5 +1,5 @@
# Georide Home assistant
![Logo Georide](./georide-logo.png)
![Logo Georide](/georide-logo.png)
⚠️ This is not an official implementation

@ -68,6 +68,7 @@ async def async_setup(hass, config):
def connect_socket(hass, component):
"""subscribe to georide socket"""
_LOGGER.info("Run socket connexion tread")
context = hass.data[DOMAIN]["context"]
socket = GeorideSocket()
@ -206,6 +207,11 @@ class GeorideContext:
"""set the georide socket"""
self._socket = socket
def fire_event(self, type):
self._hass.bus.fire('georide-refresh', {
'type': type
})
@callback
def on_lock_callback(self, data):
@ -216,6 +222,7 @@ class GeorideContext:
tracker.locked_latitude = data['lockedLatitude']
tracker.locked_longitude = data['lockedLongitude']
tracker.is_locked = data['isLocked']
self.fire_event('on_lock')
return
@callback
@ -225,6 +232,7 @@ class GeorideContext:
for tracker in self._georide_trackers:
if tracker.tracker_id == data['trackerId']:
tracker.status = data['status']
self.fire_event('on_device')
return
@callback
@ -238,6 +246,7 @@ class GeorideContext:
tracker.moving = data['moving']
tracker.speed = data['speed']
tracker.fixtime = data['fixtime']
self.fire_event('on_position')
return

@ -34,6 +34,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities): # pylint: d
return True
class GeorideOdometerSensorEntity(SwitchDevice):
"""Represent a tracked device."""

@ -31,6 +31,9 @@ async def async_setup_entry(hass, config_entry, async_add_entities): # pylint: d
georide_context.get_tracker, data=tracker)
hass.data[GEORIDE_DOMAIN]["devices"][tracker.tracker_id] = entity
lock_switch_entities.append(entity)
#Here we subscribe to teh georide event
hass.bus.listen('georide-refresh', entity.update)
async_add_entities(lock_switch_entities)
@ -80,10 +83,11 @@ class GeorideLockSwitchEntity(SwitchDevice):
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
_LOGGER.info('update')
data = self._get_tracker_callback(self._tracker_id)
self._data = data
self._name = data.tracker_name
self._is_on = data.is_locked
@property
def unique_id(self):

Loading…
Cancel
Save