Skip to content

Commit 65f1374

Browse files
committed
Merge branch 'cluster/whtrm' into 'main'
Components/esp-matter: Add Water Heater Management cluster See merge request app-frameworks/esp-matter!936
2 parents 785b16c + 99a6953 commit 65f1374

14 files changed

+278
-0
lines changed

components/esp_matter/esp_matter_attribute.cpp

+41
Original file line numberDiff line numberDiff line change
@@ -4770,5 +4770,46 @@ attribute_t *create_progress(cluster_t *cluster, uint8_t *value, uint16_t length
47704770
} /* attribute */
47714771
} /* service_area */
47724772

4773+
namespace water_heater_management {
4774+
namespace attribute {
4775+
attribute_t *create_heater_types(cluster_t *cluster, uint8_t value)
4776+
{
4777+
return esp_matter::attribute::create(cluster, WaterHeaterManagement::Attributes::HeaterTypes::Id,
4778+
ATTRIBUTE_FLAG_NONE, esp_matter_bitmap8(value));
4779+
}
4780+
4781+
attribute_t *create_heat_demand(cluster_t *cluster, uint8_t value)
4782+
{
4783+
return esp_matter::attribute::create(cluster, WaterHeaterManagement::Attributes::HeatDemand::Id,
4784+
ATTRIBUTE_FLAG_NONE, esp_matter_bitmap8(value));
4785+
}
4786+
4787+
attribute_t *create_tank_volume(cluster_t *cluster, uint16_t value)
4788+
{
4789+
return esp_matter::attribute::create(cluster, WaterHeaterManagement::Attributes::TankVolume::Id,
4790+
ATTRIBUTE_FLAG_NONE, esp_matter_uint16(value));
4791+
}
4792+
4793+
attribute_t *create_estimated_heat_required(cluster_t *cluster, int64_t value)
4794+
{
4795+
return esp_matter::attribute::create(cluster, WaterHeaterManagement::Attributes::EstimatedHeatRequired::Id,
4796+
ATTRIBUTE_FLAG_NONE, esp_matter_int64(value));
4797+
}
4798+
4799+
attribute_t *create_tank_percentage(cluster_t *cluster, uint8_t value)
4800+
{
4801+
return esp_matter::attribute::create(cluster, WaterHeaterManagement::Attributes::TankPercentage::Id,
4802+
ATTRIBUTE_FLAG_NONE, esp_matter_uint8(value));
4803+
}
4804+
4805+
attribute_t *create_boost_state(cluster_t *cluster, uint8_t value)
4806+
{
4807+
return esp_matter::attribute::create(cluster, WaterHeaterManagement::Attributes::BoostState::Id,
4808+
ATTRIBUTE_FLAG_NONE, esp_matter_enum8(value));
4809+
}
4810+
4811+
} /* attribute */
4812+
} /* water_heater_management */
4813+
47734814
} /* cluster */
47744815
} /* esp_matter */

components/esp_matter/esp_matter_attribute.h

+11
Original file line numberDiff line numberDiff line change
@@ -1160,5 +1160,16 @@ attribute_t *create_progress(cluster_t *cluster, uint8_t *value, uint16_t length
11601160
} /* attribute */
11611161
} /* service_area */
11621162

1163+
namespace water_heater_management {
1164+
namespace attribute {
1165+
attribute_t *create_heater_types(cluster_t *cluster, uint8_t value);
1166+
attribute_t *create_heat_demand(cluster_t *cluster, uint8_t value);
1167+
attribute_t *create_tank_volume(cluster_t *cluster, uint16_t value);
1168+
attribute_t *create_estimated_heat_required(cluster_t *cluster, int64_t value);
1169+
attribute_t *create_tank_percentage(cluster_t *cluster, uint8_t value);
1170+
attribute_t *create_boost_state(cluster_t *cluster, uint8_t value);
1171+
} /* attribute */
1172+
} /* water_heater_management */
1173+
11631174
} /* cluster */
11641175
} /* esp_matter */

