|
@@ -18,6 +18,7 @@ from .const import (
|
|
|
DOMAIN,
|
|
DOMAIN,
|
|
|
STORE_CURRENT,
|
|
STORE_CURRENT,
|
|
|
STORE_NEXT,
|
|
STORE_NEXT,
|
|
|
|
|
+ SYNC_MODE_API,
|
|
|
SYNC_MODE_MANUAL,
|
|
SYNC_MODE_MANUAL,
|
|
|
)
|
|
)
|
|
|
from .coordinator import CoordinatorData, RoomCalCoordinator
|
|
from .coordinator import CoordinatorData, RoomCalCoordinator
|
|
@@ -33,10 +34,18 @@ async def async_setup_entry(
|
|
|
|
|
|
|
|
room_name = entry.data.get(CONF_ROOM_NAME, entry.title)
|
|
room_name = entry.data.get(CONF_ROOM_NAME, entry.title)
|
|
|
|
|
|
|
|
|
|
+ room_state_device = DeviceInfo(
|
|
|
|
|
+ identifiers={(DOMAIN, f"{entry.entry_id}_room_state")},
|
|
|
|
|
+ name=f"{room_name} Room State",
|
|
|
|
|
+ )
|
|
|
|
|
+
|
|
|
entities: list[SensorEntity] = [
|
|
entities: list[SensorEntity] = [
|
|
|
- SyncSourceSensor(entry, room_name),
|
|
|
|
|
|
|
+ SyncSourceSensor(entry, room_name, room_state_device),
|
|
|
]
|
|
]
|
|
|
|
|
|
|
|
|
|
+ if entry.options.get(CONF_SYNC_MODE) == SYNC_MODE_API:
|
|
|
|
|
+ entities.append(ApiHealthSensor(coordinator, entry, room_state_device))
|
|
|
|
|
+
|
|
|
for slot, device_name in (
|
|
for slot, device_name in (
|
|
|
(STORE_CURRENT, f"{room_name} Current"),
|
|
(STORE_CURRENT, f"{room_name} Current"),
|
|
|
(STORE_NEXT, f"{room_name} Next"),
|
|
(STORE_NEXT, f"{room_name} Next"),
|
|
@@ -66,13 +75,10 @@ class SyncSourceSensor(SensorEntity):
|
|
|
_attr_name = "Sync Source"
|
|
_attr_name = "Sync Source"
|
|
|
_attr_icon = "mdi:sync"
|
|
_attr_icon = "mdi:sync"
|
|
|
|
|
|
|
|
- def __init__(self, entry: ConfigEntry, room_name: str) -> None:
|
|
|
|
|
|
|
+ def __init__(self, entry: ConfigEntry, room_name: str, device_info: DeviceInfo) -> None:
|
|
|
self._entry = entry
|
|
self._entry = entry
|
|
|
self._attr_unique_id = f"{entry.entry_id}_sync_source"
|
|
self._attr_unique_id = f"{entry.entry_id}_sync_source"
|
|
|
- self._attr_device_info = DeviceInfo(
|
|
|
|
|
- identifiers={(DOMAIN, f"{entry.entry_id}_room_state")},
|
|
|
|
|
- name=f"{room_name} Room State",
|
|
|
|
|
- )
|
|
|
|
|
|
|
+ self._attr_device_info = device_info
|
|
|
|
|
|
|
|
@property
|
|
@property
|
|
|
def native_value(self) -> str:
|
|
def native_value(self) -> str:
|
|
@@ -222,6 +228,7 @@ class LastRefreshSensor(CoordinatorEntity[RoomCalCoordinator], SensorEntity):
|
|
|
_attr_has_entity_name = True
|
|
_attr_has_entity_name = True
|
|
|
_attr_name = "Last Refresh"
|
|
_attr_name = "Last Refresh"
|
|
|
_attr_device_class = SensorDeviceClass.TIMESTAMP
|
|
_attr_device_class = SensorDeviceClass.TIMESTAMP
|
|
|
|
|
+ _attr_icon = "mdi:timer-sync"
|
|
|
|
|
|
|
|
def __init__(
|
|
def __init__(
|
|
|
self,
|
|
self,
|
|
@@ -243,3 +250,33 @@ class LastRefreshSensor(CoordinatorEntity[RoomCalCoordinator], SensorEntity):
|
|
|
if self._slot == STORE_CURRENT
|
|
if self._slot == STORE_CURRENT
|
|
|
else data.next_last_refresh
|
|
else data.next_last_refresh
|
|
|
)
|
|
)
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+class ApiHealthSensor(CoordinatorEntity[RoomCalCoordinator], SensorEntity):
|
|
|
|
|
+ _attr_has_entity_name = True
|
|
|
|
|
+ _attr_name = "API Health"
|
|
|
|
|
+ _attr_icon = "mdi:api"
|
|
|
|
|
+
|
|
|
|
|
+ def __init__(
|
|
|
|
|
+ self,
|
|
|
|
|
+ coordinator: RoomCalCoordinator,
|
|
|
|
|
+ entry: ConfigEntry,
|
|
|
|
|
+ device_info: DeviceInfo,
|
|
|
|
|
+ ) -> None:
|
|
|
|
|
+ super().__init__(coordinator)
|
|
|
|
|
+ self._attr_unique_id = f"{entry.entry_id}_api_health"
|
|
|
|
|
+ self._attr_device_info = device_info
|
|
|
|
|
+
|
|
|
|
|
+ @property
|
|
|
|
|
+ def native_value(self) -> str | None:
|
|
|
|
|
+ api_status = self.coordinator.data.api_status
|
|
|
|
|
+ if api_status is None:
|
|
|
|
|
+ return None
|
|
|
|
|
+ return "OK" if api_status.status == "OK" else "Degraded"
|
|
|
|
|
+
|
|
|
|
|
+ @property
|
|
|
|
|
+ def extra_state_attributes(self) -> dict | None:
|
|
|
|
|
+ api_status = self.coordinator.data.api_status
|
|
|
|
|
+ if api_status is None or not api_status.services:
|
|
|
|
|
+ return None
|
|
|
|
|
+ return dict(api_status.services)
|