Skip to content

Commit 467a218

Browse files
authored
TC-LUNIT-3.1: Update test to be backwards compatible for 1.4.1 and earlier devices (#39225)
* TC-LUNIT-3.1: Update test to be backwards compatible for 1.4.1 and earlier devices * Fix some of the steps text * remove unused import * Update src/python_testing/TC_LUNIT_3_1.py
1 parent efe5c11 commit 467a218

File tree

1 file changed

+50
-27
lines changed

1 file changed

+50
-27
lines changed

src/python_testing/TC_LUNIT_3_1.py

Lines changed: 50 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@
3232
# quiet: true
3333
# === END CI TEST ARGUMENTS ===
3434

35-
import logging
36-
3735
import chip.clusters as Clusters
3836
from chip import ChipDeviceCtrl
3937
from chip.interaction_model import Status
@@ -51,27 +49,31 @@ async def write_lunit_temp_unit(self,
5149
endpoint,
5250
temp_unit,
5351
dev_ctrl: ChipDeviceCtrl = None,
54-
expected_status: Status = Status.Success) -> Status:
52+
expected_status: list[Status] = [Status.Success]) -> Status:
5553
if dev_ctrl is None:
5654
dev_ctrl = self.default_controller
5755
cluster = Clusters.Objects.UnitLocalization
5856
result = await dev_ctrl.WriteAttribute(self.dut_node_id, [(endpoint, cluster.Attributes.TemperatureUnit(temp_unit))])
5957
status = result[0].Status
60-
asserts.assert_equal(status, expected_status,
61-
f"TemperatureUnit write returned {status.name}; expected {expected_status.name}")
58+
asserts.assert_in(status, expected_status,
59+
f"TemperatureUnit write returned {status.name}; expected {[e.name for e in expected_status]}")
6260
return status
6361

6462
def desc_TC_LUNIT_3_1(self) -> str:
6563
return "[TC-LUNIT-2.1] Read and Write Unit Localization Cluster Attributes with DUT as Server"
6664

6765
def steps_TC_LUNIT_3_1(self) -> list[TestStep]:
6866
steps = [
69-
TestStep(0, "Commissioning, already done", is_commissioning=True),
67+
TestStep(0, "Commission DUT if required", is_commissioning=True),
7068
TestStep(1, "TH reads from the DUT the TemperatureUnit attribute"),
71-
TestStep(2, "TH reads from the DUT the SupportedTemperatureUnits attribute"),
72-
TestStep(3, "With each entry in SupportedUnitsList, TH writes to the DUT the TemperatureUnit attribute"),
73-
TestStep(4, "Construct a list with valid TempUnitEnum values that are not contained in SupportedUnitsList"),
74-
TestStep(5, "With each entry in UnsupportedUnitsList, TH writes to the DUT the TemperatureUnit attribute")
69+
TestStep(2, "If supported, TH reads from the DUT the SupportedTemperatureUnits attribute",
70+
"Verify the list length is between 2 and 3 inclusive.\nVerify that each entry in the list is a valid\nTempUnitEnum value and is unique."),
71+
TestStep(3, "If the SupportedTemperatureUnits is supported, TH creates a `supported` list With each entry in SupportedUnitsList. If SupportedTemperatureUnits is not supported, TH creates a `supported` list with Celsius and Fahrenheit. TH writes each entry in the `supported` list to the DUT the TemperatureUnit attribute", "Write is successful"),
72+
TestStep(4, "If the SupportedTemperatureUnits is supported, TH construct a list with valid TempUnitEnum values that are not contained in SupportedUnitsList"),
73+
TestStep(5, "if the SupportedTemperatureUnits is supported, With each entry in UnsupportedUnitsList, TH writes to the DUT the TemperatureUnit attribute",
74+
"Write returns CONSTRAINT_ERROR"),
75+
TestStep(6, "If SupportedTemperatureUnits is not supported, TH writes Kelvin",
76+
"Write either returns SUCCESS or CONSTRAINT_ERROR")
7577
]
7678
return steps
7779

@@ -88,14 +90,16 @@ async def test_TC_LUNIT_3_1(self):
8890
attributes = Clusters.UnitLocalization.Attributes
8991
features = await self.read_lunit_attribute_expect_success(endpoint=endpoint, attribute=attributes.FeatureMap)
9092
self.supports_TEMP = bool(features & Clusters.UnitLocalization.Bitmaps.Feature.kTemperatureUnit)
93+
attribute_list = await self.read_lunit_attribute_expect_success(endpoint=endpoint, attribute=attributes.AttributeList)
94+
has_supported_temperature_units = attributes.SupportedTemperatureUnits.attribute_id in attribute_list
9195

9296
# Step 0 - Commissioning, already done", is_commissioning=True)
9397

9498
self.step(0) # commissioning - already done
9599

