mirror of
https://github.com/home-assistant/core.git
synced 2025-07-25 06:07:17 +00:00
Streamline setup of deCONZ lock from sensor platform (#71707)
This commit is contained in:
parent
e6d7170fd8
commit
3d05a9d31f
@ -11,7 +11,6 @@ from pydeconz.models.sensor.door_lock import DoorLock
|
|||||||
from homeassistant.components.lock import DOMAIN, LockEntity
|
from homeassistant.components.lock import DOMAIN, LockEntity
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.core import HomeAssistant, callback
|
from homeassistant.core import HomeAssistant, callback
|
||||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
|
|
||||||
from .deconz_device import DeconzDevice
|
from .deconz_device import DeconzDevice
|
||||||
@ -43,33 +42,19 @@ async def async_setup_entry(
|
|||||||
async_add_lock_from_light(EventType.ADDED, lock_id)
|
async_add_lock_from_light(EventType.ADDED, lock_id)
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def async_add_lock_from_sensor(sensors: list[DoorLock] | None = None) -> None:
|
def async_add_lock_from_sensor(_: EventType, lock_id: str) -> None:
|
||||||
"""Add lock from deCONZ."""
|
"""Add lock from deCONZ."""
|
||||||
entities = []
|
lock = gateway.api.sensors.door_lock[lock_id]
|
||||||
|
async_add_entities([DeconzLock(lock, gateway)])
|
||||||
if sensors is None:
|
|
||||||
sensors = list(gateway.api.sensors.door_lock.values())
|
|
||||||
|
|
||||||
for sensor in sensors:
|
|
||||||
|
|
||||||
if (
|
|
||||||
isinstance(sensor, DoorLock)
|
|
||||||
and sensor.unique_id not in gateway.entities[DOMAIN]
|
|
||||||
):
|
|
||||||
entities.append(DeconzLock(sensor, gateway))
|
|
||||||
|
|
||||||
if entities:
|
|
||||||
async_add_entities(entities)
|
|
||||||
|
|
||||||
config_entry.async_on_unload(
|
config_entry.async_on_unload(
|
||||||
async_dispatcher_connect(
|
gateway.api.sensors.door_lock.subscribe(
|
||||||
hass,
|
|
||||||
gateway.signal_new_sensor,
|
|
||||||
async_add_lock_from_sensor,
|
async_add_lock_from_sensor,
|
||||||
|
EventType.ADDED,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
for lock_id in gateway.api.sensors.door_lock:
|
||||||
async_add_lock_from_sensor()
|
async_add_lock_from_sensor(EventType.ADDED, lock_id)
|
||||||
|
|
||||||
|
|
||||||
class DeconzLock(DeconzDevice, LockEntity):
|
class DeconzLock(DeconzDevice, LockEntity):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user