components/esp_matter/esp_matter_cluster.cpp

+44
Original file line numberDiff line numberDiff line change
@@ -3568,6 +3568,50 @@ cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags, uint32_
35683568
}
35693569
} /* service_area */
35703570

3571+
namespace water_heater_management {
3572+
const function_generic_t *function_list = NULL;
3573+
const int function_flags = CLUSTER_FLAG_NONE;
3574+
3575+
cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags, uint32_t features)
3576+
{
3577+
cluster_t *cluster = cluster::create(endpoint, WaterHeaterManagement::Id, flags);
3578+
if (!cluster) {
3579+
ESP_LOGE(TAG, "Could not create cluster");
3580+
return NULL;
3581+
}
3582+
if (flags & CLUSTER_FLAG_SERVER) {
3583+
if (config -> delegate != nullptr) {
3584+
static const auto delegate_init_cb = WaterHeaterManagementDelegateInitCB;
3585+
set_delegate_and_init_callback(cluster, delegate_init_cb, config->delegate);
3586+
}
3587+
static const auto plugin_server_init_cb = CALL_ONCE(MatterWaterHeaterManagementPluginServerInitCallback);
3588+
set_plugin_server_init_callback(cluster, plugin_server_init_cb);
3589+
add_function_list(cluster, function_list, function_flags);
3590+
3591+
/* Attributes managed internally */
3592+
global::attribute::create_feature_map(cluster, 0);
3593+
3594+
/** Attributes not managed internally **/
3595+
global::attribute::create_cluster_revision(cluster, cluster_revision);
3596+
attribute::create_heater_types(cluster, config->heater_types);
3597+
attribute::create_heat_demand(cluster, config->heat_demand);
3598+
attribute::create_tank_volume(cluster, config->tank_volume);
3599+
}
3600+
3601+
if (features & feature::energy_management::get_id()) {
3602+
feature::energy_management::add(cluster, &(config->energy_management));
3603+
}
3604+
if (features & feature::tank_percent::get_id()) {
3605+
feature::tank_percent::add(cluster, &(config->tank_percent));
3606+
}
3607+
3608+
event::create_boost_started(cluster);
3609+
event::create_boost_ended(cluster);
3610+
return cluster;
3611+
}
3612+
3613+
} /* water_heater_management */
3614+
35713615
// namespace binary_input_basic {
35723616
// // ToDo
35733617
// } /* binary_input_basic */

components/esp_matter/esp_matter_cluster.h

+14
Original file line numberDiff line numberDiff line change
@@ -906,5 +906,19 @@ typedef struct config {
906906
cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags, uint32_t features);
907907
} /* service_area */
908908

909+
namespace water_heater_management {
910+
typedef struct config {
911+
uint8_t heater_types;
912+
uint8_t heat_demand;
913+
uint8_t tank_volume;
914+
void *delegate;
915+
feature::energy_management::config_t energy_management;
916+
feature::tank_percent::config_t tank_percent;
917+
config() : heater_types(0), heat_demand(0), tank_volume(0), delegate(nullptr) {}
918+
} config_t;
919+
920+
cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags, uint32_t features);
921+
} /* water_heater_management */
922+
909923
} /* cluster */
910924
} /* esp_matter */

components/esp_matter/esp_matter_command.cpp

+25
Original file line numberDiff line numberDiff line change
@@ -3261,6 +3261,30 @@ command_t *create_skip_area_response(cluster_t *cluster)
32613261
} /* command */
32623262
} /* service_area */
32633263

