From 5cab811c85ff3fba1915d3d7f26950ff06665092 Mon Sep 17 00:00:00 2001 From: Matthieu Date: Sat, 10 Apr 2021 13:48:31 +0200 Subject: [PATCH] Fix binnary sensors --- custom_components/georide/binary_sensor.py | 14 +++++++++----- custom_components/georide/switch.py | 2 ++ 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/custom_components/georide/binary_sensor.py b/custom_components/georide/binary_sensor.py index 55b9e92..b997a0f 100644 --- a/custom_components/georide/binary_sensor.py +++ b/custom_components/georide/binary_sensor.py @@ -20,22 +20,27 @@ async def async_setup_entry(hass, config_entry, async_add_entities): # pylint: d return False trackers = await hass.async_add_executor_job(GeoRideApi.get_trackers,token) + - binary_sensor_entities = [] + stolen_entities = [] for tracker in trackers: stolen_entity = GeoRideStolenBinarySensorEntity(hass, tracker.tracker_id, georide_context.get_token, georide_context.get_tracker, data=tracker) hass.data[GEORIDE_DOMAIN]["devices"][tracker.tracker_id] = stolen_entity + stolen_entities.append(stolen_entity) + async_add_entities(stolen_entities) + + crashed_entities = [] + for tracker in trackers: crashed_entity = GeoRideCrashedBinarySensorEntity(hass, tracker.tracker_id, georide_context.get_token, georide_context.get_tracker, data=tracker) hass.data[GEORIDE_DOMAIN]["devices"][tracker.tracker_id] = crashed_entity - binary_sensor_entities.append(stolen_entity) - binary_sensor_entities.append(crashed_entity) - async_add_entities(binary_sensor_entities) + crashed_entities.append(crashed_entity) + async_add_entities(crashed_entities) return True @@ -112,7 +117,6 @@ class GeoRideCrashedBinarySensorEntity(BinarySensorEntity): self._state = 0 self._hass = hass - async def async_update(self): """ update the current tracker""" _LOGGER.info('update') diff --git a/custom_components/georide/switch.py b/custom_components/georide/switch.py index 9fc8615..686a32f 100644 --- a/custom_components/georide/switch.py +++ b/custom_components/georide/switch.py @@ -88,6 +88,8 @@ class GeoRideLockSwitchEntity(SwitchEntity): """ update the current tracker""" _LOGGER.info('update') self._data = await self._get_tracker_callback(self._tracker_id) + _LOGGER.debug('data %s', self._data) + self._name = self._data.tracker_name self._is_on = self._data.is_locked