Skip to content

Commit 8d1491e

Browse files
committed
Add close at start of test
1 parent 847a8d7 commit 8d1491e

File tree

3 files changed

+38
-20
lines changed

3 files changed

+38
-20
lines changed

examples/all-clusters-app/linux/ValveControlDelegate.cpp

-3
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ DataModel::Nullable<chip::Percent> ValveControlDelegate::HandleOpenValve(DataMod
3838
// In this demo application, the transition is considered instant,
3939
// so current level is set to the requested level and current state is set to kOpen.
4040
currentLevel = sLevel;
41-
Attributes::CurrentState::Set(kValveEndpoint, ValveConfigurationAndControl::ValveStateEnum::kOpen);
4241

4342
return DataModel::Nullable<chip::Percent>(currentLevel);
4443
}
@@ -48,8 +47,6 @@ CHIP_ERROR ValveControlDelegate::HandleCloseValve()
4847
sLastOpenDuration = 0;
4948
sLevel = 0;
5049
ReturnErrorOnFailure(ValveConfigurationAndControl::UpdateCurrentLevel(kValveEndpoint, sLevel));
51-
ReturnErrorOnFailure(
52-
ValveConfigurationAndControl::UpdateCurrentState(kValveEndpoint, ValveConfigurationAndControl::ValveStateEnum::kClosed));
5350
ChipLogProgress(NotSpecified, "Valve closed");
5451
return CHIP_NO_ERROR;
5552
}

src/app/clusters/valve-configuration-and-control-server/valve-configuration-and-control-server.cpp