3264+
namespace water_heater_management {
3265+
namespace command {
3266+
constexpr const command_entry_t accepted_command_list[] = {
3267+
{WaterHeaterManagement::Commands::Boost::Id, COMMAND_FLAG_ACCEPTED, NULL},
3268+
{WaterHeaterManagement::Commands::CancelBoost::Id, COMMAND_FLAG_ACCEPTED, NULL},
3269+
};
3270+
3271+
constexpr const command_entry_t generated_command_list[] = {};
3272+
3273+
command_t *create_boost(cluster_t *cluster)
3274+
{
3275+
return esp_matter::command::create(cluster, WaterHeaterManagement::Commands::CancelBoost::Id,
3276+
COMMAND_FLAG_ACCEPTED, NULL);
3277+
}
3278+
3279+
command_t *create_cancel_boost(cluster_t *cluster)
3280+
{
3281+
return esp_matter::command::create(cluster, WaterHeaterManagement::Commands::CancelBoost::Id,
3282+
COMMAND_FLAG_ACCEPTED, NULL);
3283+
}
3284+
3285+
} /* command */
3286+
} /* water_heater_management */
3287+
32643288
} /* cluster */
32653289
} /* esp_matter */
32663290

@@ -3307,6 +3331,7 @@ constexpr const cluster_command_t cluster_command_table[] = {
33073331
{ThreadBorderRouterManagement::Id, GET_COMMAND_COUNT_LIST(cluster::thread_border_router_management)},
33083332
{WiFiNetworkManagement::Id, GET_COMMAND_COUNT_LIST(cluster::wifi_network_management)},
33093333
{ThreadNetworkDirectory::Id, GET_COMMAND_COUNT_LIST(cluster::thread_network_directory)},
3334+
{WaterHeaterManagement::Id, GET_COMMAND_COUNT_LIST(cluster::water_heater_management)},
33103335
};
33113336

33123337
#if defined(CONFIG_ESP_MATTER_ENABLE_MATTER_SERVER) && defined(CONFIG_ESP_MATTER_ENABLE_DATA_MODEL)

components/esp_matter/esp_matter_command.h

+7
Original file line numberDiff line numberDiff line change
@@ -466,5 +466,12 @@ command_t *create_skip_area_response(cluster_t *cluster);
466466
} /* command */
467467
} /* service_area */
468468

469+
namespace water_heater_management {
470+
namespace command {
471+
command_t *create_boost(cluster_t *cluster);
472+
command_t *create_cancel_boost(cluster_t *cluster);
473+
} /* command */
474+
} /* water_heater_management */
475+
469476
} /* cluster */
470477
} /* esp_matter */

components/esp_matter/esp_matter_delegate_callbacks.cpp

+15
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include <app/clusters/keypad-input-server/keypad-input-server.h>
3939
#include <app/clusters/mode-select-server//supported-modes-manager.h>
4040
#include <app/clusters/thread-border-router-management-server/thread-border-router-management-server.h>
41+
#include <app/clusters/water-heater-management-server/water-heater-management-server.h>
4142

4243
using namespace chip::app::Clusters;
4344
namespace esp_matter {
@@ -379,6 +380,20 @@ void ServiceAreaDelegateInitCB(void *delegate, uint16_t endpoint_id)
379380
{
380381
// TODO: This cluster have two delegates we need to update exsiting delegate logic to accomodate multiple delegates.
381382
}
383+
384+
void WaterHeaterManagementDelegateInitCB(void *delegate, uint16_t endpoint_id)
385+
{
386+
if(delegate == nullptr)
387+
{
388+
return;
389+
}
390+
static WaterHeaterManagement::Instance * wHtrInstance = nullptr;
391+
WaterHeaterManagement::Delegate *whtr_delegate = static_cast<WaterHeaterManagement::Delegate*>(delegate);
392+
uint32_t feature_map = get_feature_map_value(endpoint_id, WaterHeaterManagement::Id);
393+
wHtrInstance = new WaterHeaterManagement::Instance(endpoint_id, *whtr_delegate, chip::BitMask<WaterHeaterManagement::Feature, uint32_t>(feature_map));
394+
wHtrInstance->Init();
395+
}
396+
382397
} // namespace delegate_cb
383398

384399
} // namespace cluster

