Skip to content

Commit f21874c

Browse files
committed
Merge branch 'device/water_valve' into 'main'
[Delegate optional] Add water valve device type See merge request app-frameworks/esp-matter!683
2 parents 8e4c70d + f465141 commit f21874c

18 files changed

+380
-5
lines changed

SUPPORTED_DEVICE_TYPES.md

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ c. Smart Plugs/Outlets
3030
1. On/Off Plugin Unit
3131
2. Dimmable Plugin Unit
3232
3. Pump
33+
4. Water Valve
3334

3435
d. Generic
3536
1. Mode Select

components/esp_matter/esp_matter_attribute.cpp

+60
Original file line numberDiff line numberDiff line change
@@ -4633,5 +4633,65 @@ attribute_t *create_watt_rating(cluster_t *cluster, uint16_t value)
46334633
} /* attribute */
46344634
} /* microwave_oven_control */
46354635

4636+
namespace valve_configuration_and_control {
4637+
namespace attribute {
4638+
attribute_t *create_open_duration(cluster_t *cluster, nullable<uint32_t> value)
4639+
{
4640+
return esp_matter::attribute::create(cluster, ValveConfigurationAndControl::Attributes::OpenDuration::Id, ATTRIBUTE_FLAG_NULLABLE, esp_matter_nullable_uint32(value));
4641+
}
4642+
4643+
attribute_t *create_default_open_duration(cluster_t *cluster, nullable<uint32_t> value)
4644+
{
4645+
return esp_matter::attribute::create(cluster, ValveConfigurationAndControl::Attributes::DefaultOpenDuration::Id, ATTRIBUTE_FLAG_NULLABLE | ATTRIBUTE_FLAG_WRITABLE | ATTRIBUTE_FLAG_NONVOLATILE, esp_matter_nullable_uint32(value));
4646+
}
4647+
4648+
attribute_t *create_auto_close_time(cluster_t *cluster, nullable<uint64_t> value)
4649+
{
4650+
return esp_matter::attribute::create(cluster, ValveConfigurationAndControl::Attributes::AutoCloseTime::Id, ATTRIBUTE_FLAG_NULLABLE, esp_matter_nullable_uint64(value));
4651+
}
4652+
4653+
attribute_t *create_remaining_duration(cluster_t *cluster, nullable<uint32_t> value)
4654+
{
4655+
return esp_matter::attribute::create(cluster, ValveConfigurationAndControl::Attributes::RemainingDuration::Id, ATTRIBUTE_FLAG_NULLABLE, esp_matter_nullable_uint32(value));
4656+
}
4657+
4658+
attribute_t *create_current_state(cluster_t *cluster, nullable<uint8_t> value)
4659+
{
4660+
return esp_matter::attribute::create(cluster, ValveConfigurationAndControl::Attributes::CurrentState::Id, ATTRIBUTE_FLAG_NULLABLE, esp_matter_nullable_enum8(value));
4661+
}
4662+
4663+
attribute_t *create_target_state(cluster_t *cluster, nullable<uint8_t> value)
4664+
{
4665+
return esp_matter::attribute::create(cluster, ValveConfigurationAndControl::Attributes::TargetState::Id, ATTRIBUTE_FLAG_NULLABLE, esp_matter_nullable_enum8(value));
4666+
}
4667+
4668+
attribute_t *create_current_level(cluster_t *cluster, nullable<uint8_t> value)
4669+
{
4670+
return esp_matter::attribute::create(cluster, ValveConfigurationAndControl::Attributes::CurrentLevel::Id, ATTRIBUTE_FLAG_NULLABLE, esp_matter_nullable_uint8(value));
4671+
}
4672+
4673+
attribute_t *create_target_level(cluster_t *cluster, nullable<uint8_t> value)
4674+
{
4675+
return esp_matter::attribute::create(cluster, ValveConfigurationAndControl::Attributes::TargetLevel::Id, ATTRIBUTE_FLAG_NULLABLE, esp_matter_nullable_uint8(value));
4676+
}
4677+
4678+
attribute_t *create_default_open_level(cluster_t *cluster, uint8_t value)
4679+
{
4680+
return esp_matter::attribute::create(cluster, ValveConfigurationAndControl::Attributes::DefaultOpenLevel::Id, ATTRIBUTE_FLAG_NONVOLATILE | ATTRIBUTE_FLAG_WRITABLE, esp_matter_uint8(value));
4681+
}
4682+
4683+
attribute_t *create_valve_fault(cluster_t *cluster, uint16_t value)
4684+
{
4685+
return esp_matter::attribute::create(cluster, ValveConfigurationAndControl::Attributes::ValveFault::Id, ATTRIBUTE_FLAG_NONE, esp_matter_bitmap16(value));
4686+
}
4687+
4688+
attribute_t *create_level_step(cluster_t *cluster, const uint8_t value)
4689+
{
4690+
return esp_matter::attribute::create(cluster, ValveConfigurationAndControl::Attributes::LevelStep::Id, ATTRIBUTE_FLAG_NONE, esp_matter_uint8(value));
4691+
}
4692+
4693+
} /* attribute */
4694+
} /* valve_configuration_and_control */
4695+
46364696
} /* cluster */
46374697
} /* esp_matter */

