1 """Dormakaba dKey integration binary sensor platform."""
3 from __future__
import annotations
5 from collections.abc
import Callable
6 from dataclasses
import dataclass
8 from py_dormakaba_dkey
import DKEYLock
9 from py_dormakaba_dkey.commands
import DoorPosition, Notifications, UnlockStatus
12 BinarySensorDeviceClass,
14 BinarySensorEntityDescription,
21 from .const
import DOMAIN
22 from .entity
import DormakabaDkeyEntity
23 from .models
import DormakabaDkeyData
26 @dataclass(frozen=True, kw_only=True)
28 """Describes Dormakaba dKey binary sensor entity."""
30 is_on: Callable[[Notifications], bool]
33 BINARY_SENSOR_DESCRIPTIONS = (
36 device_class=BinarySensorDeviceClass.DOOR,
37 is_on=
lambda state: state.door_position == DoorPosition.OPEN,
40 key=
"security_locked",
41 translation_key=
"deadbolt",
42 device_class=BinarySensorDeviceClass.LOCK,
43 is_on=
lambda state: state.unlock_status
44 not in (UnlockStatus.SECURITY_LOCKED, UnlockStatus.UNLOCKED_SECURITY_LOCKED),
52 async_add_entities: AddEntitiesCallback,
54 """Set up the binary sensor platform for Dormakaba dKey."""
55 data: DormakabaDkeyData = hass.data[DOMAIN][entry.entry_id]
58 for description
in BINARY_SENSOR_DESCRIPTIONS
63 """Dormakaba dKey binary sensor."""
65 _attr_has_entity_name =
True
66 entity_description: DormakabaDkeyBinarySensorDescription
70 coordinator: DataUpdateCoordinator[
None],
72 description: DormakabaDkeyBinarySensorDescription,
74 """Initialize a Dormakaba dKey binary sensor."""
81 """Handle updating _attr values."""
None __init__(self, DataUpdateCoordinator[None] coordinator, DKEYLock lock, DormakabaDkeyBinarySensorDescription description)
None _async_update_attrs(self)
None async_setup_entry(HomeAssistant hass, ConfigEntry entry, AddEntitiesCallback async_add_entities)