1 """Support for Notion binary sensors."""
3 from __future__
import annotations
5 from dataclasses
import dataclass
6 from typing
import Literal
8 from aionotion.listener.models
import ListenerKind
11 BinarySensorDeviceClass,
13 BinarySensorEntityDescription,
33 from .coordinator
import NotionDataUpdateCoordinator
34 from .entity
import NotionEntity, NotionEntityDescription
37 @dataclass(frozen=True, kw_only=True)
39 BinarySensorEntityDescription, NotionEntityDescription
41 """Describe a Notion binary sensor."""
43 on_state: Literal[
"alarm",
"leak",
"low",
"not_missing",
"open"]
46 BINARY_SENSOR_DESCRIPTIONS = (
49 device_class=BinarySensorDeviceClass.BATTERY,
50 entity_category=EntityCategory.DIAGNOSTIC,
51 listener_kind=ListenerKind.BATTERY,
56 device_class=BinarySensorDeviceClass.DOOR,
57 listener_kind=ListenerKind.DOOR,
61 key=SENSOR_GARAGE_DOOR,
62 device_class=BinarySensorDeviceClass.GARAGE_DOOR,
63 listener_kind=ListenerKind.GARAGE_DOOR,
68 device_class=BinarySensorDeviceClass.MOISTURE,
69 listener_kind=ListenerKind.LEAK_STATUS,
74 device_class=BinarySensorDeviceClass.CONNECTIVITY,
75 entity_category=EntityCategory.DIAGNOSTIC,
76 listener_kind=ListenerKind.CONNECTED,
77 on_state=
"not_missing",
81 translation_key=
"safe",
82 device_class=BinarySensorDeviceClass.DOOR,
83 listener_kind=ListenerKind.SAFE,
88 translation_key=
"sliding_door_window",
89 device_class=BinarySensorDeviceClass.DOOR,
90 listener_kind=ListenerKind.SLIDING_DOOR_OR_WINDOW,
95 translation_key=
"smoke_carbon_monoxide_detector",
96 device_class=BinarySensorDeviceClass.SMOKE,
97 listener_kind=ListenerKind.SMOKE,
101 key=SENSOR_WINDOW_HINGED,
102 translation_key=
"hinged_window",
103 listener_kind=ListenerKind.HINGED_WINDOW,
110 hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
112 """Set up Notion sensors based on a config entry."""
113 coordinator: NotionDataUpdateCoordinator = hass.data[DOMAIN][entry.entry_id]
124 for listener_id, listener
in coordinator.data.listeners.items()
125 for description
in BINARY_SENSOR_DESCRIPTIONS
126 if description.listener_kind.value == listener.definition_id
127 and (sensor := coordinator.data.sensors[listener.sensor_id])
133 """Define a Notion sensor."""
135 entity_description: NotionBinarySensorDescription
139 """Return true if the binary sensor is on."""
140 if not self.
listenerlistener.insights.primary.value:
141 LOGGER.warning(
"Unknown listener structure: %s", self.
listenerlistener)
None async_setup_entry(HomeAssistant hass, ConfigEntry entry, AddEntitiesCallback async_add_entities)