From 660aaa018024522d24fada61ff4d146aba534647 Mon Sep 17 00:00:00 2001 From: Matthieu Date: Sun, 11 Apr 2021 00:05:52 +0200 Subject: [PATCH] Fix switch response --- custom_components/georide/device_tracker.py | 9 ++++++--- custom_components/georide/switch.py | 14 ++------------ 2 files changed, 8 insertions(+), 15 deletions(-) diff --git a/custom_components/georide/device_tracker.py b/custom_components/georide/device_tracker.py index dc1feb3..c016696 100644 --- a/custom_components/georide/device_tracker.py +++ b/custom_components/georide/device_tracker.py @@ -49,7 +49,7 @@ class GeoRideTrackerEntity(CoordinatorEntity, TrackerEntity): @property def unique_id(self): """Return the unique ID.""" - return self._tracker_id + return self._tracker.tracker_id @property def name(self): @@ -59,14 +59,14 @@ class GeoRideTrackerEntity(CoordinatorEntity, TrackerEntity): @property def latitude(self): """Return latitude value of the device.""" - if self._data.latitude: + if self._tracker.latitude: return self._tracker.latitude return None @property def longitude(self): """Return longitude value of the device.""" - if self._data.longitude: + if self._tracker.longitude: return self._tracker.longitude return None @@ -86,6 +86,9 @@ class GeoRideTrackerEntity(CoordinatorEntity, TrackerEntity): """return the entity icon""" return "mdi:map-marker" + async def async_update(self): + """ update the current tracker""" + _LOGGER.debug('update') @property def device_info(self): diff --git a/custom_components/georide/switch.py b/custom_components/georide/switch.py index f972f12..26c24f7 100644 --- a/custom_components/georide/switch.py +++ b/custom_components/georide/switch.py @@ -50,7 +50,6 @@ class GeoRideLockSwitchEntity(CoordinatorEntity, SwitchEntity): super().__init__(coordinator) self._tracker = tracker self._name = tracker.tracker_name - self._is_on = tracker.is_locked self.entity_id = ENTITY_ID_FORMAT.format("lock") +"." + str(tracker.tracker_id) self._hass = hass @@ -64,7 +63,6 @@ class GeoRideLockSwitchEntity(CoordinatorEntity, SwitchEntity): token, self._tracker_id) if success: self._tracker.is_locked = True - self._is_on = True async def async_turn_off(self, **kwargs): """ unlock the GeoRide tracker """ @@ -75,7 +73,6 @@ class GeoRideLockSwitchEntity(CoordinatorEntity, SwitchEntity): token, self._tracker_id) if success: self._tracker.is_locked = False - self._is_on = False async def async_toggle(self, **kwargs): """ toggle lock the georide tracker """ @@ -85,13 +82,6 @@ class GeoRideLockSwitchEntity(CoordinatorEntity, SwitchEntity): result = await self._hass.async_add_executor_job(GeoRideApi.toogle_lock_tracker, token, self._tracker_id) self._tracker.is_locked = result - self._is_on = result - - async def async_update(self): - """ update the current tracker""" - _LOGGER.debug('update') - self._name = self._tracker.tracker_name - self._is_on = self._tracker.is_lockedtracker @property def unique_id(self): @@ -106,12 +96,12 @@ class GeoRideLockSwitchEntity(CoordinatorEntity, SwitchEntity): @property def is_on(self): """ GeoRide switch status """ - return self._is_on + return self._tracker.is_locked @property def icon(self): """return the entity icon""" - if self._is_on: + if self._tracker.tracker_id: return "mdi:lock" return "mdi:lock-open"