forked from project-chip/connectedhomeip
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTC_FAN_3_2.py
98 lines (74 loc) · 4.33 KB
/
TC_FAN_3_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
#
# 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.
#
# 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
# test-runner-run/run1/script-args: --storage-path admin_storage.json --commissioning-method on-network --discriminator 1234 --passcode 20202021 --trace-to json:${TRACE_TEST_JSON}.json --trace-to perfetto:${TRACE_TEST_PERFETTO}.perfetto
import logging
import time
import chip.clusters as Clusters
from chip.interaction_model import Status
from matter_testing_support import MatterBaseTest, async_test_body, default_matter_test_main
from mobly import asserts
logger = logging.getLogger(__name__)
class TC_FAN_3_2(MatterBaseTest):
async def read_fc_attribute_expect_success(self, endpoint, attribute):
cluster = Clusters.Objects.FanControl
return await self.read_single_attribute_check_success(endpoint=endpoint, cluster=cluster, attribute=attribute)
async def read_speed_setting(self, endpoint):
return await self.read_fc_attribute_expect_success(endpoint, Clusters.FanControl.Attributes.SpeedSetting)
async def read_speed_current(self, endpoint):
return await self.read_fc_attribute_expect_success(endpoint, Clusters.FanControl.Attributes.SpeedCurrent)
async def read_speed_max(self, endpoint):
return await self.read_fc_attribute_expect_success(endpoint, Clusters.FanControl.Attributes.SpeedMax)
async def write_speed_setting(self, endpoint, speed_setting) -> Status:
result = await self.default_controller.WriteAttribute(self.dut_node_id, [(endpoint, Clusters.FanControl.Attributes.SpeedSetting(speed_setting))])
return result[0].Status
def pics_TC_FAN_3_2(self) -> list[str]:
return ["FAN.S"]
@async_test_body
async def test_TC_FAN_3_2(self):
if not self.check_pics("FAN.S.F00"):
logger.info("Test skipped because PICS FAN.S.F00 is not set")
return
endpoint = self.user_params.get("endpoint", 1)
self.print_step(1, "Commissioning, already done")
self.print_step(2, "Read from the DUT the SpeedSetting attribute and store")
existing_speed_setting = await self.read_speed_setting(endpoint=endpoint)
self.print_step(3, "Read from the DUT the SpeedMax attribute and store")
speed_max = await self.read_speed_max(endpoint=endpoint)
self.print_step(4, "Write to the DUT the SpeedSetting attribute with value SpeedMax")
status = await self.write_speed_setting(endpoint=endpoint, speed_setting=speed_max)
status_ok = (status == Status.Success) or (status == Status.InvalidInState)
asserts.assert_true(status_ok, "SpeedSetting write did not return a value of Success or InvalidInState")
self.print_step(5, "After a few seconds, read from the DUT the SpeedSetting attribute")
time.sleep(3)
new_speed_setting = await self.read_speed_setting(endpoint=endpoint)
if status == Status.Success:
asserts.assert_equal(new_speed_setting, speed_max, "SpeedSetting is not equal to SpeedMax")
else:
asserts.assert_equal(new_speed_setting, existing_speed_setting, "SpeedSetting is not unchanged")
self.print_step(6, "Read from the DUT the SpeedCurrent attribute")
speed_current = await self.read_speed_current(endpoint=endpoint)
if status == Status.Success:
asserts.assert_equal(speed_current, speed_max, "SpeedCurrent is not equal to SpeedMax")
else:
asserts.assert_equal(speed_current, existing_speed_setting, "SpeedCurrent is not unchanged")
if __name__ == "__main__":
default_matter_test_main()