Skip to content

Commit 109f400

Browse files
committed
Add close at start of test
1 parent 7d45e45 commit 109f400

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

@@ -76,32 +77,41 @@ async def test_TC_VALCC_3_1(self):
7677
await attribute_subscription.start(self.default_controller, self.dut_node_id, endpoint)
7778

7879
self.step(3)
79-
await self.send_single_cmd(cmd=Clusters.Objects.ValveConfigurationAndControl.Commands.Open(), endpoint=endpoint)
80+
await self.send_single_cmd(cmd=cluster.Commands.Close(), endpoint=endpoint)
81+
current_state_dut = await self.read_valcc_attribute_expect_success(endpoint=endpoint, attribute=attributes.CurrentState)
82+
if current_state_dut != cluster.Enums.ValveStateEnum.kClosed:
83+
current_state_closed = AttributeValue(
84+
endpoint_id=endpoint, attribute=attributes.CurrentState, value=cluster.Enums.ValveStateEnum.kClosed)
85+
attribute_subscription.await_all_final_values_reported(expected_final_values=[current_state_closed])
8086

8187
self.step(4)
88+
attribute_subscription.reset()
89+
await self.send_single_cmd(cmd=Clusters.Objects.ValveConfigurationAndControl.Commands.Open(), endpoint=endpoint)
90+
91+
self.step(5)
8292
# Wait until the current state is open and the target state is Null.
8393
# 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.
8494
timeout = self.matter_test_config.timeout if self.matter_test_config.timeout is not None else self.default_timeout
8595
expected_final_state = [AttributeValue(endpoint_id=endpoint, attribute=attributes.TargetState, value=NullValue), AttributeValue(
8696
endpoint_id=endpoint, attribute=attributes.CurrentState, value=cluster.Enums.ValveStateEnum.kOpen)]
8797
attribute_subscription.await_all_final_values_reported(expected_final_values=expected_final_state, timeout_sec=timeout)
8898

89-
self.step(5)
99+
self.step(6)
90100
target_state_dut = await self.read_valcc_attribute_expect_success(endpoint=endpoint, attribute=attributes.TargetState)
91101
current_state_dut = await self.read_valcc_attribute_expect_success(endpoint=endpoint, attribute=attributes.CurrentState)
92102
asserts.assert_equal(current_state_dut, cluster.Enums.ValveStateEnum.kOpen, "CurrentState is not open")
93103
asserts.assert_equal(target_state_dut, NullValue, "TargetState is not null")
94104

95-
self.step(6)
105+
self.step(7)
96106
attribute_subscription.reset()
97-
await self.send_single_cmd(cmd=Clusters.Objects.ValveConfigurationAndControl.Commands.Close(), endpoint=endpoint)
107+
await self.send_single_cmd(cmd=cluster.Commands.Close(), endpoint=endpoint)
98108

99-
self.step(7)
109+
self.step(8)
100110
expected_final_state = [AttributeValue(endpoint_id=endpoint, attribute=attributes.TargetState, value=NullValue), AttributeValue(
101111
endpoint_id=endpoint, attribute=attributes.CurrentState, value=cluster.Enums.ValveStateEnum.kClosed)]
102112
attribute_subscription.await_all_final_values_reported(expected_final_values=expected_final_state, timeout_sec=timeout)
103113

104-
self.step(8)
114+
self.step(9)
105115
target_state_dut = await self.read_valcc_attribute_expect_success(endpoint=endpoint, attribute=attributes.TargetState)
106116
current_state_dut = await self.read_valcc_attribute_expect_success(endpoint=endpoint, attribute=attributes.CurrentState)
107117
asserts.assert_equal(current_state_dut, cluster.Enums.ValveStateEnum.kClosed, "CurrentState is not closed")

0 commit comments

Comments
 (0)