|
|
@@ -4,8 +4,8 @@ from datetime import timedelta
|
|
|
|
|
|
from homeassistant.components.binary_sensor import BinarySensorEntity
|
|
|
from homeassistant.config_entries import ConfigEntry
|
|
|
-from homeassistant.const import EVENT_COMPONENT_LOADED, EntityCategory
|
|
|
-from homeassistant.core import Event, HomeAssistant, callback
|
|
|
+from homeassistant.const import EntityCategory
|
|
|
+from homeassistant.core import HomeAssistant
|
|
|
from homeassistant.helpers.device_registry import DeviceInfo
|
|
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
|
|
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
|
|
@@ -22,8 +22,6 @@ from .const import (
|
|
|
)
|
|
|
from .coordinator import CoordinatorData, RoomCalCoordinator
|
|
|
|
|
|
-UNIFI_DOMAIN = "unifi"
|
|
|
-
|
|
|
|
|
|
async def async_setup_entry(
|
|
|
hass: HomeAssistant,
|
|
|
@@ -42,7 +40,6 @@ async def async_setup_entry(
|
|
|
)
|
|
|
async_add_entities([
|
|
|
StaleSensor(coordinator, entry, room_state_device),
|
|
|
- UnifiAvailableSensor(coordinator, entry, room_state_device),
|
|
|
ArrivedSensor(coordinator, entry, current_device),
|
|
|
DepartedSensor(coordinator, entry, current_device),
|
|
|
])
|
|
|
@@ -82,55 +79,6 @@ class StaleSensor(CoordinatorEntity[RoomCalCoordinator], BinarySensorEntity):
|
|
|
return False
|
|
|
|
|
|
|
|
|
-class UnifiAvailableSensor(CoordinatorEntity[RoomCalCoordinator], BinarySensorEntity):
|
|
|
- """Reflects UniFi hub availability, independent of the room_cal_ha coordinator.
|
|
|
-
|
|
|
- This entity's state comes entirely from the `unifi` integration's config entries,
|
|
|
- not from `coordinator.data` — so its availability must not be tied to
|
|
|
- `coordinator.last_update_success` (the CoordinatorEntity default). A failed room_cal
|
|
|
- backend poll has no bearing on whether UniFi itself is reachable.
|
|
|
- """
|
|
|
-
|
|
|
- _attr_has_entity_name = True
|
|
|
- _attr_translation_key = "unifi_available"
|
|
|
- _attr_icon = "mdi:wifi-check"
|
|
|
- _attr_entity_category = EntityCategory.DIAGNOSTIC
|
|
|
-
|
|
|
- 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
|
|
|
-
|
|
|
- async def async_added_to_hass(self) -> None:
|
|
|
- await super().async_added_to_hass()
|
|
|
- self.async_on_remove(
|
|
|
- self.hass.bus.async_listen(EVENT_COMPONENT_LOADED, self._handle_component_loaded)
|
|
|
- )
|
|
|
-
|
|
|
- @callback
|
|
|
- def _handle_component_loaded(self, event: Event) -> None:
|
|
|
- if event.data.get("component") == UNIFI_DOMAIN:
|
|
|
- self.async_write_ha_state()
|
|
|
-
|
|
|
- @property
|
|
|
- def available(self) -> bool:
|
|
|
- return True
|
|
|
-
|
|
|
- @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
|
|
|
-
|
|
|
-
|
|
|
class ArrivedSensor(CoordinatorEntity[RoomCalCoordinator], BinarySensorEntity):
|
|
|
_attr_has_entity_name = True
|
|
|
_attr_translation_key = "arrived"
|