components/esp_matter/esp_matter_delegate_callbacks.h

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ void KeypadInputDelegateInitCB(void *delegate, uint16_t endpoint_id);
4747
void ModeSelectDelegateInitCB(void *delegate, uint16_t endpoint_id);
4848
void ThreadBorderRouterManagementDelegateInitCB(void *delegate, uint16_t endpoint_id);
4949
void ServiceAreaDelegateInitCB(void *delegate, uint16_t endpoint_id);
50+
void WaterHeaterManagementDelegateInitCB(void *delegate, uint16_t endpoint_id);
5051
} // namespace delegate_cb
5152

5253
} // namespace cluster

components/esp_matter/esp_matter_event.cpp

+15
Original file line numberDiff line numberDiff line change
@@ -744,5 +744,20 @@ event_t *create_resumed(cluster_t *cluster)
744744
} // namespace event
745745
} // namespace device_energy_management
746746

747+
namespace water_heater_management {
748+
namespace event {
749+
event_t *create_boost_started(cluster_t *cluster)
750+
{
751+
return esp_matter::event::create(cluster, WaterHeaterManagement::Events::BoostStarted::Id);
752+
}
753+
754+
event_t *create_boost_ended(cluster_t *cluster)
755+
{
756+
return esp_matter::event::create(cluster, WaterHeaterManagement::Events::BoostEnded::Id);
757+
}
758+
759+
} // namespace event
760+
} // namespace water_heater_management
761+
747762
} // namespace cluster
748763
} // namespace esp_matter

components/esp_matter/esp_matter_event.h

+7
Original file line numberDiff line numberDiff line change
@@ -223,5 +223,12 @@ event_t *create_resumed(cluster_t *cluster);
223223
} // namespace event
224224
} // namespace device_energy_management
225225

226+
namespace water_heater_management {
227+
namespace event {
228+
event_t *create_boost_started(cluster_t *cluster);
229+
event_t *create_boost_ended(cluster_t *cluster);
230+
} // namespace event
231+
} // namespace water_heater_management
232+
226233
} // namespace cluster
227234
} // namespace esp_matter

components/esp_matter/esp_matter_feature.cpp

+52
Original file line numberDiff line numberDiff line change
@@ -4850,5 +4850,57 @@ esp_err_t add(cluster_t *cluster)
48504850
} /* feature */
48514851
} /* service_area */
48524852

4853+
namespace water_heater_management {
4854+
namespace feature {
4855+
4856+
namespace energy_management {
4857+
4858+
uint32_t get_id()
4859+
{
4860+
return static_cast<uint32_t>(WaterHeaterManagement::Feature::kEnergyManagement);
4861+
}
4862+
4863+
esp_err_t add(cluster_t *cluster, config_t *config)
4864+
{
4865+
if (!cluster) {
4866+
ESP_LOGE(TAG, "Cluster cannot be NULL");
4867+
return ESP_ERR_INVALID_ARG;
4868+
}
4869+
update_feature_map(cluster, get_id());
4870+
/* attribute */
4871+
attribute::create_tank_volume(cluster, config->tank_volume);
4872+
attribute::create_estimated_heat_required(cluster, config->estimated_heat_required);
4873+
4874+
return ESP_OK;
4875+
}
4876+
4877+
} /* energy_management */
4878+
4879+
namespace tank_percent {
4880+
4881+
uint32_t get_id()
4882+
{
4883+
return static_cast<uint32_t>(WaterHeaterManagement::Feature::kEnergyManagement);
4884+
}
4885+
4886+
esp_err_t add(cluster_t *cluster, config_t *config)
4887+
{
4888+
if (!cluster) {
4889+
ESP_LOGE(TAG, "Cluster cannot be NULL");
4890+
return ESP_ERR_INVALID_ARG;
4891+
}
4892+
update_feature_map(cluster, get_id());
4893+
/* attribute */
4894+
attribute::create_tank_percentage(cluster, config->tank_percentage);
4895+
4896+
return ESP_OK;
4897+
}
4898+
4899+
4900+
} /* tank_percent */
4901+
4902+
} /* feature */
4903+
} /* water_heater_management */
4904+
48534905
} /* cluster */
48544906
} /* esp_matter */