+16-5
Original file line numberDiff line numberDiff line change
@@ -360,9 +360,8 @@ CHIP_ERROR SetValveLevel(EndpointId ep, DataModel::Nullable<Percent> level, Data
360360
if (!isDelegateNull(delegate))
361361
{
362362
DataModel::Nullable<Percent> cLevel = delegate->HandleOpenValve(level);
363-
if (HasFeature(ep, ValveConfigurationAndControl::Feature::kLevel))
364-
{
365-
VerifyOrReturnError(Status::Success == CurrentLevel::Set(ep, cLevel), attribute_error);
363+
if (!cLevel.IsNull()) {
364+
UpdateCurrentLevel(ep, cLevel.Value());
366365
}
367366
}
368367
// start countdown
@@ -376,14 +375,26 @@ CHIP_ERROR UpdateCurrentLevel(EndpointId ep, Percent currentLevel)
376375
if (HasFeature(ep, ValveConfigurationAndControl::Feature::kLevel))
377376
{
378377
VerifyOrReturnError(Status::Success == CurrentLevel::Set(ep, currentLevel), CHIP_IM_GLOBAL_STATUS(ConstraintError));
379-
return CHIP_NO_ERROR;
380378
}
381-
return CHIP_IM_GLOBAL_STATUS(UnsupportedAttribute);
379+
DataModel::Nullable<Percent> targetLevel = DataModel::NullNullable;
380+
TargetLevel::Get(ep, targetLevel);
381+
if (!targetLevel.IsNull() && currentLevel == targetLevel.Value()) {
382+
targetLevel = DataModel::NullNullable;
383+
TargetLevel::Set(ep, targetLevel);
384+
UpdateCurrentState(ep, currentLevel == 0 ? ValveStateEnum::kClosed : ValveStateEnum::kOpen);
385+
}
386+
return CHIP_NO_ERROR;
382387
}
383388

384389
CHIP_ERROR UpdateCurrentState(EndpointId ep, ValveConfigurationAndControl::ValveStateEnum currentState)
385390
{
386391
VerifyOrReturnError(Status::Success == CurrentState::Set(ep, currentState), CHIP_IM_GLOBAL_STATUS(ConstraintError));
392+
DataModel::Nullable<ValveStateEnum> targetState = DataModel::NullNullable;
393+
TargetState::Get(ep, targetState);
394+
if (currentState == targetState.ValueOr(ValveStateEnum::kUnknownEnumValue)) {
395+
targetState = DataModel::NullNullable;
396+
TargetState::Set(ep, targetState);
397+
}
387398
emitValveStateChangedEvent(ep, currentState);
388399
return CHIP_NO_ERROR;
389400
}

src/python_testing/TC_VALCC_3_1.py

+22-12
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,15 @@ def steps_TC_VALCC_3_1(self) -> list[TestStep]:
4545
steps = [
4646
TestStep(1, "Commissioning, already done", is_commissioning=True),
4747
TestStep(2, "Set up a subscription to all attributes on the DUT"),
48-
TestStep(3, "Send Open command", "DUT returns SUCCESS"),
49-
TestStep(4, "Wait until TH receives and data report for TargetState set to NULL and an attribute report for CurrentState set to Open (ordering does not matter)",
48+
TestStep(3, "Send a close command to the DUT and wait until the CurrentState is closed", "DUT returns SUCCESS"),
49+
TestStep(4, "Send Open command", "DUT returns SUCCESS"),
50+
TestStep(5, "Wait until TH receives and data report for TargetState set to NULL and an attribute report for CurrentState set to Open (ordering does not matter)",
5051
"Expected attribute reports are received"),
51-
TestStep(5, "Read CurrentState and TargetState attribute", "CurrentState is Open, TargetState is NULL"),
52-
TestStep(6, "Send Close command", "DUT returns SUCCESS"),
53-
TestStep(7, "Wait until TH receives and data report for TargetState set to NULL and an attribute report for CurrentState set to Closed (ordering does not matter)",
52+
TestStep(6, "Read CurrentState and TargetState attribute", "CurrentState is Open, TargetState is NULL"),
53+
TestStep(7, "Send Close command", "DUT returns SUCCESS"),
54+
TestStep(8, "Wait until TH receives and data report for TargetState set to NULL and an attribute report for CurrentState set to Closed (ordering does not matter)",
5455
"Expected attribute reports are received"),
55-
TestStep(8, "Read CurrentState and TargetState attribute", "CurrentState is Closed, TargetState is NULL"),
56+
TestStep(9, "Read CurrentState and TargetState attribute", "CurrentState is Closed, TargetState is NULL"),
5657
]
5758
return steps
5859

@@ -70,32 +71,41 @@ async def test_TC_VALCC_3_1(self):
7071
await attribute_subscription.start(self.default_controller, self.dut_node_id, endpoint)
7172

7273
self.step(3)
73-
await self.send_single_cmd(cmd=Clusters.Objects.ValveConfigurationAndControl.Commands.Open(), endpoint=endpoint)
74+
await self.send_single_cmd(cmd=cluster.Commands.Close(), endpoint=endpoint)
75+
current_state_dut = await self.read_valcc_attribute_expect_success(endpoint=endpoint, attribute=attributes.CurrentState)
76+
if current_state_dut != cluster.Enums.ValveStateEnum.kClosed:
77+
current_state_closed = AttributeValue(
78+
endpoint_id=endpoint, attribute=attributes.CurrentState, value=cluster.Enums.ValveStateEnum.kClosed)
79+
attribute_subscription.await_all_final_values_reported(expected_final_values=[current_state_closed])
7480

7581
self.step(4)
82+
attribute_subscription.reset()
83+
await self.send_single_cmd(cmd=Clusters.Objects.ValveConfigurationAndControl.Commands.Open(), endpoint=endpoint)
84+
85+
self.step(5)
7686
# Wait until the current state is open and the target state is Null.
7787
# Wait for the entire duration of the test because this valve may be slow. The test will time out before this does. That's fine.
7888
timeout = self.matter_test_config.timeout if self.matter_test_config.timeout is not None else self.default_timeout
7989
expected_final_state = [AttributeValue(endpoint_id=endpoint, attribute=attributes.TargetState, value=NullValue), AttributeValue(
8090
endpoint_id=endpoint, attribute=attributes.CurrentState, value=cluster.Enums.ValveStateEnum.kOpen)]
8191
attribute_subscription.await_all_final_values_reported(expected_final_values=expected_final_state, timeout_sec=timeout)
8292

83-
self.step(5)
93+
self.step(6)
8494
target_state_dut = await self.read_valcc_attribute_expect_success(endpoint=endpoint, attribute=attributes.TargetState)
8595
current_state_dut = await self.read_valcc_attribute_expect_success(endpoint=endpoint, attribute=attributes.CurrentState)
8696
asserts.assert_equal(current_state_dut, cluster.Enums.ValveStateEnum.kOpen, "CurrentState is not open")
8797
asserts.assert_equal(target_state_dut, NullValue, "TargetState is not null")
8898

89-
self.step(6)
99+
self.step(7)
90100
attribute_subscription.reset()
91-
await self.send_single_cmd(cmd=Clusters.Objects.ValveConfigurationAndControl.Commands.Close(), endpoint=endpoint)
101+
await self.send_single_cmd(cmd=cluster.Commands.Close(), endpoint=endpoint)
92102

93-
self.step(7)
103+
self.step(8)
94104
expected_final_state = [AttributeValue(endpoint_id=endpoint, attribute=attributes.TargetState, value=NullValue), AttributeValue(
95105
endpoint_id=endpoint, attribute=attributes.CurrentState, value=cluster.Enums.ValveStateEnum.kClosed)]
96106
attribute_subscription.await_all_final_values_reported(expected_final_values=expected_final_state, timeout_sec=timeout)
97107

98-
self.step(8)
108+
self.step(9)
99109
target_state_dut = await self.read_valcc_attribute_expect_success(endpoint=endpoint, attribute=attributes.TargetState)
100110
current_state_dut = await self.read_valcc_attribute_expect_success(endpoint=endpoint, attribute=attributes.CurrentState)
101111
asserts.assert_equal(current_state_dut, cluster.Enums.ValveStateEnum.kClosed, "CurrentState is not closed")

0 commit comments

Comments
 (0)