File: test_multicast.py

package info (click to toggle)
zwave-js-server-python 0.67.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,820 kB
  • sloc: python: 15,886; sh: 21; javascript: 16; makefile: 2
file content (326 lines) | stat: -rw-r--r-- 9,784 bytes parent folder | download | duplicates (2)
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
"""Test node utility functions."""

from zwave_js_server.const import CommandClass, SetValueStatus
from zwave_js_server.util.multicast import (
    async_multicast_endpoint_get_cc_version,
    async_multicast_endpoint_invoke_cc_api,
    async_multicast_endpoint_supports_cc,
    async_multicast_endpoint_supports_cc_api,
    async_multicast_get_endpoint_count,
    async_multicast_set_value,
)


async def test_endpoint_get_cc_version_multicast(
    climate_radio_thermostat_ct100_plus, inovelli_switch, client, uuid4, mock_command
):
    """Test multicast_group.get_cc_version command."""
    node1 = climate_radio_thermostat_ct100_plus
    node2 = inovelli_switch
    ack_commands = mock_command(
        {"command": "multicast_group.get_cc_version"},
        {"version": 1},
    )

    assert (
        await async_multicast_endpoint_get_cc_version(
            client, 1, CommandClass.NOTIFICATION, [node1, node2]
        )
        == 1
    )

    assert ack_commands[0] == {
        "command": "multicast_group.get_cc_version",
        "index": 1,
        "commandClass": 113,
        "nodeIDs": [node1.node_id, node2.node_id],
        "messageId": uuid4,
    }


async def test_endpoint_get_cc_version_broadcast(client, uuid4, mock_command):
    """Test broadcast_node.get_cc_version command."""
    ack_commands = mock_command(
        {"command": "broadcast_node.get_cc_version"},
        {"version": 1},
    )

    assert (
        await async_multicast_endpoint_get_cc_version(
            client, 1, CommandClass.NOTIFICATION
        )
        == 1
    )

    assert ack_commands[0] == {
        "command": "broadcast_node.get_cc_version",
        "index": 1,
        "commandClass": 113,
        "messageId": uuid4,
    }


async def test_endpoint_supports_cc_broadcast(client, uuid4, mock_command):
    """Test broadcast_node.supports_cc command."""
    ack_commands = mock_command(
        {"command": "broadcast_node.supports_cc"},
        {"supported": True},
    )

    assert await async_multicast_endpoint_supports_cc(
        client, 1, CommandClass.NOTIFICATION
    )

    assert ack_commands[0] == {
        "command": "broadcast_node.supports_cc",
        "index": 1,
        "commandClass": 113,
        "messageId": uuid4,
    }


async def test_endpoint_supports_cc_multicast(
    climate_radio_thermostat_ct100_plus, inovelli_switch, client, uuid4, mock_command
):
    """Test multicast_group.supports_cc command."""
    node1 = climate_radio_thermostat_ct100_plus
    node2 = inovelli_switch
    ack_commands = mock_command(
        {"command": "multicast_group.supports_cc"},
        {"supported": True},
    )

    assert await async_multicast_endpoint_supports_cc(
        client, 1, CommandClass.NOTIFICATION, [node1, node2]
    )

    assert ack_commands[0] == {
        "command": "multicast_group.supports_cc",
        "index": 1,
        "commandClass": 113,
        "nodeIDs": [node1.node_id, node2.node_id],
        "messageId": uuid4,
    }


async def test_get_endpoint_count_broadcast(client, uuid4, mock_command):
    """Test broadcast_node.get_endpoint_count command."""
    ack_commands = mock_command(
        {"command": "broadcast_node.get_endpoint_count"},
        {"count": 1},
    )

    assert await async_multicast_get_endpoint_count(client) == 1

    assert ack_commands[0] == {
        "command": "broadcast_node.get_endpoint_count",
        "messageId": uuid4,
    }


async def test_get_endpoint_count_multicast(
    climate_radio_thermostat_ct100_plus, inovelli_switch, client, uuid4, mock_command
):
    """Test multicast_group.get_endpoint_count command."""
    node1 = climate_radio_thermostat_ct100_plus
    node2 = inovelli_switch
    ack_commands = mock_command(
        {"command": "multicast_group.get_endpoint_count"},
        {"count": 1},
    )

    assert await async_multicast_get_endpoint_count(client, [node1, node2]) == 1

    assert ack_commands[0] == {
        "command": "multicast_group.get_endpoint_count",
        "nodeIDs": [node1.node_id, node2.node_id],
        "messageId": uuid4,
    }


async def test_set_value_broadcast(client, driver, uuid4, mock_command):
    """Test broadcast_node.set_value command."""
    ack_commands = mock_command(
        {"command": "broadcast_node.set_value"},
        {"result": {"status": 255}},
    )

    result = await async_multicast_set_value(
        client, 1, {"commandClass": 1, "property": 1}
    )
    assert result.status == SetValueStatus.SUCCESS

    assert ack_commands[0] == {
        "command": "broadcast_node.set_value",
        "value": 1,
        "valueId": {"commandClass": 1, "property": 1},
        "options": None,
        "messageId": uuid4,
    }


async def test_set_value_multicast(
    climate_radio_thermostat_ct100_plus, inovelli_switch, client, uuid4, mock_command
):
    """Test multicast_group.set_value command."""
    node1 = climate_radio_thermostat_ct100_plus
    node2 = inovelli_switch
    ack_commands = mock_command(
        {"command": "multicast_group.set_value"},
        {"result": {"status": 255}},
    )

    result = await async_multicast_set_value(
        client, 1, {"commandClass": 112, "property": 1}, [node1, node2]
    )
    assert result.status == SetValueStatus.SUCCESS

    assert ack_commands[0] == {
        "command": "multicast_group.set_value",
        "nodeIDs": [node1.node_id, node2.node_id],
        "value": 1,
        "valueId": {"commandClass": 112, "property": 1},
        "options": None,
        "messageId": uuid4,
    }


async def test_set_value_multicast_basic(
    climate_radio_thermostat_ct100_plus, inovelli_switch, client, uuid4, mock_command
):
    """Test multicast_group.set_value command with Basic CC."""
    node1 = climate_radio_thermostat_ct100_plus
    node2 = inovelli_switch
    ack_commands = mock_command(
        {"command": "multicast_group.set_value"},
        {"result": {"status": 255}},
    )

    result = await async_multicast_set_value(
        client, 1, {"commandClass": 32, "property": "targetValue"}, [node1, node2]
    )
    assert result.status == SetValueStatus.SUCCESS

    assert ack_commands[0] == {
        "command": "multicast_group.set_value",
        "nodeIDs": [node1.node_id, node2.node_id],
        "value": 1,
        "valueId": {"commandClass": 32, "property": "targetValue"},
        "options": None,
        "messageId": uuid4,
    }


async def test_invoke_cc_api_broadcast(client, uuid4, mock_command):
    """Test broadcast_node.invoke_cc_api command."""
    ack_commands = mock_command(
        {"command": "broadcast_node.invoke_cc_api"},
        {"response": 1},
    )

    assert (
        await async_multicast_endpoint_invoke_cc_api(
            client, 1, 1, "test", ["test_args", "test_args2"]
        )
        == 1
    )

    assert ack_commands[0] == {
        "command": "broadcast_node.invoke_cc_api",
        "index": 1,
        "commandClass": 1,
        "methodName": "test",
        "args": ["test_args", "test_args2"],
        "messageId": uuid4,
    }


async def test_invoke_cc_api_multicast(
    climate_radio_thermostat_ct100_plus, inovelli_switch, client, uuid4, mock_command
):
    """Test multicast_group.invoke_cc_api command."""
    node1 = climate_radio_thermostat_ct100_plus
    node2 = inovelli_switch
    ack_commands = mock_command(
        {"command": "multicast_group.invoke_cc_api"},
        {"response": 1},
    )

    assert (
        await async_multicast_endpoint_invoke_cc_api(
            client, 1, 1, "test", ["test_args", "test_args2"], [node1, node2]
        )
        == 1
    )

    assert ack_commands[0] == {
        "command": "multicast_group.invoke_cc_api",
        "nodeIDs": [node1.node_id, node2.node_id],
        "index": 1,
        "commandClass": 1,
        "methodName": "test",
        "args": ["test_args", "test_args2"],
        "messageId": uuid4,
    }


async def test_supports_cc_api_broadcast(client, uuid4, mock_command):
    """Test broadcast_node.supports_cc_api command."""
    ack_commands = mock_command(
        {"command": "broadcast_node.supports_cc_api"},
        {"supported": True},
    )

    assert await async_multicast_endpoint_supports_cc_api(client, 1, 1)

    assert ack_commands[0] == {
        "command": "broadcast_node.supports_cc_api",
        "index": 1,
        "commandClass": 1,
        "messageId": uuid4,
    }


async def test_supports_cc_api_multicast(
    climate_radio_thermostat_ct100_plus, inovelli_switch, client, uuid4, mock_command
):
    """Test multicast_group.supports_cc_api command."""
    node1 = climate_radio_thermostat_ct100_plus
    node2 = inovelli_switch
    ack_commands = mock_command(
        {"command": "multicast_group.supports_cc_api"},
        {"supported": True},
    )

    assert await async_multicast_endpoint_supports_cc_api(client, 1, 1, [node1, node2])

    assert ack_commands[0] == {
        "command": "multicast_group.supports_cc_api",
        "nodeIDs": [node1.node_id, node2.node_id],
        "index": 1,
        "commandClass": 1,
        "messageId": uuid4,
    }


async def test_set_value_broadcast_missing_value(
    climate_radio_thermostat_ct100_plus, inovelli_switch, client, uuid4, mock_command
):
    """Test multicast_group.set_value command with value missing from a node."""
    ack_commands = mock_command(
        {"command": "broadcast_node.set_value"},
        {"result": {"status": 255}},
    )

    result = await async_multicast_set_value(
        client, 1, {"commandClass": 67, "property": "blah"}
    )
    assert result.status == SetValueStatus.SUCCESS

    assert ack_commands[0] == {
        "command": "broadcast_node.set_value",
        "value": 1,
        "valueId": {"commandClass": 67, "property": "blah"},
        "options": None,
        "messageId": uuid4,
    }