Skip to content

Commit bbc0fb2

Browse files
Fix constraint check in thermostat cluster to follow the spec. (project-chip#36048)
* Fix constraint check in thermostat cluster to follow the spec. The cluster was excluding valid SystemMode values. * Add more test coverage, per review comment. * Removing incorrect copy/pasted comment. * Address one more review comment: need EnsureKnownEnumValue so that all unknown incoming values become the canonical one. * Turn off new test for chip-repl, since it does not support the needed functionality.
1 parent 9117e4d commit bbc0fb2

File tree

3 files changed

+94
-2
lines changed

3 files changed

+94
-2
lines changed

scripts/tests/chiptest/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ def _GetChipReplUnsupportedTests() -> Set[str]:
235235
"TestReadNoneSubscribeNone.yaml", # chip-repl does not support AnyCommands (07/27/2023)
236236
"Test_TC_IDM_1_2.yaml", # chip-repl does not support AnyCommands (19/07/2023)
237237
"Test_TC_BRBINFO_2_1.yaml", # chip-repl does not support AnyCommands (24/07/2024)
238+
"TestThermostat.yaml", # chip-repl does not support AnyCommands (14/10/2024)
238239
"TestIcdManagementCluster.yaml", # TODO(#30430): add ICD registration support in chip-repl
239240
"Test_TC_ICDM_3_4.yaml", # chip-repl does not support ICD registration
240241
# chip-repl and chip-tool disagree on what the YAML here should look like: https://github.com/project-chip/connectedhomeip/issues/29110

src/app/clusters/thermostat-server/thermostat-server.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -778,8 +778,8 @@ MatterThermostatClusterServerPreAttributeChangedCallback(const app::ConcreteAttr
778778
return Status::InvalidValue;
779779
}
780780
auto RequestedSystemMode = static_cast<SystemModeEnum>(*value);
781-
if (ControlSequenceOfOperation > ControlSequenceOfOperationEnum::kCoolingAndHeatingWithReheat ||
782-
RequestedSystemMode > SystemModeEnum::kFanOnly)
781+
if (EnsureKnownEnumValue(ControlSequenceOfOperation) == ControlSequenceOfOperationEnum::kUnknownEnumValue ||
782+
EnsureKnownEnumValue(RequestedSystemMode) == SystemModeEnum::kUnknownEnumValue)
783783
{
784784
return Status::InvalidValue;
785785
}
+91
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# Copyright (c) 2024 Project CHIP Authors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
name: Thermostat basic functionality tests
16+
17+
config:
18+
nodeId: 0x12344321
19+
cluster: "Thermostat"
20+
endpoint: 1
21+
22+
tests:
23+
- label: "Wait for the commissioned device to be retrieved"
24+
cluster: "DelayCommands"
25+
command: "WaitForCommissionee"
26+
arguments:
27+
values:
28+
- name: "nodeId"
29+
value: nodeId
30+
31+
- label: "Read current SystemMode value"
32+
command: "readAttribute"
33+
attribute: "SystemMode"
34+
response:
35+
saveAs: originalSystemMode
36+
37+
- label: "Try to set SystemMode to Sleep"
38+
command: "writeAttribute"
39+
attribute: "SystemMode"
40+
arguments:
41+
value: SystemModeEnum.Sleep
42+
43+
- label: "Check that the new value is set now"
44+
command: "readAttribute"
45+
attribute: "SystemMode"
46+
response:
47+
value: SystemModeEnum.Sleep
48+
49+
- label: "Try to set SystemMode to an invalid value"
50+
# Have to use WriteById, because normal write enforces valid values for enums.
51+
cluster: "AnyCommands"
52+
command: "WriteById"
53+
attribute: "SystemMode"
54+
arguments:
55+
values:
56+
- name: "ClusterId"
57+
value: 0x0201 # Thermostat
58+
- name: "AttributeId"
59+
value: 0x001C # SystemMode
60+
- name: "Value"
61+
# Note: At some point this might become a valid value,
62+
# and then this test will need to be adjusted, but that
63+
# seems fairly low-probability.
64+
value: 254
65+
response:
66+
error: CONSTRAINT_ERROR
67+
68+
- label: "Verify that WriteById would work correctly with a valid value"
69+
cluster: "AnyCommands"
70+
command: "WriteById"
71+
attribute: "SystemMode"
72+
arguments:
73+
values:
74+
- name: "ClusterId"
75+
value: 0x0201 # Thermostat
76+
- name: "AttributeId"
77+
value: 0x001C # SystemMode
78+
- name: "Value"
79+
value: 8 # SystemModeEnum.Dry
80+
81+
- label: "Check that the new value is set by id"
82+
command: "readAttribute"
83+
attribute: "SystemMode"
84+
response:
85+
value: SystemModeEnum.Dry
86+
87+
- label: "reset SystemMode to original value"
88+
command: "writeAttribute"
89+
attribute: "SystemMode"
90+
arguments:
91+
value: originalSystemMode

0 commit comments

Comments
 (0)