Skip to content

Commit

Permalink
Add support to all clusters app to support Thermostat presets attribu…
Browse files Browse the repository at this point in the history
…tes and commands
  • Loading branch information
nivi-apple committed Jul 31, 2024
1 parent 50fb5cc commit fcb85a5
Show file tree
Hide file tree
Showing 6 changed files with 470 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8813,14 +8813,23 @@ endpoint 1 {
ram attribute minSetpointDeadBand default = 0x19;
ram attribute controlSequenceOfOperation default = 0x04;
ram attribute systemMode default = 0x01;
callback attribute presetTypes;
ram attribute numberOfPresets default = 0;
ram attribute activePresetHandle;
callback attribute presets;
ram attribute presetsSchedulesEditable;
callback attribute generatedCommandList;
callback attribute acceptedCommandList;
callback attribute eventList;
callback attribute attributeList;
ram attribute featureMap default = 0x0023;
ram attribute featureMap default = 0x0123;
ram attribute clusterRevision default = 6;

handle command SetpointRaiseLower;
handle command SetActivePresetRequest;
handle command StartPresetsSchedulesEditRequest;
handle command CancelPresetsSchedulesEditRequest;
handle command CommitPresetsSchedulesRequest;
}

server cluster FanControl {
Expand Down
116 changes: 114 additions & 2 deletions examples/all-clusters-app/all-clusters-common/all-clusters-app.zap
Original file line number Diff line number Diff line change
Expand Up @@ -16393,6 +16393,38 @@
"source": "client",
"isIncoming": 1,
"isEnabled": 1
},
{
"name": "SetActivePresetRequest",
"code": 6,
"mfgCode": null,
"source": "client",
"isIncoming": 1,
"isEnabled": 1
},
{
"name": "StartPresetsSchedulesEditRequest",
"code": 7,
"mfgCode": null,
"source": "client",
"isIncoming": 1,
"isEnabled": 1
},
{
"name": "CancelPresetsSchedulesEditRequest",
"code": 8,
"mfgCode": null,
"source": "client",
"isIncoming": 1,
"isEnabled": 1
},
{
"name": "CommitPresetsSchedulesRequest",
"code": 9,
"mfgCode": null,
"source": "client",
"isIncoming": 1,
"isEnabled": 1
}
],
"attributes": [
Expand Down Expand Up @@ -16636,6 +16668,86 @@
"maxInterval": 65344,
"reportableChange": 0
},
{
"name": "PresetTypes",
"code": 72,
"mfgCode": null,
"side": "server",
"type": "array",
"included": 1,
"storageOption": "External",
"singleton": 0,
"bounded": 0,
"defaultValue": "",
"reportable": 1,
"minInterval": 1,
"maxInterval": 65534,
"reportableChange": 0
},
{
"name": "NumberOfPresets",
"code": 74,
"mfgCode": null,
"side": "server",
"type": "int8u",
"included": 1,
"storageOption": "RAM",
"singleton": 0,
"bounded": 0,
"defaultValue": "0",
"reportable": 1,
"minInterval": 1,
"maxInterval": 65534,
"reportableChange": 0
},
{
"name": "ActivePresetHandle",
"code": 78,
"mfgCode": null,
"side": "server",
"type": "octet_string",
"included": 1,
"storageOption": "RAM",
"singleton": 0,
"bounded": 0,
"defaultValue": "",
"reportable": 1,
"minInterval": 1,
"maxInterval": 65534,
"reportableChange": 0
},
{
"name": "Presets",
"code": 80,
"mfgCode": null,
"side": "server",
"type": "array",
"included": 1,
"storageOption": "External",
"singleton": 0,
"bounded": 0,
"defaultValue": "",
"reportable": 1,
"minInterval": 1,
"maxInterval": 65534,
"reportableChange": 0
},
{
"name": "PresetsSchedulesEditable",
"code": 82,
"mfgCode": null,
"side": "server",
"type": "boolean",
"included": 1,
"storageOption": "RAM",
"singleton": 0,
"bounded": 0,
"defaultValue": "",
"reportable": 1,
"minInterval": 1,
"maxInterval": 65534,
"reportableChange": 0
},
{
"name": "GeneratedCommandList",
"code": 65528,
Expand Down Expand Up @@ -16710,7 +16822,7 @@
"storageOption": "RAM",
"singleton": 0,
"bounded": 0,
"defaultValue": "0x0023",
"defaultValue": "0x0123",
"reportable": 1,
"minInterval": 0,
"maxInterval": 65344,
Expand Down Expand Up @@ -26554,4 +26666,4 @@
"parentEndpointIdentifier": null
}
]
}
}
1 change: 1 addition & 0 deletions examples/all-clusters-app/linux/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ source_set("chip-all-clusters-common") {
"${chip_root}/examples/all-clusters-app/all-clusters-common/src/tcc-mode.cpp",
"${chip_root}/examples/all-clusters-app/all-clusters-common/src/water-heater-mode.cpp",
"${chip_root}/examples/all-clusters-app/linux/diagnostic-logs-provider-delegate-impl.cpp",
"${chip_root}/examples/all-clusters-app/linux/thermostat-delegate-impl.cpp",
"${chip_root}/examples/energy-management-app/energy-management-common/src/ChargingTargetsMemMgr.cpp",
"${chip_root}/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementDelegateImpl.cpp",
"${chip_root}/examples/energy-management-app/energy-management-common/src/DeviceEnergyManagementManager.cpp",
Expand Down
100 changes: 100 additions & 0 deletions examples/all-clusters-app/linux/include/thermostat-delegate-impl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/*
*
* Copyright (c) 2024 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/thermostat-server/thermostat-delegate.h>

namespace chip {
namespace app {
namespace Clusters {
namespace Thermostat {

/**
* The ThermostatDelegate class serves as the instance delegate for storing Presets related information and providing it to the
* Thermostat server code. It also manages the presets attribute and provides methods to write to presets, edit presets, maintain a
* pending presets list and either commit the presets when requested or discard the changes. It also provides APIs to get and set
* the attribute values.
*
*/

static constexpr uint8_t kMaxNumberOfPresetTypes = 6;

// TODO: #34556 Support multiple presets of each type.
// We will support only one preset of each preset type.
static constexpr uint8_t kMaxNumberOfPresetsOfEachType = 1;

class ThermostatDelegate : public Delegate
{
public:
static inline ThermostatDelegate & GetInstance() { return sInstance; }

CHIP_ERROR GetPresetTypeAtIndex(size_t index, Structs::PresetTypeStruct::Type & presetType) override;

uint8_t GetNumberOfPresets() override;

CHIP_ERROR GetPresetAtIndex(size_t index, PresetStructWithOwnedMembers & preset) override;

CHIP_ERROR GetActivePresetHandle(MutableByteSpan & activePresetHandle) override;

CHIP_ERROR SetActivePresetHandle(const DataModel::Nullable<ByteSpan> & newActivePresetHandle) override;

CHIP_ERROR AppendToPendingPresetList(const Structs::PresetStruct::Type & preset) override;

CHIP_ERROR GetPendingPresetAtIndex(size_t index, PresetStructWithOwnedMembers & preset) override;

CHIP_ERROR ApplyPendingPresets() override;

void ClearPendingPresetList() override;

private:
static ThermostatDelegate sInstance;

ThermostatDelegate();
~ThermostatDelegate() = default;

ThermostatDelegate(const ThermostatDelegate &) = delete;
ThermostatDelegate & operator=(const ThermostatDelegate &) = delete;

/**
* @brief Initializes the preset types array with all preset types corresponding to PresetScenarioEnum.
*/
void InitializePresetTypes();

/**
* @brief Initializes the presets array with some sample presets for testing.
*/
void InitializePresets();

uint8_t mNumberOfPresets;

Structs::PresetTypeStruct::Type mPresetTypes[kMaxNumberOfPresetTypes];
PresetStructWithOwnedMembers mPresets[kMaxNumberOfPresetTypes * kMaxNumberOfPresetsOfEachType];
PresetStructWithOwnedMembers mPendingPresets[kMaxNumberOfPresetTypes * kMaxNumberOfPresetsOfEachType];

uint8_t mNextFreeIndexInPendingPresetsList;
uint8_t mNextFreeIndexInPresetsList;

uint8_t mActivePresetHandleData[kPresetHandleSize];
size_t mActivePresetHandleDataSize;
};

} // namespace Thermostat
} // namespace Clusters
} // namespace app
} // namespace chip
11 changes: 11 additions & 0 deletions examples/all-clusters-app/linux/main-common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "dishwasher-mode.h"
#include "energy-evse-modes.h"
#include "include/diagnostic-logs-provider-delegate-impl.h"
#include "include/thermostat-delegate-impl.h"
#include "include/tv-callbacks.h"
#include "laundry-dryer-controls-delegate-impl.h"
#include "laundry-washer-controls-delegate-impl.h"
Expand All @@ -46,6 +47,7 @@
#include <app/clusters/laundry-dryer-controls-server/laundry-dryer-controls-server.h>
#include <app/clusters/laundry-washer-controls-server/laundry-washer-controls-server.h>
#include <app/clusters/mode-base-server/mode-base-server.h>
#include <app/clusters/thermostat-server/thermostat-server.h>
#include <app/clusters/time-synchronization-server/time-synchronization-server.h>
#include <app/clusters/valve-configuration-and-control-server/valve-configuration-and-control-server.h>
#include <app/server/Server.h>
Expand Down Expand Up @@ -323,3 +325,12 @@ void emberAfDiagnosticLogsClusterInitCallback(chip::EndpointId endpoint)

DiagnosticLogsServer::Instance().SetDiagnosticLogsProviderDelegate(endpoint, &logProvider);
}

using namespace chip::app::Clusters::Thermostat;
void emberAfThermostatClusterInitCallback(EndpointId endpoint)
{
// Register the delegate for the Thermostat
auto & delegate = ThermostatDelegate::GetInstance();

SetDefaultDelegate(endpoint, &delegate);
}
Loading

0 comments on commit fcb85a5

Please sign in to comment.