Add better polling
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
# Georide Home assistant
|
# Georide Home assistant
|
||||||

|

|
||||||
|
|
||||||
⚠️ This is not an official implementation
|
⚠️ This is not an official implementation
|
||||||
|
|
||||||
|
|||||||
@@ -68,6 +68,7 @@ async def async_setup(hass, config):
|
|||||||
|
|
||||||
def connect_socket(hass, component):
|
def connect_socket(hass, component):
|
||||||
"""subscribe to georide socket"""
|
"""subscribe to georide socket"""
|
||||||
|
_LOGGER.info("Run socket connexion tread")
|
||||||
context = hass.data[DOMAIN]["context"]
|
context = hass.data[DOMAIN]["context"]
|
||||||
|
|
||||||
socket = GeorideSocket()
|
socket = GeorideSocket()
|
||||||
@@ -206,6 +207,11 @@ class GeorideContext:
|
|||||||
"""set the georide socket"""
|
"""set the georide socket"""
|
||||||
self._socket = socket
|
self._socket = socket
|
||||||
|
|
||||||
|
def fire_event(self, type):
|
||||||
|
self._hass.bus.fire('georide-refresh', {
|
||||||
|
'type': type
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def on_lock_callback(self, data):
|
def on_lock_callback(self, data):
|
||||||
@@ -216,6 +222,7 @@ class GeorideContext:
|
|||||||
tracker.locked_latitude = data['lockedLatitude']
|
tracker.locked_latitude = data['lockedLatitude']
|
||||||
tracker.locked_longitude = data['lockedLongitude']
|
tracker.locked_longitude = data['lockedLongitude']
|
||||||
tracker.is_locked = data['isLocked']
|
tracker.is_locked = data['isLocked']
|
||||||
|
self.fire_event('on_lock')
|
||||||
return
|
return
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
@@ -225,6 +232,7 @@ class GeorideContext:
|
|||||||
for tracker in self._georide_trackers:
|
for tracker in self._georide_trackers:
|
||||||
if tracker.tracker_id == data['trackerId']:
|
if tracker.tracker_id == data['trackerId']:
|
||||||
tracker.status = data['status']
|
tracker.status = data['status']
|
||||||
|
self.fire_event('on_device')
|
||||||
return
|
return
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
@@ -238,6 +246,7 @@ class GeorideContext:
|
|||||||
tracker.moving = data['moving']
|
tracker.moving = data['moving']
|
||||||
tracker.speed = data['speed']
|
tracker.speed = data['speed']
|
||||||
tracker.fixtime = data['fixtime']
|
tracker.fixtime = data['fixtime']
|
||||||
|
self.fire_event('on_position')
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities): # pylint: d
|
|||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
class GeorideOdometerSensorEntity(SwitchDevice):
|
class GeorideOdometerSensorEntity(SwitchDevice):
|
||||||
"""Represent a tracked device."""
|
"""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)
|
georide_context.get_tracker, data=tracker)
|
||||||
hass.data[GEORIDE_DOMAIN]["devices"][tracker.tracker_id] = entity
|
hass.data[GEORIDE_DOMAIN]["devices"][tracker.tracker_id] = entity
|
||||||
lock_switch_entities.append(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)
|
async_add_entities(lock_switch_entities)
|
||||||
|
|
||||||
@@ -80,10 +83,11 @@ class GeorideLockSwitchEntity(SwitchDevice):
|
|||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
""" update the current tracker"""
|
""" update the current tracker"""
|
||||||
_LOGGER.info('async_update ')
|
_LOGGER.info('update')
|
||||||
self._data = self._get_tracker_callback(self._tracker_id)
|
data = self._get_tracker_callback(self._tracker_id)
|
||||||
self._name = self._data.tracker_name
|
self._data = data
|
||||||
self._is_on = self._data.is_locked
|
self._name = data.tracker_name
|
||||||
|
self._is_on = data.is_locked
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def unique_id(self):
|
def unique_id(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user