96-
# Step 1 - TH reads from the DUT the TemperatureUnit attribute")
97-
self.step(1)
98100
if self.supports_TEMP:
101+
# Step 1 - TH reads from the DUT the TemperatureUnit attribute")
102+
self.step(1)
99103
temperature_unit = await self.read_lunit_attribute_expect_success(endpoint=endpoint, attribute=attributes.TemperatureUnit)
100104

101105
asserts.assert_greater_equal(temperature_unit, Clusters.Objects.UnitLocalization.Enums.TempUnitEnum.kFahrenheit,
@@ -105,11 +109,16 @@ async def test_TC_LUNIT_3_1(self):
105109

106110
# Step 2 - TH reads from the DUT the SupportedTemperatureUnits attribute")
107111
self.step(2)
108-
supported_temperature_units = await self.read_lunit_attribute_expect_success(endpoint=endpoint, attribute=attributes.SupportedTemperatureUnits)
109-
asserts.assert_greater_equal(len(supported_temperature_units), 2,
110-
"SupportedTemperatureUnits must have at least two entry in the list")
111-
asserts.assert_less_equal(len(supported_temperature_units), 3,
112-
"SupportedTemperatureUnits may have a maximum of three entries in the list")
112+
if has_supported_temperature_units:
113+
supported_temperature_units = await self.read_lunit_attribute_expect_success(endpoint=endpoint, attribute=attributes.SupportedTemperatureUnits)
114+
asserts.assert_greater_equal(len(supported_temperature_units), 2,
115+
"SupportedTemperatureUnits must have at least two entry in the list")
116+
asserts.assert_less_equal(len(supported_temperature_units), 3,
117+
"SupportedTemperatureUnits may have a maximum of three entries in the list")
118+
else:
119+
# Per CCB 4201, support Kelvin is not enforced for devices that predate SupportedTemperatureUnits
120+
supported_temperature_units = [Clusters.UnitLocalization.Enums.TempUnitEnum.kCelsius,
121+
Clusters.UnitLocalization.Enums.TempUnitEnum.kFahrenheit]
113122
for unit in supported_temperature_units:
114123
asserts.assert_greater_equal(unit, Clusters.Objects.UnitLocalization.Enums.TempUnitEnum.kFahrenheit,
115124
"Each entry in SupportedTemperatureUnits has to be Fahrenheit, Celsius or Kelvin")
@@ -119,24 +128,38 @@ async def test_TC_LUNIT_3_1(self):
119128
# Step 3 - With each entry in SupportedUnitsList, TH writes to the DUT the TemperatureUnit attribute")
120129
self.step(3)
121130
for unit in supported_temperature_units:
122-
await self.write_lunit_temp_unit(endpoint=endpoint, temp_unit=unit, expected_status=Status.Success)
131+
await self.write_lunit_temp_unit(endpoint=endpoint, temp_unit=unit, expected_status=[Status.Success])
123132

124133
# Step 4 - Construct a list with valid TempUnitEnum values that are not contained in
125134

126135
self.step(4)
127-
unsupported_temperature_units = []
128-
for unit in [Clusters.Objects.UnitLocalization.Enums.TempUnitEnum.kFahrenheit,
129-
Clusters.Objects.UnitLocalization.Enums.TempUnitEnum.kCelsius,
130-
Clusters.Objects.UnitLocalization.Enums.TempUnitEnum.kKelvin]:
131-
if unit not in supported_temperature_units:
132-
unsupported_temperature_units.append(unit)
136+
if has_supported_temperature_units:
137+
unsupported_temperature_units = []
138+
for unit in [Clusters.Objects.UnitLocalization.Enums.TempUnitEnum.kFahrenheit,
139+
Clusters.Objects.UnitLocalization.Enums.TempUnitEnum.kCelsius,
140+
Clusters.Objects.UnitLocalization.Enums.TempUnitEnum.kKelvin]:
141+
if unit not in supported_temperature_units:
142+
unsupported_temperature_units.append(unit)
143+
else:
144+
self.mark_current_step_skipped()
133145

134146
# Step 5 - With each entry in UnsupportedUnitsList, TH writes to the DUT the TemperatureUnit attribute")
135147
self.step(5)
136-
for unit in unsupported_temperature_units:
137-
await self.write_lunit_temp_unit(endpoint=endpoint, temp_unit=unit, expected_status=Status.ConstraintError)
148+
if has_supported_temperature_units:
149+
for unit in unsupported_temperature_units:
150+
await self.write_lunit_temp_unit(endpoint=endpoint, temp_unit=unit, expected_status=[Status.ConstraintError])
151+
else:
152+
self.mark_current_step_skipped()
153+
154+
self.step(6)
155+
if not has_supported_temperature_units:
156+
await self.write_lunit_temp_unit(endpoint=endpoint, temp_unit=unit, expected_status=[Status.Success, Status.ConstraintError])
157+
else:
158+
self.mark_current_step_skipped()
159+
138160
else:
139-
logging.info("no TEMP support - all Tests step skipped")
161+
self.skip_all_remaining_steps(1)
162+
return
140163

141164

142165
if __name__ == "__main__":

0 commit comments

Comments
 (0)