Debian Codegraph @

tests/lights/test_lock.py

raw symbols SCIP
1 """Test pydeCONZ lock."""
2
3 from unittest.mock import Mock
4
5 DATA = {
6 "etag": "5c2ec06cde4bd654aef3a555fcd8ad12",
7 "hascolor": False,
8 "lastannounced": None,
9 "lastseen": "2020-08-22T15:29:03Z",
10 "manufacturername": "Danalock",
11 "modelid": "V3-BTZB",
12 "name": "Door lock",
13 "state": {
14 "alert": "none",
15 "on": False,
16 "reachable": True,
17 },
18 "swversion": "19042019",
19 "type": "Door Lock",
20 "uniqueid": "xx:xx:xx:xx:xx:xx:xx:xx-00",
21 }
22
23
24 async def test_handler_lock(mock_aioresponse, deconz_session, deconz_called_with):
25 """Verify that controlling locks work."""
26 locks = deconz_session.lights.locks
27
28 mock_aioresponse.put("http://host:80/api/apikey/lights/0/state")
29 await locks.set_state("0", lock=True)
30 assert deconz_called_with("put", path="/lights/0/state", json={"on": True})
31
32 mock_aioresponse.put("http://host:80/api/apikey/lights/0/state")
33 await locks.set_state("0", lock=False)
34 assert deconz_called_with("put", path="/lights/0/state", json={"on": False})
35
36
37 async def test_light_lock(deconz_light):
38 """Verify that locks work."""
39 lock = await deconz_light(DATA)
40
41 assert lock.state is False
42 assert lock.is_locked is False
43
44 assert lock.reachable is True
45
46 assert lock.deconz_id == "/lights/0"
47 assert lock.etag == "5c2ec06cde4bd654aef3a555fcd8ad12"
48 assert lock.manufacturer == "Danalock"
49 assert lock.model_id == "V3-BTZB"
50 assert lock.name == "Door lock"
51 assert lock.software_version == "19042019"
52 assert lock.type == "Door Lock"
53 assert lock.unique_id == "xx:xx:xx:xx:xx:xx:xx:xx-00"
54
55 lock.register_callback(mock_callback := Mock())
56 assert lock._callbacks
57
58 event = {"state": {"on": True}}
59 lock.update(event)
60 assert lock.is_locked is True
61 mock_callback.assert_called_once()
62 assert lock.changed_keys == {"state", "on"}
63
64 lock.remove_callback(mock_callback)
65 assert not lock._callbacks