components/esp_matter/esp_matter_attribute.h

+16
Original file line numberDiff line numberDiff line change
@@ -1061,5 +1061,21 @@ attribute_t *create_watt_rating(cluster_t *cluster, uint16_t value);
10611061
} /* attribute */
10621062
} /* microwave_oven_control */
10631063

1064+
namespace valve_configuration_and_control {
1065+
namespace attribute {
1066+
attribute_t *create_open_duration(cluster_t *cluster, nullable<uint32_t> value);
1067+
attribute_t *create_default_open_duration(cluster_t *cluster, nullable<uint32_t> value);
1068+
attribute_t *create_auto_close_time(cluster_t *cluster, nullable<uint64_t> value);
1069+
attribute_t *create_remaining_duration(cluster_t *cluster, nullable<uint32_t> value);
1070+
attribute_t *create_current_state(cluster_t *cluster, nullable<uint8_t> value);
1071+
attribute_t *create_target_state(cluster_t *cluster, nullable<uint8_t> value);
1072+
attribute_t *create_current_level(cluster_t *cluster, nullable<uint8_t> value);
1073+
attribute_t *create_target_level(cluster_t *cluster, nullable<uint8_t> value);
1074+
attribute_t *create_default_open_level(cluster_t *cluster, uint8_t value);
1075+
attribute_t *create_valve_fault(cluster_t *cluster, uint16_t value);
1076+
attribute_t *create_level_step(cluster_t *cluster, const uint8_t value);
1077+
} /* attribute */
1078+
} /* valve_configuration_and_control */
1079+
10641080
} /* cluster */
10651081
} /* esp_matter */

components/esp_matter/esp_matter_cluster.cpp

+61-1
Original file line numberDiff line numberDiff line change
@@ -3921,7 +3921,7 @@ cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags, uint32_
39213921
}
39223922
}
39233923

3924-
/* Features */
3924+
/* Features */
39253925
if (features & feature::charging_preferences::get_id()) {
39263926
feature::charging_preferences::add(cluster);
39273927
}
@@ -3946,6 +3946,66 @@ cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags, uint32_
39463946
}
39473947
} /* energy_evse */
39483948

