Skip to content

Commit

Permalink
Add water heater mode to sdk and all-clusters-app (#34351)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
5 people authored and pull[bot] committed Sep 3, 2024
1 parent 77df962 commit 1172251
Show file tree
Hide file tree
Showing 14 changed files with 510 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4582,6 +4582,56 @@ cluster EnergyEvseMode = 157 {
command ChangeToMode(ChangeToModeRequest): ChangeToModeResponse = 0;
}

/** Attributes and commands for selecting a mode from a list of supported options. */
cluster WaterHeaterMode = 158 {
revision 1;

enum ModeTag : enum16 {
kOff = 16384;
kManual = 16385;
kTimed = 16386;
}

bitmap Feature : bitmap32 {
kOnOff = 0x1;
}

struct ModeTagStruct {
optional vendor_id mfgCode = 0;
enum16 value = 1;
}

struct ModeOptionStruct {
char_string<64> label = 0;
int8u mode = 1;
ModeTagStruct modeTags[] = 2;
}

readonly attribute ModeOptionStruct supportedModes[] = 0;
readonly attribute int8u currentMode = 1;
attribute optional nullable int8u startUpMode = 2;
attribute optional nullable int8u onMode = 3;
readonly attribute command_id generatedCommandList[] = 65528;
readonly attribute command_id acceptedCommandList[] = 65529;
readonly attribute event_id eventList[] = 65530;
readonly attribute attrib_id attributeList[] = 65531;
readonly attribute bitmap32 featureMap = 65532;
readonly attribute int16u clusterRevision = 65533;

request struct ChangeToModeRequest {
int8u newMode = 0;
}

response struct ChangeToModeResponse = 1 {
enum8 status = 0;
optional char_string statusText = 1;
}

/** This command is used to change device modes.
On receipt of this command the device SHALL respond with a ChangeToModeResponse command. */
command ChangeToMode(ChangeToModeRequest): ChangeToModeResponse = 0;
}

/** Attributes and commands for selecting a mode from a list of supported options. */
provisional cluster DeviceEnergyManagementMode = 159 {
revision 1;
Expand Down Expand Up @@ -8479,6 +8529,22 @@ endpoint 1 {
handle command ChangeToModeResponse;
}

server cluster WaterHeaterMode {
callback attribute supportedModes;
callback attribute currentMode;
ram attribute startUpMode;
ram attribute onMode;
callback attribute generatedCommandList;
callback attribute acceptedCommandList;
callback attribute eventList;
callback attribute attributeList;
callback attribute featureMap;
ram attribute clusterRevision default = 1;

handle command ChangeToMode;
handle command ChangeToModeResponse;
}

server cluster DeviceEnergyManagementMode {
callback attribute supportedModes;
callback attribute currentMode;
Expand Down
188 changes: 188 additions & 0 deletions examples/all-clusters-app/all-clusters-common/all-clusters-app.zap
Original file line number Diff line number Diff line change
Expand Up @@ -14745,6 +14745,194 @@
}
]
},
{
"name": "Water Heater Mode",
"code": 158,
"mfgCode": null,
"define": "WATER_HEATER_MODE_CLUSTER",
"side": "server",
"enabled": 1,
"commands": [
{
"name": "ChangeToMode",
"code": 0,
"mfgCode": null,
"source": "client",
"isIncoming": 1,
"isEnabled": 1
},
{
"name": "ChangeToModeResponse",
"code": 1,
"mfgCode": null,
"source": "server",
"isIncoming": 0,
"isEnabled": 1
}
],
"attributes": [
{
"name": "SupportedModes",
"code": 0,
"mfgCode": null,
"side": "server",
"type": "array",
"included": 1,
"storageOption": "External",
"singleton": 0,
"bounded": 0,
"defaultValue": "",
"reportable": 1,
"minInterval": 1,
"maxInterval": 65534,
"reportableChange": 0
},
{
"name": "CurrentMode",
"code": 1,
"mfgCode": null,
"side": "server",
"type": "int8u",
"included": 1,
"storageOption": "External",
"singleton": 0,
"bounded": 0,
"defaultValue": "",
"reportable": 1,
"minInterval": 1,
"maxInterval": 65534,
"reportableChange": 0
},
{
"name": "StartUpMode",
"code": 2,
"mfgCode": null,
"side": "server",
"type": "int8u",
"included": 1,
"storageOption": "RAM",
"singleton": 0,
"bounded": 0,
"defaultValue": "",
"reportable": 1,
"minInterval": 1,
"maxInterval": 65534,
"reportableChange": 0
},
{
"name": "OnMode",
"code": 3,
"mfgCode": null,
"side": "server",
"type": "int8u",
"included": 1,
"storageOption": "RAM",
"singleton": 0,
"bounded": 0,
"defaultValue": "",
"reportable": 1,
"minInterval": 1,
"maxInterval": 65534,
"reportableChange": 0
},
{
"name": "GeneratedCommandList",
"code": 65528,
"mfgCode": null,
"side": "server",
"type": "array",
"included": 1,
"storageOption": "External",
"singleton": 0,
"bounded": 0,
"defaultValue": "",
"reportable": 1,
"minInterval": 1,
"maxInterval": 65534,
"reportableChange": 0
},
{
"name": "AcceptedCommandList",
"code": 65529,
"mfgCode": null,
"side": "server",
"type": "array",
"included": 1,
"storageOption": "External",
"singleton": 0,
"bounded": 0,
"defaultValue": "",
"reportable": 1,
"minInterval": 1,
"maxInterval": 65534,
"reportableChange": 0
},
{
"name": "EventList",
"code": 65530,
"mfgCode": null,
"side": "server",
"type": "array",
"included": 1,
"storageOption": "External",
"singleton": 0,
"bounded": 0,
"defaultValue": "",
"reportable": 1,
"minInterval": 1,
"maxInterval": 65534,
"reportableChange": 0
},
{
"name": "AttributeList",
"code": 65531,
"mfgCode": null,
"side": "server",
"type": "array",
"included": 1,
"storageOption": "External",
"singleton": 0,
"bounded": 0,
"defaultValue": "",
"reportable": 1,
"minInterval": 1,
"maxInterval": 65534,
"reportableChange": 0
},
{
"name": "FeatureMap",
"code": 65532,
"mfgCode": null,
"side": "server",
"type": "bitmap32",
"included": 1,
"storageOption": "External",
"singleton": 0,
"bounded": 0,
"defaultValue": "",
"reportable": 1,
"minInterval": 1,
"maxInterval": 65534,
"reportableChange": 0
},
{
"name": "ClusterRevision",
"code": 65533,
"mfgCode": null,
"side": "server",
"type": "int16u",
"included": 1,
"storageOption": "RAM",
"singleton": 0,
"bounded": 0,
"defaultValue": "1",
"reportable": 1,
"minInterval": 1,
"maxInterval": 65534,
"reportableChange": 0
}
]
},
{
"name": "Device Energy Management Mode",
"code": 159,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
*
* Copyright (c) 2023 Project CHIP Authors
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#pragma once

#include <app/clusters/mode-base-server/mode-base-server.h>
#include <app/util/config.h>
#include <cstring>
#include <utility>

namespace chip {
namespace app {
namespace Clusters {

namespace WaterHeaterMode {

constexpr uint8_t kModeOff = 0;
constexpr uint8_t kModeManual = 1;
constexpr uint8_t kModeTimed = 2;

/// This is an application level delegate to handle WaterHeaterMode commands according to the specific business logic.
class ExampleWaterHeaterModeDelegate : public ModeBase::Delegate
{
private:
using ModeTagStructType = detail::Structs::ModeTagStruct::Type;
ModeTagStructType modeTagsOff[1] = { { .value = to_underlying(ModeTag::kOff) } };
ModeTagStructType modeTagsManual[1] = { { .value = to_underlying(ModeTag::kManual) } };
ModeTagStructType modeTagsTimed[1] = { { .value = to_underlying(ModeTag::kTimed) } };

const detail::Structs::ModeOptionStruct::Type kModeOptions[3] = {
detail::Structs::ModeOptionStruct::Type{
.label = "Off"_span, .mode = kModeOff, .modeTags = DataModel::List<const ModeTagStructType>(modeTagsOff) },
detail::Structs::ModeOptionStruct::Type{
.label = "Manual"_span, .mode = kModeManual, .modeTags = DataModel::List<const ModeTagStructType>(modeTagsManual) },
detail::Structs::ModeOptionStruct::Type{
.label = "Timed"_span, .mode = kModeTimed, .modeTags = DataModel::List<const ModeTagStructType>(modeTagsTimed) }
};

CHIP_ERROR Init() override;
void HandleChangeToMode(uint8_t mode, ModeBase::Commands::ChangeToModeResponse::Type & response) override;

CHIP_ERROR GetModeLabelByIndex(uint8_t modeIndex, MutableCharSpan & label) override;
CHIP_ERROR GetModeValueByIndex(uint8_t modeIndex, uint8_t & value) override;
CHIP_ERROR GetModeTagsByIndex(uint8_t modeIndex, DataModel::List<ModeTagStructType> & tags) override;

public:
~ExampleWaterHeaterModeDelegate() override = default;
};

ModeBase::Instance * Instance();

void Shutdown();

} // namespace WaterHeaterMode

} // namespace Clusters
} // namespace app
} // namespace chip
Loading

0 comments on commit 1172251

Please sign in to comment.