From 56a8a3547967371ad0017db4e584f4feed5d39c5 Mon Sep 17 00:00:00 2001 From: Matthieu Date: Sun, 11 Apr 2021 01:31:00 +0200 Subject: [PATCH] Fix old Swirhc entity to odometer --- custom_components/georide/binary_sensor.py | 32 ++++++++------------- custom_components/georide/device_tracker.py | 6 +--- custom_components/georide/sensor.py | 17 ++++------- 3 files changed, 18 insertions(+), 37 deletions(-) diff --git a/custom_components/georide/binary_sensor.py b/custom_components/georide/binary_sensor.py index ad7b1ef..4128747 100644 --- a/custom_components/georide/binary_sensor.py +++ b/custom_components/georide/binary_sensor.py @@ -50,8 +50,7 @@ class GeoRideBinarySensorEntity(CoordinatorEntity, BinarySensorEntity): self._name = tracker.tracker_name self.entity_id = ENTITY_ID_FORMAT.format("is_stolen") + "." + str(tracker.tracker_id) - self._state = None - self._data = False + self._is_on = False @property def unique_id(self): @@ -63,11 +62,6 @@ class GeoRideBinarySensorEntity(CoordinatorEntity, BinarySensorEntity): """ GeoRide odometer name """ return self._name - @property - def is_on(self): - """state value property""" - return self._data - @property def device_info(self): """Return the device info.""" @@ -85,17 +79,15 @@ class GeoRideStolenBinarySensorEntity(GeoRideBinarySensorEntity): super().__init__(coordinator, tracker) self.entity_id = ENTITY_ID_FORMAT.format("is_stolen") + "." + str(tracker.tracker_id) - async def async_update(self): - """ update the current tracker""" - _LOGGER.debug('update') - self._name = self._tracker.tracker_name - self._data = self._tracker.is_stolen - @property def unique_id(self): """Return the unique ID.""" return f"is_stolen_{self._tracker.tracker_id}" - + + @property + def is_on(self): + """state value property""" + return self._tracker.is_stolen @@ -109,13 +101,13 @@ class GeoRideCrashedBinarySensorEntity(GeoRideBinarySensorEntity): super().__init__(coordinator, tracker) self.entity_id = ENTITY_ID_FORMAT.format("is_crashed") + "." + str(tracker.tracker_id) - async def async_update(self): - """ update the current tracker""" - _LOGGER.debug('update') - self._name = self._tracker.tracker_name - self._data = self._tracker.is_crashed - @property def unique_id(self): """Return the unique ID.""" return f"is_crashed_{self._tracker.tracker_id}" + + @property + def is_on(self): + """state value property""" + return self._tracker.is_crashed + diff --git a/custom_components/georide/device_tracker.py b/custom_components/georide/device_tracker.py index c016696..faf1cea 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.tracker_id + return f"georide_tracker_{self._tracker.tracker_id}" @property def name(self): @@ -85,10 +85,6 @@ class GeoRideTrackerEntity(CoordinatorEntity, TrackerEntity): def icon(self): """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/sensor.py b/custom_components/georide/sensor.py index 4e2234a..5426262 100644 --- a/custom_components/georide/sensor.py +++ b/custom_components/georide/sensor.py @@ -4,8 +4,8 @@ import logging from typing import Any, Mapping from homeassistant.core import callback -from homeassistant.components.switch import SwitchEntity -from homeassistant.components.switch import ENTITY_ID_FORMAT +from homeassistant.components.sensor import SensorEntity +from homeassistant.components.sensor import ENTITY_ID_FORMAT from homeassistant.helpers.update_coordinator import ( CoordinatorEntity, DataUpdateCoordinator, @@ -36,7 +36,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities): # pylint: d return True -class GeoRideOdometerSensorEntity(CoordinatorEntity, SwitchEntity): +class GeoRideOdometerSensorEntity(CoordinatorEntity, SensorEntity): """Represent a tracked device.""" def __init__(self, coordinator: DataUpdateCoordinator[Mapping[str, Any]], tracker, hass): @@ -49,13 +49,6 @@ class GeoRideOdometerSensorEntity(CoordinatorEntity, SwitchEntity): self._state = 0 self._hass = hass - - async def async_update(self): - """ update the current tracker""" - _LOGGER.debug('update') - self._name = self._tracker.tracker_name - self._state = self._tracker.odometer - @property def unique_id(self): """Return the unique ID.""" @@ -64,12 +57,12 @@ class GeoRideOdometerSensorEntity(CoordinatorEntity, SwitchEntity): @property def name(self): """ GeoRide odometer name """ - return self._name + return self._tracker.tracker_name @property def state(self): """state property""" - return self._state + return self._tracker.odometer @property def unit_of_measurement(self):