|
@@ -20,6 +20,8 @@ from .const import (
|
|
|
)
|
|
)
|
|
|
from .coordinator import CoordinatorData, RoomCalCoordinator
|
|
from .coordinator import CoordinatorData, RoomCalCoordinator
|
|
|
|
|
|
|
|
|
|
+UNIFI_DOMAIN = "unifi"
|
|
|
|
|
+
|
|
|
|
|
|
|
|
async def async_setup_entry(
|
|
async def async_setup_entry(
|
|
|
hass: HomeAssistant,
|
|
hass: HomeAssistant,
|
|
@@ -32,7 +34,10 @@ async def async_setup_entry(
|
|
|
identifiers={(DOMAIN, f"{entry.entry_id}_room_state")},
|
|
identifiers={(DOMAIN, f"{entry.entry_id}_room_state")},
|
|
|
name=device_name,
|
|
name=device_name,
|
|
|
)
|
|
)
|
|
|
- async_add_entities([StaleSensor(coordinator, entry, device_info)])
|
|
|
|
|
|
|
+ async_add_entities([
|
|
|
|
|
+ StaleSensor(coordinator, entry, device_info),
|
|
|
|
|
+ UnifiAvailableSensor(coordinator, entry, device_info),
|
|
|
|
|
+ ])
|
|
|
|
|
|
|
|
|
|
|
|
|
class StaleSensor(CoordinatorEntity[RoomCalCoordinator], BinarySensorEntity):
|
|
class StaleSensor(CoordinatorEntity[RoomCalCoordinator], BinarySensorEntity):
|
|
@@ -66,3 +71,28 @@ class StaleSensor(CoordinatorEntity[RoomCalCoordinator], BinarySensorEntity):
|
|
|
return True
|
|
return True
|
|
|
|
|
|
|
|
return False
|
|
return False
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+class UnifiAvailableSensor(CoordinatorEntity[RoomCalCoordinator], BinarySensorEntity):
|
|
|
|
|
+ _attr_has_entity_name = True
|
|
|
|
|
+ _attr_name = "UniFi"
|
|
|
|
|
+ _attr_icon = "mdi:wifi-check"
|
|
|
|
|
+
|
|
|
|
|
+ def __init__(
|
|
|
|
|
+ self,
|
|
|
|
|
+ coordinator: RoomCalCoordinator,
|
|
|
|
|
+ entry: ConfigEntry,
|
|
|
|
|
+ device_info: DeviceInfo,
|
|
|
|
|
+ ) -> None:
|
|
|
|
|
+ super().__init__(coordinator)
|
|
|
|
|
+ self._entry = entry
|
|
|
|
|
+ self._attr_unique_id = f"{entry.entry_id}_unifi_available"
|
|
|
|
|
+ self._attr_device_info = device_info
|
|
|
|
|
+
|
|
|
|
|
+ @property
|
|
|
|
|
+ def is_on(self) -> bool:
|
|
|
|
|
+ for config_entry in self.hass.config_entries.async_loaded_entries(UNIFI_DOMAIN):
|
|
|
|
|
+ hub = config_entry.runtime_data
|
|
|
|
|
+ if hub.available:
|
|
|
|
|
+ return True
|
|
|
|
|
+ return False
|