diff --git a/README.md b/README.md index 731dd5e..0bb6289 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # Georide Home assistant -![Logo Georide](./georide-logo.png) +![Logo Georide](/georide-logo.png) ⚠️ This is not an official implementation diff --git a/custom_components/georide/__init__.py b/custom_components/georide/__init__.py index 1ea84e0..15a7f3c 100644 --- a/custom_components/georide/__init__.py +++ b/custom_components/georide/__init__.py @@ -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 diff --git a/custom_components/georide/sensor.py b/custom_components/georide/sensor.py index ba8ace6..97c5a97 100644 --- a/custom_components/georide/sensor.py +++ b/custom_components/georide/sensor.py @@ -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.""" diff --git a/custom_components/georide/switch.py b/custom_components/georide/switch.py index 76b59cb..9259a6f 100644 --- a/custom_components/georide/switch.py +++ b/custom_components/georide/switch.py @@ -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):