Add devices class to better categorisation in HA
This commit is contained in:
@@ -106,7 +106,7 @@ async def async_setup_entry(hass, entry):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry):
|
async def async_unload_entry(hass, entry):
|
||||||
"""Unload an GeoRide config entry."""
|
"""Unload an GeoRide config entry."""
|
||||||
|
|
||||||
await hass.config_entries.async_forward_entry_unload(entry, "device_tracker")
|
await hass.config_entries.async_forward_entry_unload(entry, "device_tracker")
|
||||||
@@ -116,22 +116,12 @@ async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry):
|
|||||||
await hass.config_entries.async_forward_entry_unload(entry, "siren")
|
await hass.config_entries.async_forward_entry_unload(entry, "siren")
|
||||||
|
|
||||||
context = hass.data[DOMAIN]["context"]
|
context = hass.data[DOMAIN]["context"]
|
||||||
context.socket.disconnect() // Disconnect only if all devices is disabled
|
context.socket.disconnect() # Disconnect only if all devices is disabled
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
async def async_remove_config_entry_device(hass: HomeAssistant, config_entry: ConfigEntry, device_entry: DeviceEntry) -> bool:
|
async def async_remove_config_entry_device(hass, config_entry, device_entry) -> bool:
|
||||||
"""Remove an GeoRide device entry."""
|
"""Remove an GeoRide device entry."""
|
||||||
|
|
||||||
await hass.config_entries.async_remove_config_entry_device(device_entry, "device_tracker")
|
|
||||||
await hass.config_entries.async_remove_config_entry_device(device_entry, "switch")
|
|
||||||
await hass.config_entries.async_remove_config_entry_device(device_entry, "sensor")
|
|
||||||
await hass.config_entries.async_remove_config_entry_device(device_entry, "binary_sensor")
|
|
||||||
await hass.config_entries.async_remove_config_entry_device(device_entry, "siren")
|
|
||||||
|
|
||||||
context = hass.data[DOMAIN]["context"]
|
|
||||||
# context.socket.disconnect()
|
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -6,8 +6,7 @@ from typing import Any, Mapping
|
|||||||
|
|
||||||
from homeassistant.core import callback
|
from homeassistant.core import callback
|
||||||
from homeassistant.helpers.entity import DeviceInfo, EntityCategory
|
from homeassistant.helpers.entity import DeviceInfo, EntityCategory
|
||||||
from homeassistant.components.binary_sensor import BinarySensorEntity
|
from homeassistant.components.binary_sensor import BinarySensorEntity, BinarySensorDeviceClass, ENTITY_ID_FORMAT
|
||||||
from homeassistant.components.binary_sensor import ENTITY_ID_FORMAT
|
|
||||||
from homeassistant.helpers.update_coordinator import (
|
from homeassistant.helpers.update_coordinator import (
|
||||||
CoordinatorEntity,
|
CoordinatorEntity,
|
||||||
DataUpdateCoordinator
|
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(GeoRideActiveSubscriptionBinarySensorEntity(coordinator, tracker_device))
|
||||||
entities.append(GeoRideNetworkBinarySensorEntity(coordinator, tracker_device))
|
entities.append(GeoRideNetworkBinarySensorEntity(coordinator, tracker_device))
|
||||||
entities.append(GeoRideMovingBinarySensorEntity(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
|
hass.data[GEORIDE_DOMAIN]["devices"][tracker_device.tracker.tracker_id] = coordinator
|
||||||
|
|
||||||
@@ -102,7 +102,7 @@ class GeoRideStolenBinarySensorEntity(GeoRideBinarySensorEntity):
|
|||||||
@property
|
@property
|
||||||
def device_class(self):
|
def device_class(self):
|
||||||
"""Return the device class."""
|
"""Return the device class."""
|
||||||
return "problem"
|
return BinarySensorDeviceClass.PROBLEM
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_on(self):
|
def is_on(self):
|
||||||
@@ -132,7 +132,7 @@ class GeoRideCrashedBinarySensorEntity(GeoRideBinarySensorEntity):
|
|||||||
@property
|
@property
|
||||||
def device_class(self):
|
def device_class(self):
|
||||||
"""Return the device class."""
|
"""Return the device class."""
|
||||||
return "problem"
|
return BinarySensorDeviceClass.PROBLEM
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_on(self):
|
def is_on(self):
|
||||||
@@ -236,6 +236,11 @@ class GeoRideNetworkBinarySensorEntity(GeoRideBinarySensorEntity):
|
|||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@property
|
||||||
|
def device_class(self) -> str:
|
||||||
|
"""device class"""
|
||||||
|
return BinarySensorDeviceClass.CONNECTIVITY
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
""" GeoRide name """
|
""" GeoRide name """
|
||||||
@@ -269,11 +274,48 @@ class GeoRideMovingBinarySensorEntity(GeoRideBinarySensorEntity):
|
|||||||
"""state value property"""
|
"""state value property"""
|
||||||
return self._tracker_device.tracker.moving
|
return self._tracker_device.tracker.moving
|
||||||
|
|
||||||
|
@property
|
||||||
|
def device_class(self) -> str:
|
||||||
|
"""device class"""
|
||||||
|
return BinarySensorDeviceClass.MOVING
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
""" GeoRide name """
|
""" GeoRide name """
|
||||||
return f"{self._name} is moving"
|
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):
|
class GeoRideBeaconUpdatedBinarySensorEntity(GeoRideBeaconBinarySensorEntity):
|
||||||
"""Represent a tracked device."""
|
"""Represent a tracked device."""
|
||||||
@property
|
@property
|
||||||
@@ -291,16 +333,16 @@ class GeoRideBeaconUpdatedBinarySensorEntity(GeoRideBeaconBinarySensorEntity):
|
|||||||
"""Return the unique ID."""
|
"""Return the unique ID."""
|
||||||
return f"update_{self._tracker_device_beacon.beacon.beacon_id}"
|
return f"update_{self._tracker_device_beacon.beacon.beacon_id}"
|
||||||
|
|
||||||
@property
|
|
||||||
def device_class(self):
|
|
||||||
"""Return the device class."""
|
|
||||||
return "update"
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_on(self):
|
def is_on(self):
|
||||||
"""state value property"""
|
"""state value property"""
|
||||||
return not self._tracker_device_beacon.beacon.is_updated
|
return not self._tracker_device_beacon.beacon.is_updated
|
||||||
|
|
||||||
|
@property
|
||||||
|
def device_class(self) -> str:
|
||||||
|
"""device class"""
|
||||||
|
return BinarySensorDeviceClass.UPDATE
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
""" GeoRide name """
|
""" GeoRide name """
|
||||||
|
|||||||
@@ -141,7 +141,7 @@ class DeviceBeacon:
|
|||||||
@property
|
@property
|
||||||
def via_device(self) -> str:
|
def via_device(self) -> str:
|
||||||
"""Get the unique id."""
|
"""Get the unique id."""
|
||||||
return {(GEORIDE_DOMAIN, self._beacon.tracker_id)}
|
return (GEORIDE_DOMAIN, self._beacon.linked_tracker_id )
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def device_info(self):
|
def device_info(self):
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
"issue_tracker": "https://github.com/ptimatth/GeorideHA/issues",
|
"issue_tracker": "https://github.com/ptimatth/GeorideHA/issues",
|
||||||
"iot_class": "cloud_polling",
|
"iot_class": "cloud_polling",
|
||||||
"requirements": [
|
"requirements": [
|
||||||
"georideapilib>=0.9.0",
|
"georideapilib>=0.9.3",
|
||||||
"pyjwt>=2.2.0"
|
"pyjwt>=2.2.0"
|
||||||
],
|
],
|
||||||
"dependencies": [],
|
"dependencies": [],
|
||||||
|
|||||||
@@ -5,8 +5,7 @@ from typing import Any, Mapping
|
|||||||
|
|
||||||
from homeassistant.core import callback
|
from homeassistant.core import callback
|
||||||
from homeassistant.helpers.entity import DeviceInfo, EntityCategory
|
from homeassistant.helpers.entity import DeviceInfo, EntityCategory
|
||||||
from homeassistant.components.sensor import SensorEntity
|
from homeassistant.components.sensor import SensorEntity, SensorDeviceClass, ENTITY_ID_FORMAT
|
||||||
from homeassistant.components.sensor import ENTITY_ID_FORMAT
|
|
||||||
from homeassistant.helpers.update_coordinator import (
|
from homeassistant.helpers.update_coordinator import (
|
||||||
CoordinatorEntity,
|
CoordinatorEntity,
|
||||||
DataUpdateCoordinator,
|
DataUpdateCoordinator,
|
||||||
@@ -245,6 +244,11 @@ class GeoRideInternalBatterySensorEntity(CoordinatorEntity, SensorEntity):
|
|||||||
"""icon getter"""
|
"""icon getter"""
|
||||||
return "mdi:battery"
|
return "mdi:battery"
|
||||||
|
|
||||||
|
@property
|
||||||
|
def device_class(self) -> str:
|
||||||
|
"""device class"""
|
||||||
|
return SensorDeviceClass.VOLTAGE
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def device_info(self) -> DeviceInfo:
|
def device_info(self) -> DeviceInfo:
|
||||||
"""Return the device info."""
|
"""Return the device info."""
|
||||||
@@ -302,6 +306,11 @@ class GeoRideExternalBatterySensorEntity(CoordinatorEntity, SensorEntity):
|
|||||||
"""icon getter"""
|
"""icon getter"""
|
||||||
return "mdi:battery"
|
return "mdi:battery"
|
||||||
|
|
||||||
|
@property
|
||||||
|
def device_class(self) -> str:
|
||||||
|
"""device class"""
|
||||||
|
return SensorDeviceClass.VOLTAGE
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def device_info(self) -> DeviceInfo:
|
def device_info(self) -> DeviceInfo:
|
||||||
"""Return the device info."""
|
"""Return the device info."""
|
||||||
@@ -391,6 +400,11 @@ class GeoRideBeaconBatterySensorEntity(CoordinatorEntity, SensorEntity):
|
|||||||
"""icon getter"""
|
"""icon getter"""
|
||||||
return "mdi:battery"
|
return "mdi:battery"
|
||||||
|
|
||||||
|
@property
|
||||||
|
def device_class(self) -> str:
|
||||||
|
"""device class"""
|
||||||
|
return SensorDeviceClass.BATTERY
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def device_info(self) -> DeviceInfo:
|
def device_info(self) -> DeviceInfo:
|
||||||
"""Return the device info."""
|
"""Return the device info."""
|
||||||
|
|||||||
Reference in New Issue
Block a user