File: test_scenes.py

package info (click to toggle)
pydeconz 120-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 764 kB
  • sloc: python: 7,951; sh: 6; makefile: 3
file content (137 lines) | stat: -rw-r--r-- 4,218 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
"""Test pydeCONZ scenes.

pytest --cov-report term-missing --cov=pydeconz.scene tests/test_scenes.py
"""


async def test_handler_scene(mock_aioresponse, deconz_called_with, deconz_session):
    """Verify that groups works."""
    scenes = deconz_session.scenes

    mock_aioresponse.post("http://host:80/api/apikey/groups/0/scenes")
    await scenes.create_scene(group_id="0", name="Garage")
    assert deconz_called_with("post", path="/groups/0/scenes", json={"name": "Garage"})

    mock_aioresponse.put("http://host:80/api/apikey/groups/0/scenes/1/recall")
    await scenes.recall(group_id="0", scene_id="1")
    assert deconz_called_with(
        "put",
        path="/groups/0/scenes/1/recall",
        json={},
    )

    mock_aioresponse.put("http://host:80/api/apikey/groups/0/scenes/1/store")
    await scenes.store(group_id="0", scene_id="1")
    assert deconz_called_with(
        "put",
        path="/groups/0/scenes/1/store",
        json={},
    )

    mock_aioresponse.put("http://host:80/api/apikey/groups/0/scenes/1")
    await scenes.set_attributes(group_id="0", scene_id="1", name="new name")
    assert deconz_called_with(
        "put",
        path="/groups/0/scenes/1",
        json={"name": "new name"},
    )

    mock_aioresponse.put("http://host:80/api/apikey/groups/0/scenes/1")
    await scenes.set_attributes(group_id="0", scene_id="1")
    assert deconz_called_with(
        "put",
        path="/groups/0/scenes/1",
        json={},
    )


async def test_scene(deconz_refresh_state):
    """Verify that groups works."""
    deconz_session = await deconz_refresh_state(
        groups={
            "0": {
                "action": {
                    "bri": 132,
                    "colormode": "hs",
                    "ct": 0,
                    "effect": "none",
                    "hue": 0,
                    "on": False,
                    "sat": 127,
                    "scene": None,
                    "xy": [0, 0],
                },
                "devicemembership": [],
                "etag": "e31c23b3bd9ece918f23ee17ef430304",
                "id": "11",
                "lights": ["14", "15", "12"],
                "name": "Hall",
                "scenes": [
                    {
                        "id": "1",
                        "name": "warmlight",
                        "lightcount": 3,
                        "transitiontime": 10,
                    }
                ],
                "state": {"all_on": False, "any_on": True},
                "type": "LightGroup",
            }
        }
    )

    assert len(deconz_session.scenes.values()) == 1

    scene = deconz_session.scenes["0_1"]
    assert scene.deconz_id == "/groups/0/scenes/1"
    assert scene.id == "1"
    assert scene.light_count == 3
    assert scene.transition_time == 10
    assert scene.name == "warmlight"

    await deconz_refresh_state(
        groups={
            "0": {
                "action": {
                    "bri": 132,
                    "colormode": "hs",
                    "ct": 0,
                    "effect": "none",
                    "hue": 0,
                    "on": False,
                    "sat": 127,
                    "scene": None,
                    "xy": [0, 0],
                },
                "devicemembership": [],
                "etag": "e31c23b3bd9ece918f23ee17ef430304",
                "id": "11",
                "lights": ["14", "15", "12"],
                "name": "Hall",
                "scenes": [
                    {
                        "id": "1",
                        "name": "coldlight",
                        "lightcount": 3,
                        "transitiontime": 10,
                    },
                    {"id": "2", "name": "New scene"},
                ],
                "state": {"all_on": False, "any_on": True},
                "type": "LightGroup",
            }
        }
    )

    assert len(deconz_session.scenes.values()) == 2

    # Update scene

    assert scene.name == "coldlight"

    # Add scene

    scene2 = deconz_session.scenes["0_2"]
    assert scene2.deconz_id == "/groups/0/scenes/2"
    assert scene2.id == "2"
    assert scene2.name == "New scene"