|
|
|
@ -6,8 +6,7 @@ from typing import Any, Mapping
|
|
|
|
|
|
|
|
|
|
from homeassistant.core import callback
|
|
|
|
|
from homeassistant.helpers.entity import DeviceInfo, EntityCategory
|
|
|
|
|
from homeassistant.components.binary_sensor import BinarySensorEntity
|
|
|
|
|
from homeassistant.components.binary_sensor import ENTITY_ID_FORMAT
|
|
|
|
|
from homeassistant.components.binary_sensor import BinarySensorEntity, BinarySensorDeviceClass, ENTITY_ID_FORMAT
|
|
|
|
|
from homeassistant.helpers.update_coordinator import (
|
|
|
|
|
CoordinatorEntity,
|
|
|
|
|
DataUpdateCoordinator
|
|
|
|
@ -33,6 +32,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities): # pylint: d
|
|
|
|
|
entities.append(GeoRideActiveSubscriptionBinarySensorEntity(coordinator, tracker_device))
|
|
|
|
|
entities.append(GeoRideNetworkBinarySensorEntity(coordinator, tracker_device))
|
|
|
|
|
entities.append(GeoRideMovingBinarySensorEntity(coordinator, tracker_device))
|
|
|
|
|
entities.append(GeoRideUpdatedBinarySensorEntity(coordinator, tracker_device))
|
|
|
|
|
|
|
|
|
|
hass.data[GEORIDE_DOMAIN]["devices"][tracker_device.tracker.tracker_id] = coordinator
|
|
|
|
|
|
|
|
|
@ -102,7 +102,7 @@ class GeoRideStolenBinarySensorEntity(GeoRideBinarySensorEntity):
|
|
|
|
|
@property
|
|
|
|
|
def device_class(self):
|
|
|
|
|
"""Return the device class."""
|
|
|
|
|
return "problem"
|
|
|
|
|
return BinarySensorDeviceClass.PROBLEM
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
|
def is_on(self):
|
|
|
|
@ -132,7 +132,7 @@ class GeoRideCrashedBinarySensorEntity(GeoRideBinarySensorEntity):
|
|
|
|
|
@property
|
|
|
|
|
def device_class(self):
|
|
|
|
|
"""Return the device class."""
|
|
|
|
|
return "problem"
|
|
|
|
|
return BinarySensorDeviceClass.PROBLEM
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
|
def is_on(self):
|
|
|
|
@ -236,6 +236,11 @@ class GeoRideNetworkBinarySensorEntity(GeoRideBinarySensorEntity):
|
|
|
|
|
return True
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
|
def device_class(self) -> str:
|
|
|
|
|
"""device class"""
|
|
|
|
|
return BinarySensorDeviceClass.CONNECTIVITY
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
|
def name(self):
|
|
|
|
|
""" GeoRide name """
|
|
|
|
@ -269,11 +274,48 @@ class GeoRideMovingBinarySensorEntity(GeoRideBinarySensorEntity):
|
|
|
|
|
"""state value property"""
|
|
|
|
|
return self._tracker_device.tracker.moving
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
|
def device_class(self) -> str:
|
|
|
|
|
"""device class"""
|
|
|
|
|
return BinarySensorDeviceClass.MOVING
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
|
def name(self):
|
|
|
|
|
""" GeoRide name """
|
|
|
|
|
return f"{self._name} is moving"
|
|
|
|
|
|
|
|
|
|
class GeoRideUpdatedBinarySensorEntity(GeoRideBinarySensorEntity):
|
|
|
|
|
"""Represent a tracked device."""
|
|
|
|
|
@property
|
|
|
|
|
def entity_category(self):
|
|
|
|
|
return EntityCategory.DIAGNOSTIC
|
|
|
|
|
|
|
|
|
|
def __init__(self, coordinator: DataUpdateCoordinator[Mapping[str, Any]],
|
|
|
|
|
tracker_device: Device):
|
|
|
|
|
"""Set up Georide entity."""
|
|
|
|
|
super().__init__(coordinator, tracker_device)
|
|
|
|
|
self.entity_id = f"{ENTITY_ID_FORMAT.format('update')}.{tracker_device.tracker.tracker_id}"# pylint: disable=C0301
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
|
def unique_id(self):
|
|
|
|
|
"""Return the unique ID."""
|
|
|
|
|
return f"update_{self._tracker_device.tracker.tracker_id}"
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
|
def is_on(self):
|
|
|
|
|
"""state value property"""
|
|
|
|
|
return not self._tracker_device.tracker.is_up_to_date
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
|
def device_class(self) -> str:
|
|
|
|
|
"""device class"""
|
|
|
|
|
return BinarySensorDeviceClass.UPDATE
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
|
def name(self):
|
|
|
|
|
""" GeoRide name """
|
|
|
|
|
return f"{self._name} have an update"
|
|
|
|
|
|
|
|
|
|
class GeoRideBeaconUpdatedBinarySensorEntity(GeoRideBeaconBinarySensorEntity):
|
|
|
|
|
"""Represent a tracked device."""
|
|
|
|
|
@property
|
|
|
|
@ -291,16 +333,16 @@ class GeoRideBeaconUpdatedBinarySensorEntity(GeoRideBeaconBinarySensorEntity):
|
|
|
|
|
"""Return the unique ID."""
|
|
|
|
|
return f"update_{self._tracker_device_beacon.beacon.beacon_id}"
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
|
def device_class(self):
|
|
|
|
|
"""Return the device class."""
|
|
|
|
|
return "update"
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
|
def is_on(self):
|
|
|
|
|
"""state value property"""
|
|
|
|
|
return not self._tracker_device_beacon.beacon.is_updated
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
|
def device_class(self) -> str:
|
|
|
|
|
"""device class"""
|
|
|
|
|
return BinarySensorDeviceClass.UPDATE
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
|
def name(self):
|
|
|
|
|
""" GeoRide name """
|
|
|
|
|