3949+
namespace valve_configuration_and_control {
3950+
const function_generic_t *function_list = NULL;
3951+
const int function_flags = CLUSTER_FLAG_NONE;
3952+
3953+
cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags, uint32_t features)
3954+
{
3955+
cluster_t *cluster = cluster::create(endpoint, ValveConfigurationAndControl::Id, flags);
3956+
if (!cluster) {
3957+
ESP_LOGE(TAG, "Could not create cluster");
3958+
return NULL;
3959+
}
3960+
if (flags & CLUSTER_FLAG_SERVER) {
3961+
if (config -> delegate != nullptr) {
3962+
static const auto delegate_init_cb = ValveConfigurationAndControlDelegateInitCB;
3963+
set_delegate_and_init_callback(cluster, delegate_init_cb, config->delegate);
3964+
}
3965+
static const auto plugin_server_init_cb = CALL_ONCE(MatterValveConfigurationAndControlPluginServerInitCallback);
3966+
set_plugin_server_init_callback(cluster, plugin_server_init_cb);
3967+
add_function_list(cluster, function_list, function_flags);
3968+
}
3969+
if (flags & CLUSTER_FLAG_CLIENT) {
3970+
create_default_binding_cluster(endpoint);
3971+
}
3972+
3973+
if (flags & CLUSTER_FLAG_SERVER) {
3974+
/* Attributes managed internally */
3975+
global::attribute::create_feature_map(cluster, 0);
3976+
attribute::create_remaining_duration(cluster, 0);
3977+
#if CHIP_CONFIG_ENABLE_EVENTLIST_ATTRIBUTE
3978+
global::attribute::create_event_list(cluster, NULL, 0, 0);
3979+
#endif
3980+
3981+
/** Attributes not managed internally **/
3982+
if (config) {
3983+
global::attribute::create_cluster_revision(cluster, config->cluster_revision);
3984+
attribute::create_open_duration(cluster, config->open_duration);
3985+
attribute::create_default_open_duration(cluster, config->default_open_duration);
3986+
attribute::create_current_state(cluster, config->current_state);
3987+
attribute::create_target_state(cluster, config->target_state);
3988+
} else {
3989+
ESP_LOGE(TAG, "Config is NULL. Cannot add some attributes.");
3990+
}
3991+
}
3992+
3993+
/* Commands */
3994+
command::create_open(cluster);
3995+
command::create_close(cluster);
3996+
3997+
/* Features */
3998+
if (features & feature::time_sync::get_id()) {
3999+
feature::time_sync::add(cluster, &(config->time_sync));
4000+
}
4001+
if (features & feature::level::get_id()) {
4002+
feature::level::add(cluster, &(config->level));
4003+
}
4004+
4005+
return cluster;
4006+
}
4007+
} /* valve_configuration_and_control */
4008+
39494009
// namespace binary_input_basic {
39504010
// // ToDo
39514011
// } /* binary_input_basic */

components/esp_matter/esp_matter_cluster.h

+16
Original file line numberDiff line numberDiff line change
@@ -943,5 +943,21 @@ typedef struct config {
943943
cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags, uint32_t features);
944944
} /* energy_evse */
945945

946+
namespace valve_configuration_and_control {
947+
typedef struct config {
948+
uint16_t cluster_revision;
949+
nullable<uint32_t> open_duration;
950+
nullable<uint32_t> default_open_duration;
951+
nullable<uint8_t> current_state;
952+
nullable<uint8_t> target_state;
953+
feature::time_sync::config_t time_sync;
954+
feature::level::config_t level;
955+
void *delegate;
956+
config() : cluster_revision(1), open_duration(), default_open_duration(), current_state(), target_state(), delegate(nullptr) {}
957+
} config_t;
958+
959+
cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags, uint32_t features);
960+
} /* valve_configuration_and_control */
961+
946962
} /* cluster */
947963
} /* esp_matter */

components/esp_matter/esp_matter_command.cpp

+35
Original file line numberDiff line numberDiff line change
@@ -1456,6 +1456,26 @@ static esp_err_t esp_matter_command_callback_enable_disable_alarm(const Concrete
14561456
return ESP_OK;
14571457
}
14581458

1459+
static esp_err_t esp_matter_command_callback_open(const ConcreteCommandPath &command_path, TLVReader &tlv_data, void *opaque_ptr)
1460+
{
1461+
chip::app::Clusters::ValveConfigurationAndControl::Commands::Open::DecodableType command_data;
1462+
CHIP_ERROR error = Decode(tlv_data, command_data);
1463+
if (error == CHIP_NO_ERROR) {
1464+
emberAfValveConfigurationAndControlClusterOpenCallback((CommandHandler *)opaque_ptr, command_path, command_data);
1465+
}
1466+
return ESP_OK;
1467+
}
1468+
1469+
static esp_err_t esp_matter_command_callback_close(const ConcreteCommandPath &command_path, TLVReader &tlv_data, void *opaque_ptr)
1470+
{
1471+
chip::app::Clusters::ValveConfigurationAndControl::Commands::Close::DecodableType command_data;
1472+
CHIP_ERROR error = Decode(tlv_data, command_data);
1473+
if (error == CHIP_NO_ERROR) {
1474+
emberAfValveConfigurationAndControlClusterCloseCallback((CommandHandler *)opaque_ptr, command_path, command_data);
1475+
}
1476+
return ESP_OK;
1477+
}
1478+
14591479
namespace esp_matter {
14601480
namespace cluster {
14611481

@@ -2779,6 +2799,21 @@ command_t *create_add_more_time(cluster_t *cluster)
27792799
} /* command */
27802800
} /* microwave_oven_control */
27812801

