Skip to content

Commit ce0505c

Browse files
PeterC1965restyled-commitsjamesharrowandy31415
authored andcommitted
Add water heater mode to sdk and all-clusters-app (project-chip#34351)
* Add water heater mode cluster * Get all-clusters-app building with water-heater-mode * Restyled by clang-format * Added call to WaterHeaterMode::Shutdown() to fix IntrusiveList not being freed at exit. * Added missing #include "water-heater-mode.h" to main-common.cpp * Regenerated files * Update following review comments from Andrei Litvin * Fix compilation error * Restyled by clang-format * Update after review comment from Boris * WaterHeaterMode moved to future section * Update examples/all-clusters-app/all-clusters-common/include/water-heater-mode.h Co-authored-by: Andrei Litvin <andy314@gmail.com> * Address final set of review comments from Andrei --------- Co-authored-by: Restyled.io <commits@restyled.io> Co-authored-by: jamesharrow <93921463+jamesharrow@users.noreply.github.com> Co-authored-by: James Harrow <james.harrow@gmail.com> Co-authored-by: Andrei Litvin <andy314@gmail.com>
1 parent de2c212 commit ce0505c

File tree

14 files changed

+510
-30
lines changed

14 files changed

+510
-30
lines changed

examples/all-clusters-app/all-clusters-common/all-clusters-app.matter

+66
Original file line numberDiff line numberDiff line change
@@ -4582,6 +4582,56 @@ cluster EnergyEvseMode = 157 {
45824582
command ChangeToMode(ChangeToModeRequest): ChangeToModeResponse = 0;
45834583
}
45844584

4585+
/** Attributes and commands for selecting a mode from a list of supported options. */
4586+
cluster WaterHeaterMode = 158 {
4587+
revision 1;
4588+
4589+
enum ModeTag : enum16 {
4590+
kOff = 16384;
4591+
kManual = 16385;
4592+
kTimed = 16386;
4593+
}
4594+
4595+
bitmap Feature : bitmap32 {
4596+
kOnOff = 0x1;
4597+
}
4598+
4599+
struct ModeTagStruct {
4600+
optional vendor_id mfgCode = 0;
4601+
enum16 value = 1;
4602+
}
4603+
4604+
struct ModeOptionStruct {
4605+
char_string<64> label = 0;
4606+
int8u mode = 1;
4607+
ModeTagStruct modeTags[] = 2;
4608+
}
4609+
4610+
readonly attribute ModeOptionStruct supportedModes[] = 0;
4611+
readonly attribute int8u currentMode = 1;
4612+
attribute optional nullable int8u startUpMode = 2;
4613+
attribute optional nullable int8u onMode = 3;
4614+
readonly attribute command_id generatedCommandList[] = 65528;
4615+
readonly attribute command_id acceptedCommandList[] = 65529;
4616+
readonly attribute event_id eventList[] = 65530;
4617+
readonly attribute attrib_id attributeList[] = 65531;
4618+
readonly attribute bitmap32 featureMap = 65532;
4619+
readonly attribute int16u clusterRevision = 65533;
4620+
4621+
request struct ChangeToModeRequest {
4622+
int8u newMode = 0;
4623+
}
4624+
4625+
response struct ChangeToModeResponse = 1 {
4626+
enum8 status = 0;
4627+
optional char_string statusText = 1;
4628+
}
4629+
4630+
/** This command is used to change device modes.
4631+
On receipt of this command the device SHALL respond with a ChangeToModeResponse command. */
4632+
command ChangeToMode(ChangeToModeRequest): ChangeToModeResponse = 0;
4633+
}
4634+
45854635
/** Attributes and commands for selecting a mode from a list of supported options. */
45864636
provisional cluster DeviceEnergyManagementMode = 159 {
45874637
revision 1;
@@ -8479,6 +8529,22 @@ endpoint 1 {
84798529
handle command ChangeToModeResponse;
84808530
}
84818531

8532+
server cluster WaterHeaterMode {
8533+
callback attribute supportedModes;
8534+
callback attribute currentMode;
8535+
ram attribute startUpMode;
8536+
ram attribute onMode;
8537+
callback attribute generatedCommandList;
8538+
callback attribute acceptedCommandList;
8539+
callback attribute eventList;
8540+
callback attribute attributeList;
8541+
callback attribute featureMap;
8542+
ram attribute clusterRevision default = 1;
8543+
8544+
handle command ChangeToMode;
8545+
handle command ChangeToModeResponse;
8546+
}
8547+
84828548
server cluster DeviceEnergyManagementMode {
84838549
callback attribute supportedModes;
84848550
callback attribute currentMode;

examples/all-clusters-app/all-clusters-common/all-clusters-app.zap

+188
Original file line numberDiff line numberDiff line change
@@ -14745,6 +14745,194 @@
1474514745
}
1474614746
]
1474714747
},
14748+
{
14749+
"name": "Water Heater Mode",
14750+
"code": 158,
14751+
"mfgCode": null,
14752+
"define": "WATER_HEATER_MODE_CLUSTER",
14753+
"side": "server",
14754+
"enabled": 1,
14755+
"commands": [
14756+
{
14757+
"name": "ChangeToMode",
14758+
"code": 0,
14759+
"mfgCode": null,
14760+
"source": "client",
14761+
"isIncoming": 1,
14762+
"isEnabled": 1
14763+
},
14764+
{
14765+
"name": "ChangeToModeResponse",
14766+
"code": 1,
14767+
"mfgCode": null,
14768+
"source": "server",
14769+
"isIncoming": 0,
14770+
"isEnabled": 1
14771+
}
14772+
],
14773+
"attributes": [
14774+
{
14775+
"name": "SupportedModes",
14776+
"code": 0,
14777+
"mfgCode": null,
14778+
"side": "server",
14779+
"type": "array",
14780+
"included": 1,
14781+
"storageOption": "External",
14782+
"singleton": 0,
14783+
"bounded": 0,
14784+
"defaultValue": "",
14785+
"reportable": 1,
14786+
"minInterval": 1,
14787+
"maxInterval": 65534,
14788+
"reportableChange": 0
14789+
},
14790+
{
14791+
"name": "CurrentMode",
14792+
"code": 1,
14793+
"mfgCode": null,
14794+
"side": "server",
14795+
"type": "int8u",
14796+
"included": 1,
14797+
"storageOption": "External",
14798+
"singleton": 0,
14799+
"bounded": 0,
14800+
"defaultValue": "",
14801+
"reportable": 1,
14802+
"minInterval": 1,
14803+
"maxInterval": 65534,
14804+
"reportableChange": 0
14805+
},
14806+
{
14807+
"name": "StartUpMode",
14808+
"code": 2,
14809+
"mfgCode": null,
14810+
"side": "server",
14811+
"type": "int8u",
14812+
"included": 1,
14813+
"storageOption": "RAM",
14814+
"singleton": 0,
14815+
"bounded": 0,
14816+
"defaultValue": "",
14817+
"reportable": 1,
14818+
"minInterval": 1,
14819+
"maxInterval": 65534,
14820+
"reportableChange": 0
14821+
},
14822+
{
14823+
"name": "OnMode",
14824+
"code": 3,
14825+
"mfgCode": null,
14826+
"side": "server",
14827+
"type": "int8u",
14828+
"included": 1,
14829+
"storageOption": "RAM",
14830+
"singleton": 0,
14831+
"bounded": 0,
14832+
"defaultValue": "",
14833+
"reportable": 1,
14834+
"minInterval": 1,
14835+
"maxInterval": 65534,
14836+
"reportableChange": 0
14837+
},
14838+
{
14839+
"name": "GeneratedCommandList",
14840+
"code": 65528,
14841+
"mfgCode": null,
14842+
"side": "server",
14843+
"type": "array",
14844+
"included": 1,
14845+
"storageOption": "External",
14846+
"singleton": 0,
14847+
"bounded": 0,
14848+
"defaultValue": "",
14849+
"reportable": 1,
14850+
"minInterval": 1,
14851+
"maxInterval": 65534,
14852+
"reportableChange": 0
14853+
},
14854+
{
14855+
"name": "AcceptedCommandList",
14856+
"code": 65529,
14857+
"mfgCode": null,
14858+
"side": "server",
14859+
"type": "array",
14860+
"included": 1,
14861+
"storageOption": "External",
14862+
"singleton": 0,
14863+
"bounded": 0,
14864+
"defaultValue": "",
14865+
"reportable": 1,
14866+
"minInterval": 1,
14867+
"maxInterval": 65534,
14868+
"reportableChange": 0
14869+
},
14870+
{
14871+
"name": "EventList",
14872+
"code": 65530,
14873+
"mfgCode": null,
14874+
"side": "server",
14875+
"type": "array",
14876+
"included": 1,
14877+
"storageOption": "External",
14878+
"singleton": 0,
14879+
"bounded": 0,
14880+
"defaultValue": "",
14881+
"reportable": 1,
14882+
"minInterval": 1,
14883+
"maxInterval": 65534,
14884+
"reportableChange": 0
14885+
},
14886+
{
14887+
"name": "AttributeList",
14888+
"code": 65531,
14889+
"mfgCode": null,
14890+
"side": "server",
14891+
"type": "array",
14892+
"included": 1,
14893+
"storageOption": "External",
14894+
"singleton": 0,
14895+
"bounded": 0,
14896+
"defaultValue": "",
14897+
"reportable": 1,
14898+
"minInterval": 1,
14899+
"maxInterval": 65534,
14900+
"reportableChange": 0
14901+
},
14902+
{
14903+
"name": "FeatureMap",
14904+
"code": 65532,
14905+
"mfgCode": null,
14906+
"side": "server",
14907+
"type": "bitmap32",
14908+
"included": 1,
14909+
"storageOption": "External",
14910+
"singleton": 0,
14911+
"bounded": 0,
14912+
"defaultValue": "",
14913+
"reportable": 1,
14914+
"minInterval": 1,
14915+
"maxInterval": 65534,
14916+
"reportableChange": 0
14917+
},
14918+
{
14919+
"name": "ClusterRevision",
14920+
"code": 65533,
14921+
"mfgCode": null,
14922+
"side": "server",
14923+
"type": "int16u",
14924+
"included": 1,
14925+
"storageOption": "RAM",
14926+
"singleton": 0,
14927+
"bounded": 0,
14928+
"defaultValue": "1",
14929+
"reportable": 1,
14930+
"minInterval": 1,
14931+
"maxInterval": 65534,
14932+
"reportableChange": 0
14933+
}
14934+
]
14935+
},
1474814936
{
1474914937
"name": "Device Energy Management Mode",
1475014938
"code": 159,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*
2+
*
3+
* Copyright (c) 2023 Project CHIP Authors
4+
* All rights reserved.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
#pragma once
20+
21+
#include <app/clusters/mode-base-server/mode-base-server.h>
22+
#include <app/util/config.h>
23+
#include <cstring>
24+
#include <utility>
25+
26+
namespace chip {
27+
namespace app {
28+
namespace Clusters {
29+
30+
namespace WaterHeaterMode {
31+
32+
constexpr uint8_t kModeOff = 0;
33+
constexpr uint8_t kModeManual = 1;
34+
constexpr uint8_t kModeTimed = 2;
35+
36+
/// This is an application level delegate to handle WaterHeaterMode commands according to the specific business logic.
37+
class ExampleWaterHeaterModeDelegate : public ModeBase::Delegate
38+
{
39+
private:
40+
using ModeTagStructType = detail::Structs::ModeTagStruct::Type;
41+
ModeTagStructType modeTagsOff[1] = { { .value = to_underlying(ModeTag::kOff) } };
42+
ModeTagStructType modeTagsManual[1] = { { .value = to_underlying(ModeTag::kManual) } };
43+
ModeTagStructType modeTagsTimed[1] = { { .value = to_underlying(ModeTag::kTimed) } };
44+
45+
const detail::Structs::ModeOptionStruct::Type kModeOptions[3] = {
46+
detail::Structs::ModeOptionStruct::Type{
47+
.label = "Off"_span, .mode = kModeOff, .modeTags = DataModel::List<const ModeTagStructType>(modeTagsOff) },
48+
detail::Structs::ModeOptionStruct::Type{
49+
.label = "Manual"_span, .mode = kModeManual, .modeTags = DataModel::List<const ModeTagStructType>(modeTagsManual) },
50+
detail::Structs::ModeOptionStruct::Type{
51+
.label = "Timed"_span, .mode = kModeTimed, .modeTags = DataModel::List<const ModeTagStructType>(modeTagsTimed) }
52+
};
53+
54+
CHIP_ERROR Init() override;
55+
void HandleChangeToMode(uint8_t mode, ModeBase::Commands::ChangeToModeResponse::Type & response) override;
56+
57+
CHIP_ERROR GetModeLabelByIndex(uint8_t modeIndex, MutableCharSpan & label) override;
58+
CHIP_ERROR GetModeValueByIndex(uint8_t modeIndex, uint8_t & value) override;
59+
CHIP_ERROR GetModeTagsByIndex(uint8_t modeIndex, DataModel::List<ModeTagStructType> & tags) override;
60+
61+
public:
62+
~ExampleWaterHeaterModeDelegate() override = default;
63+
};
64+
65+
ModeBase::Instance * Instance();
66+
67+
void Shutdown();
68+
69+
} // namespace WaterHeaterMode
70+
71+
} // namespace Clusters
72+
} // namespace app
73+
} // namespace chip

0 commit comments

Comments
 (0)