Fix old Swirhc entity to odometer

develop
Matthieu DUVAL 4 years ago
parent 7d25405c2f
commit 56a8a35479

@ -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

@ -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):

@ -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):

Loading…
Cancel
Save