forked from project-chip/connectedhomeip
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTC_EWATERHTRM_1_2.py
158 lines (130 loc) · 7.22 KB
/
TC_EWATERHTRM_1_2.py
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
#
# Copyright (c) 2024 Project CHIP Authors
# All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# === BEGIN CI TEST ARGUMENTS ===
# test-runner-runs: run1
# test-runner-run/run1/app: ${ALL_CLUSTERS_APP}
# test-runner-run/run1/factoryreset: True
# test-runner-run/run1/quiet: True
# test-runner-run/run1/app-args: --discriminator 1234 --KVS kvs1 --trace-to json:${TRACE_APP}.json --enable-key 000102030405060708090a0b0c0d0e0f
# test-runner-run/run1/script-args: --storage-path admin_storage.json --commissioning-method on-network --discriminator 1234 --passcode 20202021 --hex-arg enableKey:000102030405060708090a0b0c0d0e0f --endpoint 1 --trace-to json:${TRACE_TEST_JSON}.json --trace-to perfetto:${TRACE_TEST_PERFETTO}.perfetto
# === END CI TEST ARGUMENTS ===
import logging
import chip.clusters as Clusters
from matter_testing_support import MatterBaseTest, TestStep, async_test_body, default_matter_test_main
from mobly import asserts
class TC_EWATERHTRM_1_2(MatterBaseTest):
async def read_mode_attribute_expect_success(self, endpoint, attribute):
cluster = Clusters.Objects.WaterHeaterMode
return await self.read_single_attribute_check_success(endpoint=endpoint, cluster=cluster, attribute=attribute)
def desc_TC_EWATERHTRM_1_2(self) -> str:
return "[TC-EWATERHTRM-1.2] Cluster attributes with DUT as Server"
def steps_TC_EWATERHTRM_1_2(self) -> list[TestStep]:
steps = [
TestStep(1, "Commissioning, already done", is_commissioning=True),
TestStep(2, "Read the SupportedModes attribute"),
TestStep(3, "Read the CurrentMode attribute"),
]
return steps
def pics_TC_EWATERHTRM_1_2(self) -> list[str]:
pics = [
"EWATERHTRM.S",
]
return pics
@async_test_body
async def test_TC_EWATERHTRM_1_2(self):
endpoint = self.user_params.get("endpoint", 1)
attributes = Clusters.WaterHeaterMode.Attributes
self.step(1)
self.step(2)
supported_modes = await self.read_mode_attribute_expect_success(endpoint=endpoint, attribute=attributes.SupportedModes)
asserts.assert_greater_equal(len(supported_modes), 2,
"SupportedModes must have at least 2 entries!")
asserts.assert_less_equal(len(supported_modes), 255,
"SupportedModes must have at most 255 entries!")
modes = set([m.mode for m in supported_modes])
asserts.assert_equal(len(modes), len(supported_modes),
"SupportedModes must have unique mode values")
labels = set([m.label for m in supported_modes])
asserts.assert_equal(len(labels), len(supported_modes),
"SupportedModes must have unique mode label values")
# common mode tags
commonTags = {0x0: 'Auto',
0x1: 'Quick',
0x2: 'Quiet',
0x3: 'LowNoise',
0x4: 'LowEnergy',
0x5: 'Vacation',
0x6: 'Min',
0x7: 'Max',
0x8: 'Night',
0x9: 'Day'}
# derived cluster defined tags
# kUnknownEnumValue may not be defined
try:
derivedTags = [tag.value for tag in Clusters.WaterHeaterMode.Enums.ModeTag
if tag is not Clusters.WaterHeaterMode.Enums.ModeTag.kUnknownEnumValue]
except AttributeError:
derivedTags = Clusters.WaterHeaterMode.Enums.ModeTag
logging.info("Derived tags: %s" % derivedTags)
# According to the Mode spec:
# At least one entry in the SupportedModes attribute SHALL include the Manual mode tag in the ModeTags field list.
# At least one entry in the SupportedModes attribute SHALL include the Off mode tag in the ModeTags field list.
# An entry in the SupportedModes attribute that includes one of an Off, Manual, or Timed tag
# SHALL NOT also include an additional instance of any one of these tag types.
off_present = 0
manual_present = 0
timed_present = 0
for m in supported_modes:
off_manual_timed_present_in_this_mode = 0
for t in m.modeTags:
is_mfg = (0x8000 <= t.value and t.value <= 0xBFFF)
asserts.assert_true(t.value in commonTags.keys() or t.value in derivedTags or is_mfg,
"Found a SupportedModes entry with invalid mode tag value!")
if t.value == Clusters.WaterHeaterMode.Enums.ModeTag.kOff:
off_present += 1
off_manual_timed_present_in_this_mode += 1
logging.info(
"Found Off mode tag %s with tag value %s", m.mode, t.value)
if t.value == Clusters.WaterHeaterMode.Enums.ModeTag.kManual:
manual_present += 1
off_manual_timed_present_in_this_mode += 1
logging.info(
"Found Manual mode tag %s with tag value %s", m.mode, t.value)
if t.value == Clusters.WaterHeaterMode.Enums.ModeTag.kTimed:
timed_present += 1
off_manual_timed_present_in_this_mode += 1
logging.info(
"Found Timed mode tag %s with tag value %s", m.mode, t.value)
asserts.assert_less_equal(off_manual_timed_present_in_this_mode, 1,
f"The supported mode ({m.mode}) should only include one of OFF, MANUAL or TIMED, but includes more than one.")
asserts.assert_greater(off_present, 0,
"SupportedModes does not have an entry of Off(0x4000)")
asserts.assert_greater(manual_present, 0,
"SupportedModes does not have an entry of Manual(0x4001)")
asserts.assert_less_equal(off_present, 1,
"SupportedModes cannot have more than one instance of Off(0x4000)")
asserts.assert_less_equal(manual_present, 1,
"SupportedModes cannot have more than one instance of Manual(0x4001)")
asserts.assert_less_equal(timed_present, 1,
"SupportedModes cannot have more than one instance of Timed(0x4002)")
self.step(3)
current_mode = await self.read_mode_attribute_expect_success(endpoint=endpoint, attribute=attributes.CurrentMode)
logging.info("CurrentMode: %s" % current_mode)
asserts.assert_true(current_mode in modes,
"CurrentMode is not a supported mode!")
if __name__ == "__main__":
default_matter_test_main()