1 """Doorsensor Support for the Nuki Lock."""
3 from __future__
import annotations
5 from pynuki.constants
import STATE_DOORSENSOR_OPENED
6 from pynuki.device
import NukiDevice
9 BinarySensorDeviceClass,
17 from .
import NukiEntryData
18 from .const
import DOMAIN
as NUKI_DOMAIN
19 from .entity
import NukiEntity
23 hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
25 """Set up the Nuki binary sensors."""
26 entry_data: NukiEntryData = hass.data[NUKI_DOMAIN][entry.entry_id]
28 entities: list[NukiEntity] = []
30 for lock
in entry_data.locks:
31 if lock.is_door_sensor_activated:
36 for opener
in entry_data.openers:
44 """Representation of a Nuki Lock Doorsensor."""
46 _attr_has_entity_name =
True
48 _attr_device_class = BinarySensorDeviceClass.DOOR
52 """Return a unique ID."""
53 return f
"{self._nuki_device.nuki_id}_doorsensor"
57 """Return true if door sensor is present and activated."""
58 return super().available
and self._nuki_device.is_door_sensor_activated
62 """Return the state of the door sensor."""
63 return self._nuki_device.door_sensor_state
67 """Return the state name of the door sensor."""
68 return self._nuki_device.door_sensor_state_name
72 """Return true if the door is open."""
77 """Representation of a Nuki Opener Ringaction."""
79 _attr_has_entity_name =
True
80 _attr_translation_key =
"ring_action"
84 """Return a unique ID."""
85 return f
"{self._nuki_device.nuki_id}_ringaction"
89 """Return the value of the ring action state."""
90 return self._nuki_device.ring_action_state
94 """Representation of Nuki Battery Critical."""
96 _attr_has_entity_name =
True
97 _attr_device_class = BinarySensorDeviceClass.BATTERY
98 _attr_entity_category = EntityCategory.DIAGNOSTIC
102 """Return a unique ID."""
103 return f
"{self._nuki_device.nuki_id}_battery_critical"
107 """Return the value of the battery critical."""
108 return self._nuki_device.battery_critical
112 """Representation of a Nuki Battery charging."""
114 _attr_has_entity_name =
True
115 _attr_device_class = BinarySensorDeviceClass.BATTERY_CHARGING
116 _attr_entity_category = EntityCategory.DIAGNOSTIC
117 _attr_entity_registry_enabled_default =
False
121 """Return a unique ID."""
122 return f
"{self._nuki_device.nuki_id}_battery_charging"
126 """Return the value of the battery charging."""
127 return self._nuki_device.battery_charging
def door_sensor_state(self)
def door_sensor_state_name(self)
None async_setup_entry(HomeAssistant hass, ConfigEntry entry, AddEntitiesCallback async_add_entities)