Debian Codegraph @

tests/test_scenes.py

raw symbols SCIP
1 """Test pydeCONZ scenes.
2
3 pytest --cov-report term-missing --cov=pydeconz.scene tests/test_scenes.py
4 """
5
6
7 async def test_handler_scene(mock_aioresponse, deconz_called_with, deconz_session):
8 """Verify that groups works."""
9 scenes = deconz_session.scenes
10
11 mock_aioresponse.post("http://host:80/api/apikey/groups/0/scenes")
12 await scenes.create_scene(group_id="0", name="Garage")
13 assert deconz_called_with("post", path="/groups/0/scenes", json={"name": "Garage"})
14
15 mock_aioresponse.put("http://host:80/api/apikey/groups/0/scenes/1/recall")
16 await scenes.recall(group_id="0", scene_id="1")
17 assert deconz_called_with(
18 "put",
19 path="/groups/0/scenes/1/recall",
20 json={},
21 )
22
23 mock_aioresponse.put("http://host:80/api/apikey/groups/0/scenes/1/store")
24 await scenes.store(group_id="0", scene_id="1")
25 assert deconz_called_with(
26 "put",
27 path="/groups/0/scenes/1/store",
28 json={},
29 )
30
31 mock_aioresponse.put("http://host:80/api/apikey/groups/0/scenes/1")
32 await scenes.set_attributes(group_id="0", scene_id="1", name="new name")
33 assert deconz_called_with(
34 "put",
35 path="/groups/0/scenes/1",
36 json={"name": "new name"},
37 )
38
39 mock_aioresponse.put("http://host:80/api/apikey/groups/0/scenes/1")
40 await scenes.set_attributes(group_id="0", scene_id="1")
41 assert deconz_called_with(
42 "put",
43 path="/groups/0/scenes/1",
44 json={},
45 )
46
47
48 async def test_scene(deconz_refresh_state):
49 """Verify that groups works."""
50 deconz_session = await deconz_refresh_state(
51 groups={
52 "0": {
53 "action": {
54 "bri": 132,
55 "colormode": "hs",
56 "ct": 0,
57 "effect": "none",
58 "hue": 0,
59 "on": False,
60 "sat": 127,
61 "scene": None,
62 "xy": [0, 0],
63 },
64 "devicemembership": [],
65 "etag": "e31c23b3bd9ece918f23ee17ef430304",
66 "id": "11",
67 "lights": ["14", "15", "12"],
68 "name": "Hall",
69 "scenes": [
70 {
71 "id": "1",
72 "name": "warmlight",
73 "lightcount": 3,
74 "transitiontime": 10,
75 }
76 ],
77 "state": {"all_on": False, "any_on": True},
78 "type": "LightGroup",
79 }
80 }
81 )
82
83 assert len(deconz_session.scenes.values()) == 1
84
85 scene = deconz_session.scenes["0_1"]
86 assert scene.deconz_id == "/groups/0/scenes/1"
87 assert scene.id == "1"
88 assert scene.light_count == 3
89 assert scene.transition_time == 10
90 assert scene.name == "warmlight"
91
92 await deconz_refresh_state(
93 groups={
94 "0": {
95 "action": {
96 "bri": 132,
97 "colormode": "hs",
98 "ct": 0,
99 "effect": "none",
100 "hue": 0,
101 "on": False,
102 "sat": 127,
103 "scene": None,
104 "xy": [0, 0],
105 },
106 "devicemembership": [],
107 "etag": "e31c23b3bd9ece918f23ee17ef430304",
108 "id": "11",
109 "lights": ["14", "15", "12"],
110 "name": "Hall",
111 "scenes": [
112 {
113 "id": "1",
114 "name": "coldlight",
115 "lightcount": 3,
116 "transitiontime": 10,
117 },
118 {"id": "2", "name": "New scene"},
119 ],
120 "state": {"all_on": False, "any_on": True},
121 "type": "LightGroup",
122 }
123 }
124 )
125
126 assert len(deconz_session.scenes.values()) == 2
127
128 # Update scene
129
130 assert scene.name == "coldlight"
131
132 # Add scene
133
134 scene2 = deconz_session.scenes["0_2"]
135 assert scene2.deconz_id == "/groups/0/scenes/2"
136 assert scene2.id == "2"
137 assert scene2.name == "New scene"