2802+
namespace valve_configuration_and_control {
2803+
namespace command {
2804+
command_t *create_open(cluster_t *cluster)
2805+
{
2806+
return esp_matter::command::create(cluster, ValveConfigurationAndControl::Commands::Open::Id, COMMAND_FLAG_ACCEPTED, esp_matter_command_callback_open);
2807+
}
2808+
2809+
command_t *create_close(cluster_t *cluster)
2810+
{
2811+
return esp_matter::command::create(cluster, ValveConfigurationAndControl::Commands::Close::Id, COMMAND_FLAG_ACCEPTED, esp_matter_command_callback_close);
2812+
}
2813+
2814+
} /* command */
2815+
} /* valve_configuration_and_control */
2816+
27822817
} /* cluster */
27832818
} /* esp_matter */
27842819

components/esp_matter/esp_matter_command.h

+7
Original file line numberDiff line numberDiff line change
@@ -397,5 +397,12 @@ command_t *create_add_more_time(cluster_t *cluster);
397397
} /* command */
398398
} /* microwave_oven_control */
399399

400+
namespace valve_configuration_and_control {
401+
namespace command {
402+
command_t *create_open(cluster_t *cluster);
403+
command_t *create_close(cluster_t *cluster);
404+
} /* command */
405+
} /* valve_configuration_and_control */
406+
400407
} /* cluster */
401408
} /* esp_matter */

components/esp_matter/esp_matter_delegate_callbacks.cpp

+11
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <app/clusters/resource-monitoring-server/resource-monitoring-server.h>
2424
#include <app/clusters/fan-control-server/fan-control-server.h>
2525
#include <app/clusters/laundry-dryer-controls-server/laundry-dryer-controls-server.h>
26+
#include <app/clusters/valve-configuration-and-control-server/valve-configuration-and-control-server.h>
2627

2728
using namespace chip::app::Clusters;
2829
namespace esp_matter {
@@ -194,6 +195,16 @@ void LaundryDryerControlsDelegateInitCB(void *delegate, uint16_t endpoint_id)
194195
LaundryDryerControls::LaundryDryerControlsServer::SetDefaultDelegate(endpoint_id, laundry_dryer_controls_delegate);
195196
}
196197

198+
void ValveConfigurationAndControlDelegateInitCB(void *delegate, uint16_t endpoint_id)
199+
{
200+
if(delegate == nullptr)
201+
{
202+
return;
203+
}
204+
ValveConfigurationAndControl::Delegate *valve_configuration_and_control_delegate = static_cast<ValveConfigurationAndControl::Delegate*>(delegate);
205+
ValveConfigurationAndControl::SetDefaultDelegate(endpoint_id, valve_configuration_and_control_delegate);
206+
}
207+
197208
} // namespace delegate_cb
198209

199210
} // namespace cluster

components/esp_matter/esp_matter_delegate_callbacks.h

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ void FanControlDelegateInitCB(void *delegate, uint16_t endpoint_id);
3131
void HepaFilterMonitoringDelegateInitCB(void *delegate, uint16_t endpoint_id);
3232
void ActivatedCarbonFilterMonitoringDelegateInitCB(void *delegate, uint16_t endpoint_id);
3333
void LaundryDryerControlsDelegateInitCB(void *delegate, uint16_t endpoint_id);
34+
void ValveConfigurationAndControlDelegateInitCB(void *delegate, uint16_t endpoint_id);
3435
} // namespace delegate_cb
3536

3637
} // namespace cluster

components/esp_matter/esp_matter_endpoint.cpp

+39
Original file line numberDiff line numberDiff line change
@@ -1905,6 +1905,45 @@ esp_err_t add(endpoint_t *endpoint, config_t *config)
19051905
}
19061906
} /* extractor_hood */
19071907

