Skip to content

Commit 7467abc

Browse files
authored
Update TC_TSTAT_4_2 to work with thermostats that do not have AUTO feature (#35579)
* Update TC_TSTAT_4_2 to work with thermostats that do not have AUTO feature * Python formatting for restyled
1 parent 236908d commit 7467abc

File tree

1 file changed

+53
-25
lines changed

1 file changed

+53
-25
lines changed

src/python_testing/TC_TSTAT_4_2.py

+53-25
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,16 @@ def get_available_scenario(self, presetTypes: list, presetScenarioCounts: map):
101101
return availableScenarios[0]
102102
return None
103103

104+
def make_preset(self, presetScenario, coolSetpoint, heatSetpoint, presetHandle=NullValue, name=None, builtIn=False):
105+
preset = cluster.Structs.PresetStruct(presetHandle=presetHandle, presetScenario=presetScenario, builtIn=builtIn)
106+
if self.check_pics("TSTAT.S.F00"):
107+
preset.heatingSetpoint = heatSetpoint
108+
if self.check_pics("TSTAT.S.F01"):
109+
preset.coolingSetpoint = coolSetpoint
110+
if name is not None:
111+
preset.name = name
112+
return preset
113+
104114
async def write_presets(self,
105115
endpoint,
106116
presets,
@@ -255,13 +265,29 @@ async def test_TC_TSTAT_4_2(self):
255265
presetTypes = []
256266
presetScenarioCounts = {}
257267
numberOfPresetsSupported = 0
258-
minHeatSetpointLimit = await self.read_single_attribute_check_success(endpoint=endpoint, cluster=cluster, attribute=cluster.Attributes.MinHeatSetpointLimit)
259-
maxHeatSetpointLimit = await self.read_single_attribute_check_success(endpoint=endpoint, cluster=cluster, attribute=cluster.Attributes.MaxHeatSetpointLimit)
260-
minCoolSetpointLimit = await self.read_single_attribute_check_success(endpoint=endpoint, cluster=cluster, attribute=cluster.Attributes.MinCoolSetpointLimit)
261-
maxCoolSetpointLimit = await self.read_single_attribute_check_success(endpoint=endpoint, cluster=cluster, attribute=cluster.Attributes.MaxCoolSetpointLimit)
268+
minHeatSetpointLimit = 700
269+
maxHeatSetpointLimit = 3000
270+
minCoolSetpointLimit = 1600
271+
maxCoolSetpointLimit = 3200
272+
273+
supportsHeat = self.check_pics("TSTAT.S.F00")
274+
supportsCool = self.check_pics("TSTAT.S.F01")
275+
supportsOccupancy = self.check_pics("TSTAT.S.F02")
276+
277+
occupied = True
262278

263-
asserts.assert_true(minHeatSetpointLimit < maxHeatSetpointLimit, "Heat setpoint range invalid")
264-
asserts.assert_true(minCoolSetpointLimit < maxCoolSetpointLimit, "Cool setpoint range invalid")
279+
if supportsHeat:
280+
minHeatSetpointLimit = await self.read_single_attribute_check_success(endpoint=endpoint, cluster=cluster, attribute=cluster.Attributes.MinHeatSetpointLimit)
281+
maxHeatSetpointLimit = await self.read_single_attribute_check_success(endpoint=endpoint, cluster=cluster, attribute=cluster.Attributes.MaxHeatSetpointLimit)
282+
asserts.assert_true(minHeatSetpointLimit < maxHeatSetpointLimit, "Heat setpoint range invalid")
283+
284+
if supportsCool:
285+
minCoolSetpointLimit = await self.read_single_attribute_check_success(endpoint=endpoint, cluster=cluster, attribute=cluster.Attributes.MinCoolSetpointLimit)
286+
maxCoolSetpointLimit = await self.read_single_attribute_check_success(endpoint=endpoint, cluster=cluster, attribute=cluster.Attributes.MaxCoolSetpointLimit)
287+
asserts.assert_true(minCoolSetpointLimit < maxCoolSetpointLimit, "Cool setpoint range invalid")
288+
289+
if supportsOccupancy:
290+
occupied = await self.read_single_attribute_check_success(endpoint=endpoint, cluster=cluster, attribute=cluster.Attributes.Occupancy) & 1
265291

266292
heatSetpoint = minHeatSetpointLimit + ((maxHeatSetpointLimit - minHeatSetpointLimit) / 2)
267293
coolSetpoint = minCoolSetpointLimit + ((maxCoolSetpointLimit - minCoolSetpointLimit) / 2)
@@ -296,8 +322,7 @@ async def test_TC_TSTAT_4_2(self):
296322
for preset in test_presets:
297323
preset.builtIn = NullValue
298324

299-
test_presets.append(cluster.Structs.PresetStruct(presetHandle=NullValue, presetScenario=availableScenario,
300-
coolingSetpoint=coolSetpoint, heatingSetpoint=heatSetpoint, builtIn=False))
325+
test_presets.append(self.make_preset(availableScenario, coolSetpoint, heatSetpoint))
301326

302327
await self.send_atomic_request_begin_command()
303328

@@ -334,8 +359,7 @@ async def test_TC_TSTAT_4_2(self):
334359
if len(builtInPresets) > 0:
335360
builtInPresets[0].builtIn = NullValue
336361

337-
test_presets.append(cluster.Structs.PresetStruct(presetHandle=NullValue, presetScenario=availableScenario,
338-
coolingSetpoint=coolSetpoint, heatingSetpoint=heatSetpoint, builtIn=False))
362+
test_presets.append(self.make_preset(availableScenario, coolSetpoint, heatSetpoint))
339363

340364
# Send the AtomicRequest begin command
341365
await self.send_atomic_request_begin_command()
@@ -415,7 +439,16 @@ async def test_TC_TSTAT_4_2(self):
415439
"Couldn't run test step 6 since there were no non-built-in presets to activate and delete")
416440

417441
# Write the occupied cooling setpoint to a different value
418-
await self.write_single_attribute(attribute_value=cluster.Attributes.OccupiedCoolingSetpoint(2300), endpoint_id=endpoint)
442+
if occupied:
443+
if supportsHeat:
444+
await self.write_single_attribute(attribute_value=cluster.Attributes.OccupiedHeatingSetpoint(heatSetpoint+1), endpoint_id=endpoint)
445+
elif supportsCool:
446+
await self.write_single_attribute(attribute_value=cluster.Attributes.OccupiedCoolingSetpoint(coolSetpoint+1), endpoint_id=endpoint)
447+
else:
448+
if supportsHeat:
449+
await self.write_single_attribute(attribute_value=cluster.Attributes.UnoccupiedHeatingSetpoint(heatSetpoint+1), endpoint_id=endpoint)
450+
elif supportsCool:
451+
await self.write_single_attribute(attribute_value=cluster.Attributes.UnoccupiedCoolingSetpoint(coolSetpoint+1), endpoint_id=endpoint)
419452

420453
activePresetHandle = await self.read_single_attribute_check_success(endpoint=endpoint, cluster=cluster, attribute=cluster.Attributes.ActivePresetHandle)
421454
logger.info(f"Rx'd ActivePresetHandle: {activePresetHandle}")
@@ -456,8 +489,7 @@ async def test_TC_TSTAT_4_2(self):
456489
await self.send_atomic_request_begin_command()
457490

458491
# Write to the presets attribute after adding a preset with builtIn set to True
459-
test_presets.append(cluster.Structs.PresetStruct(presetHandle=NullValue, presetScenario=availableScenario,
460-
coolingSetpoint=coolSetpoint, heatingSetpoint=heatSetpoint, builtIn=True))
492+
test_presets.append(self.make_preset(availableScenario, coolSetpoint, heatSetpoint, builtIn=True))
461493

462494
status = await self.write_presets(endpoint=endpoint, presets=test_presets, expected_status=Status.ConstraintError)
463495

@@ -475,8 +507,8 @@ async def test_TC_TSTAT_4_2(self):
475507

476508
# Write to the presets attribute after adding a preset with a preset handle that doesn't exist in Presets attribute
477509
test_presets = copy.deepcopy(current_presets)
478-
test_presets.append(cluster.Structs.PresetStruct(presetHandle=random.randbytes(16), presetScenario=cluster.Enums.PresetScenarioEnum.kWake,
479-
name="Wake", coolingSetpoint=coolSetpoint, heatingSetpoint=heatSetpoint, builtIn=True))
510+
test_presets.append(self.make_preset(cluster.Enums.PresetScenarioEnum.kWake, coolSetpoint,
511+
heatSetpoint, presetHandle=random.randbytes(16), name="Wake", builtIn=True))
480512

481513
status = await self.write_presets(endpoint=endpoint, presets=test_presets, expected_status=Status.NotFound)
482514

@@ -497,8 +529,8 @@ async def test_TC_TSTAT_4_2(self):
497529
await self.send_atomic_request_begin_command()
498530

499531
# Write to the presets attribute after adding a duplicate preset
500-
test_presets.append(cluster.Structs.PresetStruct(
501-
presetHandle=duplicatePreset.presetHandle, presetScenario=availableScenario, coolingSetpoint=coolSetpoint, heatingSetpoint=heatSetpoint, builtIn=False))
532+
test_presets.append(self.make_preset(availableScenario, coolSetpoint,
533+
heatSetpoint, presetHandle=duplicatePreset.presetHandle))
502534

503535
await self.write_presets(endpoint=endpoint, presets=test_presets, expected_status=Status.ConstraintError)
504536

@@ -540,8 +572,7 @@ async def test_TC_TSTAT_4_2(self):
540572
presets_without_name_support = list(preset for preset in test_presets if preset.presetScenario in availableScenarios)
541573

542574
if len(presets_without_name_support) == 0 and len(availableScenarios) > 0:
543-
new_preset = cluster.Structs.PresetStruct(presetHandle=NullValue, presetScenario=availableScenarios[0],
544-
coolingSetpoint=coolSetpoint, heatingSetpoint=heatSetpoint, builtIn=True)
575+
new_preset = self.make_preset(availableScenarios[0], coolSetpoint, heatSetpoint, builtIn=True)
545576
test_presets.append(new_preset)
546577
presets_without_name_support = [new_preset]
547578

@@ -570,8 +601,7 @@ async def test_TC_TSTAT_4_2(self):
570601

571602
# Write to the presets attribute with a new valid preset added
572603
test_presets = copy.deepcopy(current_presets)
573-
test_presets.append(cluster.Structs.PresetStruct(presetHandle=NullValue, presetScenario=availableScenario,
574-
coolingSetpoint=coolSetpoint, heatingSetpoint=heatSetpoint, builtIn=False))
604+
test_presets.append(self.make_preset(availableScenario, coolSetpoint, heatSetpoint))
575605

576606
# Send the AtomicRequest begin command
577607
await self.send_atomic_request_begin_command()
@@ -630,8 +660,7 @@ async def test_TC_TSTAT_4_2(self):
630660
presetScenario for presetScenario in cluster.Enums.PresetScenarioEnum if presetScenario not in supportedScenarios)
631661
if len(unavailableScenarios) > 0:
632662
test_presets = current_presets.copy()
633-
test_presets.append(cluster.Structs.PresetStruct(presetHandle=NullValue, presetScenario=unavailableScenarios[0],
634-
name="Preset", coolingSetpoint=coolSetpoint, heatingSetpoint=heatSetpoint, builtIn=False))
663+
test_presets.append(self.make_preset(unavailableScenarios[0], coolSetpoint, heatSetpoint, name="Preset"))
635664

636665
# Send the AtomicRequest begin command
637666
await self.send_atomic_request_begin_command()
@@ -664,8 +693,7 @@ async def test_TC_TSTAT_4_2(self):
664693
presetsAddedForScenario = presetsAddedForScenario + 1
665694

666695
while presetsAddedForScenario < presetType.numberOfPresets:
667-
testPresets.append(cluster.Structs.PresetStruct(presetHandle=NullValue, presetScenario=scenario,
668-
coolingSetpoint=coolSetpoint, heatingSetpoint=heatSetpoint, builtIn=False))
696+
testPresets.append(self.make_preset(scenario, coolSetpoint, heatSetpoint))
669697
presetsAddedForScenario = presetsAddedForScenario + 1
670698

671699
# Send the AtomicRequest begin command

0 commit comments

Comments
 (0)