|
@@ -11,10 +11,14 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
|
|
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
|
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
|
|
|
|
|
|
|
from .const import (
|
|
from .const import (
|
|
|
|
|
+ CONF_API_BASE_URL,
|
|
|
|
|
+ CONF_CALDAV_URL,
|
|
|
CONF_ROOM_NAME,
|
|
CONF_ROOM_NAME,
|
|
|
|
|
+ CONF_SYNC_MODE,
|
|
|
DOMAIN,
|
|
DOMAIN,
|
|
|
STORE_CURRENT,
|
|
STORE_CURRENT,
|
|
|
STORE_NEXT,
|
|
STORE_NEXT,
|
|
|
|
|
+ SYNC_MODE_MANUAL,
|
|
|
)
|
|
)
|
|
|
from .coordinator import CoordinatorData, RoomCalCoordinator
|
|
from .coordinator import CoordinatorData, RoomCalCoordinator
|
|
|
from .models import ReservationData
|
|
from .models import ReservationData
|
|
@@ -29,7 +33,9 @@ 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)
|
|
|
|
|
|
|
|
- entities: list[SensorEntity] = []
|
|
|
|
|
|
|
+ entities: list[SensorEntity] = [
|
|
|
|
|
+ SyncSourceSensor(entry, room_name),
|
|
|
|
|
+ ]
|
|
|
|
|
|
|
|
for slot, device_name in (
|
|
for slot, device_name in (
|
|
|
(STORE_CURRENT, f"{room_name} Current"),
|
|
(STORE_CURRENT, f"{room_name} Current"),
|
|
@@ -55,6 +61,35 @@ async def async_setup_entry(
|
|
|
async_add_entities(entities)
|
|
async_add_entities(entities)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+class SyncSourceSensor(SensorEntity):
|
|
|
|
|
+ _attr_has_entity_name = True
|
|
|
|
|
+ _attr_name = "Sync Source"
|
|
|
|
|
+ _attr_icon = "mdi:sync"
|
|
|
|
|
+
|
|
|
|
|
+ def __init__(self, entry: ConfigEntry, room_name: str) -> None:
|
|
|
|
|
+ self._entry = entry
|
|
|
|
|
+ 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",
|
|
|
|
|
+ )
|
|
|
|
|
+
|
|
|
|
|
+ @property
|
|
|
|
|
+ def native_value(self) -> str:
|
|
|
|
|
+ return self._entry.options.get(CONF_SYNC_MODE, SYNC_MODE_MANUAL)
|
|
|
|
|
+
|
|
|
|
|
+ @property
|
|
|
|
|
+ def extra_state_attributes(self) -> dict[str, str | None]:
|
|
|
|
|
+ mode = self._entry.options.get(CONF_SYNC_MODE, SYNC_MODE_MANUAL)
|
|
|
|
|
+ if mode == "caldav":
|
|
|
|
|
+ url = self._entry.options.get(CONF_CALDAV_URL)
|
|
|
|
|
+ elif mode == "api":
|
|
|
|
|
+ url = self._entry.options.get(CONF_API_BASE_URL)
|
|
|
|
|
+ else:
|
|
|
|
|
+ url = None
|
|
|
|
|
+ return {"server_url": url}
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
class _ReservationSensor(CoordinatorEntity[RoomCalCoordinator], SensorEntity):
|
|
class _ReservationSensor(CoordinatorEntity[RoomCalCoordinator], SensorEntity):
|
|
|
_attr_has_entity_name = True
|
|
_attr_has_entity_name = True
|
|
|
|
|
|