1908+
namespace water_valve {
1909+
1910+
uint32_t get_device_type_id()
1911+
{
1912+
return ESP_MATTER_WATER_VALVE_DEVICE_TYPE_ID;
1913+
}
1914+
1915+
uint8_t get_device_type_version()
1916+
{
1917+
return ESP_MATTER_WATER_VALVE_DEVICE_TYPE_VERSION;
1918+
}
1919+
1920+
endpoint_t *create(node_t *node, config_t *config, uint8_t flags, void *priv_data)
1921+
{
1922+
endpoint_t *endpoint = endpoint::create(node, flags, priv_data);
1923+
add(endpoint, config);
1924+
return endpoint;
1925+
}
1926+
1927+
esp_err_t add(endpoint_t *endpoint, config_t *config)
1928+
{
1929+
if (!endpoint) {
1930+
ESP_LOGE(TAG, "Endpoint cannot be NULL");
1931+
return ESP_ERR_INVALID_ARG;
1932+
}
1933+
esp_err_t err = add_device_type(endpoint, get_device_type_id(), get_device_type_version());
1934+
if (err != ESP_OK) {
1935+
ESP_LOGE(TAG, "Failed to add device type id:%" PRIu32 ",err: %d", get_device_type_id(), err);
1936+
return err;
1937+
}
1938+
1939+
identify::create(endpoint, &(config->identify), CLUSTER_FLAG_SERVER);
1940+
descriptor::create(endpoint, &(config->descriptor), CLUSTER_FLAG_SERVER);
1941+
valve_configuration_and_control::create(endpoint, &(config->valve_configuration_and_control), CLUSTER_FLAG_SERVER, ESP_MATTER_NONE_FEATURE_ID);
1942+
1943+
return ESP_OK;
1944+
}
1945+
} /** water_valve **/
1946+
19081947
} /* endpoint */
19091948

19101949
namespace node {

components/esp_matter/esp_matter_endpoint.h

+15
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@
118118
#define ESP_MATTER_ENERGY_EVSE_DEVICE_TYPE_VERSION 1
119119
#define ESP_MATTER_EXTRACTOR_HOOD_DEVICE_TYPE_ID 0x007A
120120
#define ESP_MATTER_EXTRACTOR_HOOD_DEVICE_TYPE_VERSION 1
121+
#define ESP_MATTER_WATER_VALVE_DEVICE_TYPE_ID 0x0042
122+
#define ESP_MATTER_WATER_VALVE_DEVICE_TYPE_VERSION 1
121123

122124
namespace esp_matter {
123125

@@ -765,6 +767,19 @@ endpoint_t *create(node_t *node, config_t *config, uint8_t flags, void *priv_dat
765767
esp_err_t add(endpoint_t *endpoint, config_t *config);
766768
} /* extractor_hood */
767769

770+
namespace water_valve {
771+
typedef struct config {
772+
cluster::descriptor::config_t descriptor;
773+
cluster::identify::config_t identify;
774+
cluster::valve_configuration_and_control::config_t valve_configuration_and_control;
775+
} config_t;
776+
777+
uint32_t get_device_type_id();
778+
uint8_t get_device_type_version();
779+
endpoint_t *create(node_t *node, config_t *config, uint8_t flags, void *priv_data);
780+
esp_err_t add(endpoint_t *endpoint, config_t *config);
781+
} /** water_valve **/
782+
768783
} /* endpoint */
769784

770785
namespace node {

components/esp_matter/esp_matter_event.cpp

+14
Original file line numberDiff line numberDiff line change
@@ -705,5 +705,19 @@ event_t *create_periodic_energy_measured(cluster_t *cluster)
705705
} // namespace event
706706
} // namespace electrical_energy_measurement
707707

708+
namespace valve_configuration_and_control {
709+
namespace event {
710+
event_t *create_valve_state_changed(cluster_t *cluster)
711+
{
712+
return esp_matter::event::create(cluster, ValveConfigurationAndControl::Events::ValveStateChanged::Id);
713+
}
714+
715+
event_t *create_valve_fault(cluster_t *cluster)
716+
{
717+
return esp_matter::event::create(cluster, ValveConfigurationAndControl::Events::ValveFault::Id);
718+
}
719+
} // namespace event
720+
} // namespace valve_configuration_and_control
721+
708722
} // namespace cluster
709723
} // namespace esp_matter

components/esp_matter/esp_matter_event.h

+7
Original file line numberDiff line numberDiff line change
@@ -207,5 +207,12 @@ event_t *create_periodic_energy_measured(cluster_t *cluster);
207207
} // namespace event
208208
} // namespace electrical_energy_measurement
209209

210+
namespace valve_configuration_and_control {
211+
namespace event {
212+
event_t *create_valve_state_changed(cluster_t *cluster);
213+
event_t *create_valve_fault(cluster_t *cluster);
214+
} // namespace event
215+
} // namespace valve_configuration_and_control
216+
210217
} // namespace cluster
211218
} // namespace esp_matter

0 commit comments

Comments
 (0)