Extend Nuki integration to expose ringer through Nuki Opener (#107745)

* Expose ring_action_state and ring_action_timestamp of Nuki Opener

* add translation key

* address comments
This commit is contained in:
steffenrapp 2024-01-12 18:45:02 +01:00 committed by GitHub
parent 28917011cb
commit d0e9e54f26
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 41 additions and 4 deletions

View File

@ -19,16 +19,22 @@ from .const import ATTR_NUKI_ID, DOMAIN as NUKI_DOMAIN
async def async_setup_entry( async def async_setup_entry(
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
) -> None: ) -> None:
"""Set up the Nuki lock binary sensor.""" """Set up the Nuki binary sensors."""
entry_data: NukiEntryData = hass.data[NUKI_DOMAIN][entry.entry_id] entry_data: NukiEntryData = hass.data[NUKI_DOMAIN][entry.entry_id]
entities = [] lock_entities = []
opener_entities = []
for lock in entry_data.locks: for lock in entry_data.locks:
if lock.is_door_sensor_activated: if lock.is_door_sensor_activated:
entities.extend([NukiDoorsensorEntity(entry_data.coordinator, lock)]) lock_entities.extend([NukiDoorsensorEntity(entry_data.coordinator, lock)])
async_add_entities(entities) async_add_entities(lock_entities)
for opener in entry_data.openers:
opener_entities.extend([NukiRingactionEntity(entry_data.coordinator, opener)])
async_add_entities(opener_entities)
class NukiDoorsensorEntity(NukiEntity[NukiDevice], BinarySensorEntity): class NukiDoorsensorEntity(NukiEntity[NukiDevice], BinarySensorEntity):
@ -70,3 +76,29 @@ class NukiDoorsensorEntity(NukiEntity[NukiDevice], BinarySensorEntity):
def is_on(self): def is_on(self):
"""Return true if the door is open.""" """Return true if the door is open."""
return self.door_sensor_state == STATE_DOORSENSOR_OPENED return self.door_sensor_state == STATE_DOORSENSOR_OPENED
class NukiRingactionEntity(NukiEntity[NukiDevice], BinarySensorEntity):
"""Representation of a Nuki Opener Ringaction."""
_attr_has_entity_name = True
_attr_translation_key = "ring_action"
_attr_icon = "mdi:bell-ring"
@property
def unique_id(self) -> str:
"""Return a unique ID."""
return f"{self._nuki_device.nuki_id}_ringaction"
@property
def extra_state_attributes(self):
"""Return the device specific state attributes."""
data = {
ATTR_NUKI_ID: self._nuki_device.nuki_id,
}
return data
@property
def is_on(self) -> bool:
"""Return the value of the ring action state."""
return self._nuki_device.ring_action_state

View File

@ -38,6 +38,11 @@
} }
}, },
"entity": { "entity": {
"binary_sensor": {
"ring_action": {
"name": "Ring Action"
}
},
"lock": { "lock": {
"nuki_lock": { "nuki_lock": {
"state_attributes": { "state_attributes": {