Skip to content

Commit ae25a08

Browse files
Fix TC-OCC-3.1 and TC-OCC-3.2 runtime errors (#34747)
* Fix TC-OCC-3.1 and TC-OCC-3.2 runtime errors - Refactor common code to be clearer in TC-OCC-3.1/3.2 - Fix runtime errors - Move `await_sequence_of_reports` to matter_testing_support.py - Make a helper to write attributes: `write_single_attribute` Fixes #34730 Testing done: - TC-OCC-3.1 and 3.2 no longer break locally (CI integration pending named pipe update in follow-up) - TC_SWTCH still works * Fix lint * restyle * poke styler * restyle
1 parent 6ba9655 commit ae25a08

File tree

4 files changed

+168
-167
lines changed

4 files changed

+168
-167
lines changed

src/python_testing/TC_OCC_3_1.py

+30-22
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616
#
1717
# === BEGIN CI TEST ARGUMENTS ===
1818
# test-runner-runs: run1
19-
# test-runner-run/run1/app: ${TYPE_OF_APP}
19+
# test-runner-run/run1/app: ${ALL_CLUSTERS_APP}
2020
# test-runner-run/run1/factoryreset: True
2121
# test-runner-run/run1/quiet: True
2222
# test-runner-run/run1/app-args: --discriminator 1234 --KVS kvs1 --trace-to json:${TRACE_APP}.json
23-
# 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
23+
# 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 --endpoint 1
2424
# === END CI TEST ARGUMENTS ===
2525
# There are CI issues to be followed up for the test cases below that implements manually controlling sensor device for
2626
# the occupancy state ON/OFF change.
@@ -29,19 +29,29 @@
2929

3030
import logging
3131
import time
32+
from typing import Any, Optional
3233

3334
import chip.clusters as Clusters
34-
from chip import ChipDeviceCtrl
3535
from chip.interaction_model import Status
3636
from matter_testing_support import MatterBaseTest, TestStep, async_test_body, default_matter_test_main
3737
from mobly import asserts
3838

3939

4040
class TC_OCC_3_1(MatterBaseTest):
41-
async def read_occ_attribute_expect_success(self, endpoint, attribute):
41+
async def read_occ_attribute_expect_success(self, attribute):
4242
cluster = Clusters.Objects.OccupancySensing
43+
endpoint = self.matter_test_config.endpoint
4344
return await self.read_single_attribute_check_success(endpoint=endpoint, cluster=cluster, attribute=attribute)
4445

46+
async def write_hold_time(self, hold_time: Optional[Any]) -> Status:
47+
dev_ctrl = self.default_controller
48+
node_id = self.dut_node_id
49+
endpoint = self.matter_test_config.endpoint
50+
51+
cluster = Clusters.OccupancySensing
52+
write_result = await dev_ctrl.WriteAttribute(node_id, [(endpoint, cluster.Attributes.HoldTime(hold_time))])
53+
return write_result[0].Status
54+
4555
def desc_TC_OCC_3_1(self) -> str:
4656
return "[TC-OCC-3.1] Primary functionality with server as DUT"
4757

@@ -63,58 +73,56 @@ def pics_TC_OCC_3_1(self) -> list[str]:
6373

6474
@async_test_body
6575
async def test_TC_OCC_3_1(self):
66-
67-
endpoint = self.user_params.get("endpoint", 1)
68-
node_id = self.matter_test_config.dut_node_ids[0]
6976
hold_time = 10 # 10 seconds for occupancy state hold time
7077

7178
self.step(1) # commissioning and getting cluster attribute list
72-
attributes = Clusters.OccupancySensing.Attributes
73-
attribute_list = await self.read_occ_attribute_expect_success(endpoint=endpoint, attribute=attributes.AttributeList)
79+
cluster = Clusters.OccupancySensing
80+
attributes = cluster.Attributes
81+
attribute_list = await self.read_occ_attribute_expect_success(attribute=attributes.AttributeList)
7482

75-
self.step(2)
76-
if attributes.HoldTime.attribute_id in attribute_list:
77-
# write 10 as a HoldTime attibute
78-
write_res = await ChipDeviceCtrl.WriteAttribute(node_id, [(endpoint, attributes.HoldTime(hold_time))])
79-
asserts.assert_equal(write_res[0].status, Status.Success, "Write HoldTime failed")
83+
has_hold_time = attributes.HoldTime.attribute_id in attribute_list
8084

85+
self.step(2)
86+
if has_hold_time:
87+
# write 10 as a HoldTime attribute
88+
await self.write_single_attribute(cluster.Attributes.HoldTime(hold_time))
8189
else:
8290
logging.info("No HoldTime attribute supports. Will test only occupancy attribute triggering functionality")
8391

8492
self.step(3)
8593
# check if Occupancy attribute is 0
86-
occupancy_dut = await self.read_occ_attribute_expect_success(endpoint=endpoint, attribute=attributes.Occupancy)
94+
occupancy_dut = await self.read_occ_attribute_expect_success(attribute=attributes.Occupancy)
8795

8896
# if occupancy is on, then wait until the sensor occupancy state is 0.
8997
if occupancy_dut == 1:
9098
# Don't trigger occupancy sensor to render occupancy attribute to 0
91-
if attributes.HoldTime.attribute_id in attribute_list:
92-
time.sleep(hold_time + 2) # add some extra 2 seconds to ensure hold time has passed.
99+
if has_hold_time:
100+
time.sleep(hold_time + 2.0) # add some extra 2 seconds to ensure hold time has passed.
93101
else: # a user wait until a sensor specific time to change occupancy attribute to 0. This is the case where the sensor doesn't support HoldTime.
94102
self.wait_for_user_input(
95103
prompt_msg="Type any letter and press ENTER after the sensor occupancy is detection ready state (occupancy attribute = 0)")
96104

97105
# check sensor occupancy state is 0 for the next test step
98-
occupancy_dut = await self.read_occ_attribute_expect_success(endpoint=endpoint, attribute=attributes.Occupancy)
106+
occupancy_dut = await self.read_occ_attribute_expect_success(attribute=attributes.Occupancy)
99107
asserts.assert_equal(occupancy_dut, 0, "Occupancy attribute is still 1.")
100108

101109
self.step(4)
102110
# Trigger occupancy sensor to change Occupancy attribute value to 1 => TESTER ACTION on DUT
103111
self.wait_for_user_input(prompt_msg="Type any letter and press ENTER after a sensor occupancy is triggered.")
104112

105113
# And then check if Occupancy attribute has changed.
106-
occupancy_dut = await self.read_occ_attribute_expect_success(endpoint=endpoint, attribute=attributes.Occupancy)
114+
occupancy_dut = await self.read_occ_attribute_expect_success(attribute=attributes.Occupancy)
107115
asserts.assert_equal(occupancy_dut, 1, "Occupancy state is not changed to 1")
108116

109117
self.step(5)
110118
# check if Occupancy attribute is back to 0 after HoldTime attribute period
111119
# Tester should not be triggering the sensor for this test step.
112-
if attributes.HoldTime.attribute_id in attribute_list:
120+
if has_hold_time:
113121

114122
# Start a timer based on HoldTime
115-
time.sleep(hold_time+2) # add some extra 2 seconds to ensure hold time has passed.
123+
time.sleep(hold_time + 2.0) # add some extra 2 seconds to ensure hold time has passed.
116124

117-
occupancy_dut = await self.read_occ_attribute_expect_success(endpoint=endpoint, attribute=attributes.Occupancy)
125+
occupancy_dut = await self.read_occ_attribute_expect_success(attribute=attributes.Occupancy)
118126
asserts.assert_equal(occupancy_dut, 0, "Occupancy state is not 0 after HoldTime period")
119127

120128
else:

0 commit comments

Comments
 (0)