components/esp_matter/esp_matter_feature.h

+31
Original file line numberDiff line numberDiff line change
@@ -2122,5 +2122,36 @@ esp_err_t add(cluster_t *cluster);
21222122
} /* feature */
21232123
} /* service_area */
21242124

2125+
namespace water_heater_management {
2126+
namespace feature {
2127+
2128+
namespace energy_management {
2129+
2130+
typedef struct config {
2131+
uint16_t tank_volume;
2132+
int64_t estimated_heat_required;
2133+
config(): tank_volume(0), estimated_heat_required(0) {}
2134+
} config_t;
2135+
2136+
uint32_t get_id();
2137+
esp_err_t add(cluster_t *cluster, config_t *config);
2138+
2139+
} /* energy_management */
2140+
2141+
namespace tank_percent {
2142+
2143+
typedef struct config {
2144+
uint8_t tank_percentage;
2145+
config(): tank_percentage(0) {}
2146+
} config_t;
2147+
2148+
uint32_t get_id();
2149+
esp_err_t add(cluster_t *cluster, config_t *config);
2150+
2151+
} /* tank_percent */
2152+
2153+
} /* feature */
2154+
} /* water_heater_management */
2155+
21252156
} /* cluster */
21262157
} /* esp_matter */

components/esp_matter/private/esp_matter_cluster_revisions.h

+4
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,10 @@ namespace service_area {
383383
constexpr uint16_t cluster_revision = 1;
384384
} // namespace service_area
385385

386+
namespace water_heater_management {
387+
constexpr uint16_t cluster_revision = 2;
388+
} // namespace water_heater_management
389+
386390
} // namespace cluster
387391
} // namespace esp_matter
388392

docs/en/app_guide.rst

+11
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ List of clusters with delegate:
4545
- Wake On Lan Cluster.
4646
- Target Navigator Cluster.
4747
- Mode Select Cluster.
48+
- Water Heater Management Cluster.
4849

4950
9.1.1 Mode Base Cluster
5051
-----------------------
@@ -216,6 +217,14 @@ ModeWaterHeater, ModeRefrigerator, ModeLaundryWasher and ModeMicrowaveOven.
216217

217218
`Mode Select`_, `Mode Select Delegate`_
218219

220+
9.1.21 Water Heater Management Cluster
221+
--------------------------------------
222+
223+
.. csv-table::
224+
:header: "Delegate Class", "Reference Implementation"
225+
226+
`Water Heater Management`_, `Water Heater Management Delegate`_
227+
219228

220229
.. note::
221230
Make sure that after implementing delegate class, you set the delegate class pointer at the time of creating cluster.
@@ -269,3 +278,5 @@ ModeWaterHeater, ModeRefrigerator, ModeLaundryWasher and ModeMicrowaveOven.
269278
.. _`Keypad Input Delegate`: https://github.com/espressif/connectedhomeip/blob/ea679d2dc674f576f4d391d1d71af1489010e580/examples/chef/common/clusters/keypad-input/KeypadInputManager.h
270279
.. _`Mode Select`: https://github.com/espressif/connectedhomeip/blob/ea679d2dc674f576f4d391d1d71af1489010e580/src/app/clusters/mode-select-server/supported-modes-manager.h
271280
.. _`Mode Select Delegate`: https://github.com/espressif/connectedhomeip/blob/ea679d2dc674f576f4d391d1d71af1489010e580/examples/all-clusters-app/all-clusters-common/include/static-supported-modes-manager.h
281+
.. _`Water Heater Management`: https://github.com/espressif/connectedhomeip/blob/ea679d2dc674f576f4d391d1d71af1489010e580/src/app/clusters/water-heater-management-server/water-heater-management-server.h
282+
.. _`Water Heater Management Delegate`: https://github.com/espressif/connectedhomeip/blob/ea679d2dc674f576f4d391d1d71af1489010e580/examples/energy-management-app/energy-management-common/water-heater/include/WhmDelegate.h

0 commit comments

Comments
 (0)