Streamline setup of deCONZ lock from light platform (#71659)
This commit is contained in:
parent
920c0d1667
commit
db17d7aecf
1 changed files with 8 additions and 20 deletions
|
@ -4,6 +4,7 @@ from __future__ import annotations
|
|||
|
||||
from typing import Any
|
||||
|
||||
from pydeconz.models.event import EventType
|
||||
from pydeconz.models.light.lock import Lock
|
||||
from pydeconz.models.sensor.door_lock import DoorLock
|
||||
|
||||
|
@ -27,31 +28,19 @@ async def async_setup_entry(
|
|||
gateway.entities[DOMAIN] = set()
|
||||
|
||||
@callback
|
||||
def async_add_lock_from_light(lights: list[Lock] | None = None) -> None:
|
||||
def async_add_lock_from_light(_: EventType, lock_id: str) -> None:
|
||||
"""Add lock from deCONZ."""
|
||||
entities = []
|
||||
|
||||
if lights is None:
|
||||
lights = list(gateway.api.lights.locks.values())
|
||||
|
||||
for light in lights:
|
||||
|
||||
if (
|
||||
isinstance(light, Lock)
|
||||
and light.unique_id not in gateway.entities[DOMAIN]
|
||||
):
|
||||
entities.append(DeconzLock(light, gateway))
|
||||
|
||||
if entities:
|
||||
async_add_entities(entities)
|
||||
lock = gateway.api.lights.locks[lock_id]
|
||||
async_add_entities([DeconzLock(lock, gateway)])
|
||||
|
||||
config_entry.async_on_unload(
|
||||
async_dispatcher_connect(
|
||||
hass,
|
||||
gateway.signal_new_light,
|
||||
gateway.api.lights.locks.subscribe(
|
||||
async_add_lock_from_light,
|
||||
EventType.ADDED,
|
||||
)
|
||||
)
|
||||
for lock_id in gateway.api.lights.locks:
|
||||
async_add_lock_from_light(EventType.ADDED, lock_id)
|
||||
|
||||
@callback
|
||||
def async_add_lock_from_sensor(sensors: list[DoorLock] | None = None) -> None:
|
||||
|
@ -80,7 +69,6 @@ async def async_setup_entry(
|
|||
)
|
||||
)
|
||||
|
||||
async_add_lock_from_light()
|
||||
async_add_lock_from_sensor()
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue