forked from home-assistant-libs/zwave-js-server-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_value.py
More file actions
292 lines (250 loc) · 8.72 KB
/
test_value.py
File metadata and controls
292 lines (250 loc) · 8.72 KB
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
"""Test value model."""
from copy import deepcopy
from zwave_js_server.const import ConfigurationValueType, SetValueStatus
from zwave_js_server.model.node import Node
from zwave_js_server.model.value import (
ConfigurationValue,
ConfigurationValueFormat,
MetaDataType,
SetValueResult,
ValueDataType,
get_value_id_str,
)
def test_value_size(lock_schlage_be469):
"""Test the value size property for a value."""
node = lock_schlage_be469
zwave_value = node.values["20-112-0-3"]
assert zwave_value.metadata.value_size == 1
def test_buffer_dict(client, idl_101_lock_state):
"""Test that we handle buffer dictionary correctly."""
node_data = deepcopy(idl_101_lock_state)
node = Node(client, node_data)
value_id = get_value_id_str(node, 99, "userCode", 0, 3)
assert value_id == "26-99-0-userCode-3"
zwave_value = node.values[value_id]
assert zwave_value.metadata.type == "buffer"
assert zwave_value.value == "¤\x0eªV"
def test_unparseable_value(client, unparseable_json_string_value_state):
"""Test that we handle string value with unparseable format."""
node = Node(client, unparseable_json_string_value_state)
value_id = get_value_id_str(node, 99, "userCode", 0, 4)
assert value_id == "20-99-0-userCode-4"
assert value_id not in node.values
def test_allow_manual_entry(client, inovelli_switch_state):
"""Test that allow_manaual_entry works correctly."""
node = Node(client, inovelli_switch_state)
config_values = node.get_configuration_values()
value_id = get_value_id_str(node, 112, 8, 0, 255)
zwave_value = config_values[value_id]
assert zwave_value.configuration_value_type == ConfigurationValueType.MANUAL_ENTRY
value_id = get_value_id_str(node, 112, 8, 0, 65280)
zwave_value = config_values[value_id]
assert zwave_value.configuration_value_type == ConfigurationValueType.ENUMERATED
def test_stateful(lock_schlage_be469):
"""Test the stateful property for a value."""
node = lock_schlage_be469
zwave_value = node.values["20-112-0-3"]
assert not zwave_value.metadata.secret
def test_secret(lock_schlage_be469):
"""Test the secret property for a value."""
node = lock_schlage_be469
zwave_value = node.values["20-112-0-3"]
assert zwave_value.metadata.stateful
def test_configuration_value_type(inovelli_switch_state):
"""Test configuration value types."""
value = ConfigurationValue(
inovelli_switch_state,
ValueDataType(
commandClass=112,
property=8,
propertyName="8",
endpoint=0,
metadata=MetaDataType(
type="boolean",
max=2,
min=0,
allowManualEntry=True,
states={True: "On", False: "Off"},
),
),
)
assert value.configuration_value_type == ConfigurationValueType.MANUAL_ENTRY
value = ConfigurationValue(
inovelli_switch_state,
ValueDataType(
commandClass=112,
property=8,
propertyName="8",
endpoint=0,
metadata=MetaDataType(
type="boolean",
max=1,
min=0,
allowManualEntry=False,
states={True: "On", False: "Off"},
),
),
)
assert value.configuration_value_type == ConfigurationValueType.ENUMERATED
value = ConfigurationValue(
inovelli_switch_state,
ValueDataType(
commandClass=112,
property=8,
propertyName="8",
endpoint=0,
metadata=MetaDataType(
type="boolean",
max=1,
min=0,
allowManualEntry=False,
),
),
)
assert value.configuration_value_type == ConfigurationValueType.BOOLEAN
value = ConfigurationValue(
inovelli_switch_state,
ValueDataType(
commandClass=112,
property=8,
propertyName="8",
endpoint=0,
metadata=MetaDataType(
type="number",
max=2,
min=0,
allowManualEntry=True,
states={0: "On", 1: "Off"},
),
),
)
assert value.configuration_value_type == ConfigurationValueType.MANUAL_ENTRY
value = ConfigurationValue(
inovelli_switch_state,
ValueDataType(
commandClass=112,
property=8,
propertyName="8",
endpoint=0,
metadata=MetaDataType(
type="number",
max=1,
min=0,
allowManualEntry=False,
states={"1": "On", "0": "Off"},
),
),
)
assert value.configuration_value_type == ConfigurationValueType.ENUMERATED
value = ConfigurationValue(
inovelli_switch_state,
ValueDataType(
commandClass=112,
property=8,
propertyName="8",
endpoint=0,
metadata=MetaDataType(
type="number",
max=2,
min=0,
allowManualEntry=False,
),
),
)
assert value.configuration_value_type == ConfigurationValueType.RANGE
value = ConfigurationValue(
inovelli_switch_state,
ValueDataType(
commandClass=112,
property=8,
propertyName="8",
endpoint=0,
metadata=MetaDataType(
type="number",
allowManualEntry=False,
),
),
)
assert value.configuration_value_type == ConfigurationValueType.UNDEFINED
def test_set_value_result_str():
"""Test SetValueResult str."""
result = SetValueResult({"status": 255})
assert result.status == SetValueStatus.SUCCESS
assert str(result) == "Success"
result = SetValueResult({"status": 1, "remainingDuration": {"unit": "default"}})
assert result.status == SetValueStatus.WORKING
assert str(result) == "Working (default duration)"
result = SetValueResult(
{"status": 1, "remainingDuration": {"unit": "seconds", "value": 1}}
)
assert result.status == SetValueStatus.WORKING
assert str(result) == "Working (1 seconds)"
result = SetValueResult({"status": 3, "message": "test"})
assert result.status == SetValueStatus.ENDPOINT_NOT_FOUND
assert str(result) == "Endpoint Not Found: test"
result = SetValueResult({"status": 1, "remainingDuration": "unknown"})
assert result.status == SetValueStatus.WORKING
assert str(result) == "Working (unknown duration)"
def test_configuration_value_metadata(inovelli_switch_state):
"""Test configuration value specific metadata."""
value = ConfigurationValue(
inovelli_switch_state,
ValueDataType(
commandClass=112,
property=8,
propertyName="8",
endpoint=0,
metadata=MetaDataType(
type="boolean",
max=2,
min=0,
allowManualEntry=True,
states={True: "On", False: "Off"},
),
),
)
metadata = value.metadata
assert metadata.default is None
assert metadata.is_advanced is None
assert metadata.is_from_config is None
assert metadata.requires_re_inclusion is None
assert metadata.no_bulk_support is None
assert metadata.value_size is None
assert metadata.format is None
assert metadata.allowed is None
assert metadata.purpose is None
value = ConfigurationValue(
inovelli_switch_state,
ValueDataType(
commandClass=112,
property=8,
propertyName="8",
endpoint=0,
metadata=MetaDataType(
type="boolean",
max=2,
min=0,
allowManualEntry=True,
states={True: "On", False: "Off"},
default=2,
isAdvanced=True,
isFromConfig=True,
requiresReInclusion=True,
noBulkSupport=True,
valueSize=1,
format=0,
allowed=[{"value": 0}, {"from": 5, "to": 10, "step": 1}],
purpose="state_after_power_failure",
),
),
)
metadata = value.metadata
assert metadata.default == 2
assert metadata.is_advanced
assert metadata.is_from_config
assert metadata.requires_re_inclusion
assert metadata.no_bulk_support
assert metadata.value_size == 1
assert metadata.format == ConfigurationValueFormat.SIGNED_INTEGER
assert metadata.allowed == [{"value": 0}, {"from": 5, "to": 10, "step": 1}]
assert metadata.purpose == "state_after_power_failure"