mirror of
https://github.com/home-assistant/core.git
synced 2025-07-17 10:17:09 +00:00
Add support for ZHADoorLock locks to deCONZ integration(#48516)
This commit is contained in:
parent
96c391af09
commit
c80f34a754
@ -60,7 +60,7 @@ COVER_TYPES = DAMPERS + WINDOW_COVERS
|
|||||||
FANS = ["Fan"]
|
FANS = ["Fan"]
|
||||||
|
|
||||||
# Locks
|
# Locks
|
||||||
LOCKS = ["Door Lock"]
|
LOCKS = ["Door Lock", "ZHADoorLock"]
|
||||||
LOCK_TYPES = LOCKS
|
LOCK_TYPES = LOCKS
|
||||||
|
|
||||||
# Switches
|
# Switches
|
||||||
|
@ -3,7 +3,7 @@ from homeassistant.components.lock import DOMAIN, LockEntity
|
|||||||
from homeassistant.core import callback
|
from homeassistant.core import callback
|
||||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||||
|
|
||||||
from .const import LOCKS, NEW_LIGHT
|
from .const import LOCKS, NEW_LIGHT, NEW_SENSOR
|
||||||
from .deconz_device import DeconzDevice
|
from .deconz_device import DeconzDevice
|
||||||
from .gateway import get_gateway_from_config_entry
|
from .gateway import get_gateway_from_config_entry
|
||||||
|
|
||||||
@ -14,7 +14,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
|||||||
gateway.entities[DOMAIN] = set()
|
gateway.entities[DOMAIN] = set()
|
||||||
|
|
||||||
@callback
|
@callback
|
||||||
def async_add_lock(lights=gateway.api.lights.values()):
|
def async_add_lock_from_light(lights=gateway.api.lights.values()):
|
||||||
"""Add lock from deCONZ."""
|
"""Add lock from deCONZ."""
|
||||||
entities = []
|
entities = []
|
||||||
|
|
||||||
@ -28,11 +28,33 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
|||||||
|
|
||||||
gateway.listeners.append(
|
gateway.listeners.append(
|
||||||
async_dispatcher_connect(
|
async_dispatcher_connect(
|
||||||
hass, gateway.async_signal_new_device(NEW_LIGHT), async_add_lock
|
hass, gateway.async_signal_new_device(NEW_LIGHT), async_add_lock_from_light
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
async_add_lock()
|
@callback
|
||||||
|
def async_add_lock_from_sensor(sensors=gateway.api.sensors.values()):
|
||||||
|
"""Add lock from deCONZ."""
|
||||||
|
entities = []
|
||||||
|
|
||||||
|
for sensor in sensors:
|
||||||
|
|
||||||
|
if sensor.type in LOCKS and sensor.uniqueid not in gateway.entities[DOMAIN]:
|
||||||
|
entities.append(DeconzLock(sensor, gateway))
|
||||||
|
|
||||||
|
if entities:
|
||||||
|
async_add_entities(entities)
|
||||||
|
|
||||||
|
gateway.listeners.append(
|
||||||
|
async_dispatcher_connect(
|
||||||
|
hass,
|
||||||
|
gateway.async_signal_new_device(NEW_SENSOR),
|
||||||
|
async_add_lock_from_sensor,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
async_add_lock_from_light()
|
||||||
|
async_add_lock_from_sensor()
|
||||||
|
|
||||||
|
|
||||||
class DeconzLock(DeconzDevice, LockEntity):
|
class DeconzLock(DeconzDevice, LockEntity):
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
"name": "deCONZ",
|
"name": "deCONZ",
|
||||||
"config_flow": true,
|
"config_flow": true,
|
||||||
"documentation": "https://www.home-assistant.io/integrations/deconz",
|
"documentation": "https://www.home-assistant.io/integrations/deconz",
|
||||||
"requirements": ["pydeconz==77"],
|
"requirements": ["pydeconz==78"],
|
||||||
"ssdp": [
|
"ssdp": [
|
||||||
{
|
{
|
||||||
"manufacturer": "Royal Philips Electronics"
|
"manufacturer": "Royal Philips Electronics"
|
||||||
|
@ -3,6 +3,7 @@ from pydeconz.sensor import (
|
|||||||
Battery,
|
Battery,
|
||||||
Consumption,
|
Consumption,
|
||||||
Daylight,
|
Daylight,
|
||||||
|
DoorLock,
|
||||||
Humidity,
|
Humidity,
|
||||||
LightLevel,
|
LightLevel,
|
||||||
Power,
|
Power,
|
||||||
@ -103,7 +104,10 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
|||||||
if (
|
if (
|
||||||
not sensor.BINARY
|
not sensor.BINARY
|
||||||
and sensor.type
|
and sensor.type
|
||||||
not in Battery.ZHATYPE + Switch.ZHATYPE + Thermostat.ZHATYPE
|
not in Battery.ZHATYPE
|
||||||
|
+ DoorLock.ZHATYPE
|
||||||
|
+ Switch.ZHATYPE
|
||||||
|
+ Thermostat.ZHATYPE
|
||||||
and sensor.uniqueid not in gateway.entities[DOMAIN]
|
and sensor.uniqueid not in gateway.entities[DOMAIN]
|
||||||
):
|
):
|
||||||
entities.append(DeconzSensor(sensor, gateway))
|
entities.append(DeconzSensor(sensor, gateway))
|
||||||
|
@ -1337,7 +1337,7 @@ pydaikin==2.4.1
|
|||||||
pydanfossair==0.1.0
|
pydanfossair==0.1.0
|
||||||
|
|
||||||
# homeassistant.components.deconz
|
# homeassistant.components.deconz
|
||||||
pydeconz==77
|
pydeconz==78
|
||||||
|
|
||||||
# homeassistant.components.delijn
|
# homeassistant.components.delijn
|
||||||
pydelijn==0.6.1
|
pydelijn==0.6.1
|
||||||
|
@ -705,7 +705,7 @@ pycoolmasternet-async==0.1.2
|
|||||||
pydaikin==2.4.1
|
pydaikin==2.4.1
|
||||||
|
|
||||||
# homeassistant.components.deconz
|
# homeassistant.components.deconz
|
||||||
pydeconz==77
|
pydeconz==78
|
||||||
|
|
||||||
# homeassistant.components.dexcom
|
# homeassistant.components.dexcom
|
||||||
pydexcom==0.2.0
|
pydexcom==0.2.0
|
||||||
|
@ -4,7 +4,7 @@ from copy import deepcopy
|
|||||||
from unittest.mock import Mock, patch
|
from unittest.mock import Mock, patch
|
||||||
|
|
||||||
import pydeconz
|
import pydeconz
|
||||||
from pydeconz.websocket import STATE_RUNNING, STATE_STARTING
|
from pydeconz.websocket import STATE_RETRYING, STATE_RUNNING
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from homeassistant.components.binary_sensor import DOMAIN as BINARY_SENSOR_DOMAIN
|
from homeassistant.components.binary_sensor import DOMAIN as BINARY_SENSOR_DOMAIN
|
||||||
@ -199,7 +199,7 @@ async def test_connection_status_signalling(
|
|||||||
|
|
||||||
assert hass.states.get("binary_sensor.presence").state == STATE_OFF
|
assert hass.states.get("binary_sensor.presence").state == STATE_OFF
|
||||||
|
|
||||||
await mock_deconz_websocket(state=STATE_STARTING)
|
await mock_deconz_websocket(state=STATE_RETRYING)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
assert hass.states.get("binary_sensor.presence").state == STATE_UNAVAILABLE
|
assert hass.states.get("binary_sensor.presence").state == STATE_UNAVAILABLE
|
||||||
|
@ -27,8 +27,8 @@ async def test_no_locks(hass, aioclient_mock):
|
|||||||
assert len(hass.states.async_all()) == 0
|
assert len(hass.states.async_all()) == 0
|
||||||
|
|
||||||
|
|
||||||
async def test_locks(hass, aioclient_mock, mock_deconz_websocket):
|
async def test_lock_from_light(hass, aioclient_mock, mock_deconz_websocket):
|
||||||
"""Test that all supported lock entities are created."""
|
"""Test that all supported lock entities based on lights are created."""
|
||||||
data = {
|
data = {
|
||||||
"lights": {
|
"lights": {
|
||||||
"1": {
|
"1": {
|
||||||
@ -98,3 +98,84 @@ async def test_locks(hass, aioclient_mock, mock_deconz_websocket):
|
|||||||
await hass.config_entries.async_remove(config_entry.entry_id)
|
await hass.config_entries.async_remove(config_entry.entry_id)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
assert len(hass.states.async_all()) == 0
|
assert len(hass.states.async_all()) == 0
|
||||||
|
|
||||||
|
|
||||||
|
async def test_lock_from_sensor(hass, aioclient_mock, mock_deconz_websocket):
|
||||||
|
"""Test that all supported lock entities based on sensors are created."""
|
||||||
|
data = {
|
||||||
|
"sensors": {
|
||||||
|
"1": {
|
||||||
|
"config": {
|
||||||
|
"battery": 100,
|
||||||
|
"lock": False,
|
||||||
|
"on": True,
|
||||||
|
"reachable": True,
|
||||||
|
},
|
||||||
|
"ep": 11,
|
||||||
|
"etag": "a43862f76b7fa48b0fbb9107df123b0e",
|
||||||
|
"lastseen": "2021-03-06T22:25Z",
|
||||||
|
"manufacturername": "Onesti Products AS",
|
||||||
|
"modelid": "easyCodeTouch_v1",
|
||||||
|
"name": "Door lock",
|
||||||
|
"state": {
|
||||||
|
"lastupdated": "2021-03-06T21:25:45.624",
|
||||||
|
"lockstate": "unlocked",
|
||||||
|
},
|
||||||
|
"swversion": "20201211",
|
||||||
|
"type": "ZHADoorLock",
|
||||||
|
"uniqueid": "00:00:00:00:00:00:00:00-00",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
with patch.dict(DECONZ_WEB_REQUEST, data):
|
||||||
|
config_entry = await setup_deconz_integration(hass, aioclient_mock)
|
||||||
|
|
||||||
|
assert len(hass.states.async_all()) == 2
|
||||||
|
assert hass.states.get("lock.door_lock").state == STATE_UNLOCKED
|
||||||
|
|
||||||
|
event_changed_light = {
|
||||||
|
"t": "event",
|
||||||
|
"e": "changed",
|
||||||
|
"r": "sensors",
|
||||||
|
"id": "1",
|
||||||
|
"state": {"lockstate": "locked"},
|
||||||
|
}
|
||||||
|
await mock_deconz_websocket(data=event_changed_light)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
assert hass.states.get("lock.door_lock").state == STATE_LOCKED
|
||||||
|
|
||||||
|
# Verify service calls
|
||||||
|
|
||||||
|
mock_deconz_put_request(aioclient_mock, config_entry.data, "/sensors/1/config")
|
||||||
|
|
||||||
|
# Service lock door
|
||||||
|
|
||||||
|
await hass.services.async_call(
|
||||||
|
LOCK_DOMAIN,
|
||||||
|
SERVICE_LOCK,
|
||||||
|
{ATTR_ENTITY_ID: "lock.door_lock"},
|
||||||
|
blocking=True,
|
||||||
|
)
|
||||||
|
assert aioclient_mock.mock_calls[1][2] == {"lock": True}
|
||||||
|
|
||||||
|
# Service unlock door
|
||||||
|
|
||||||
|
await hass.services.async_call(
|
||||||
|
LOCK_DOMAIN,
|
||||||
|
SERVICE_UNLOCK,
|
||||||
|
{ATTR_ENTITY_ID: "lock.door_lock"},
|
||||||
|
blocking=True,
|
||||||
|
)
|
||||||
|
assert aioclient_mock.mock_calls[2][2] == {"lock": False}
|
||||||
|
|
||||||
|
await hass.config_entries.async_unload(config_entry.entry_id)
|
||||||
|
|
||||||
|
states = hass.states.async_all()
|
||||||
|
assert len(states) == 2
|
||||||
|
for state in states:
|
||||||
|
assert state.state == STATE_UNAVAILABLE
|
||||||
|
|
||||||
|
await hass.config_entries.async_remove(config_entry.entry_id)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
assert len(hass.states.async_all()) == 0
|
||||||
|
Loading…
x
Reference in New Issue
Block a user