Skip to content

Commit

Permalink
Merge branch 'device/water_valve' into 'main'
Browse files Browse the repository at this point in the history
[Delegate optional] Add water valve device type

See merge request app-frameworks/esp-matter!683
  • Loading branch information
dhrishi committed May 25, 2024
2 parents 8e4c70d + f465141 commit f21874c
Show file tree
Hide file tree
Showing 18 changed files with 380 additions and 5 deletions.
1 change: 1 addition & 0 deletions SUPPORTED_DEVICE_TYPES.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ c. Smart Plugs/Outlets
1. On/Off Plugin Unit
2. Dimmable Plugin Unit
3. Pump
4. Water Valve

d. Generic
1. Mode Select
Expand Down
60 changes: 60 additions & 0 deletions components/esp_matter/esp_matter_attribute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4633,5 +4633,65 @@ attribute_t *create_watt_rating(cluster_t *cluster, uint16_t value)
} /* attribute */
} /* microwave_oven_control */

namespace valve_configuration_and_control {
namespace attribute {
attribute_t *create_open_duration(cluster_t *cluster, nullable<uint32_t> value)
{
return esp_matter::attribute::create(cluster, ValveConfigurationAndControl::Attributes::OpenDuration::Id, ATTRIBUTE_FLAG_NULLABLE, esp_matter_nullable_uint32(value));
}

attribute_t *create_default_open_duration(cluster_t *cluster, nullable<uint32_t> value)
{
return esp_matter::attribute::create(cluster, ValveConfigurationAndControl::Attributes::DefaultOpenDuration::Id, ATTRIBUTE_FLAG_NULLABLE | ATTRIBUTE_FLAG_WRITABLE | ATTRIBUTE_FLAG_NONVOLATILE, esp_matter_nullable_uint32(value));
}

attribute_t *create_auto_close_time(cluster_t *cluster, nullable<uint64_t> value)
{
return esp_matter::attribute::create(cluster, ValveConfigurationAndControl::Attributes::AutoCloseTime::Id, ATTRIBUTE_FLAG_NULLABLE, esp_matter_nullable_uint64(value));
}

attribute_t *create_remaining_duration(cluster_t *cluster, nullable<uint32_t> value)
{
return esp_matter::attribute::create(cluster, ValveConfigurationAndControl::Attributes::RemainingDuration::Id, ATTRIBUTE_FLAG_NULLABLE, esp_matter_nullable_uint32(value));
}

attribute_t *create_current_state(cluster_t *cluster, nullable<uint8_t> value)
{
return esp_matter::attribute::create(cluster, ValveConfigurationAndControl::Attributes::CurrentState::Id, ATTRIBUTE_FLAG_NULLABLE, esp_matter_nullable_enum8(value));
}

attribute_t *create_target_state(cluster_t *cluster, nullable<uint8_t> value)
{
return esp_matter::attribute::create(cluster, ValveConfigurationAndControl::Attributes::TargetState::Id, ATTRIBUTE_FLAG_NULLABLE, esp_matter_nullable_enum8(value));
}

attribute_t *create_current_level(cluster_t *cluster, nullable<uint8_t> value)
{
return esp_matter::attribute::create(cluster, ValveConfigurationAndControl::Attributes::CurrentLevel::Id, ATTRIBUTE_FLAG_NULLABLE, esp_matter_nullable_uint8(value));
}

attribute_t *create_target_level(cluster_t *cluster, nullable<uint8_t> value)
{
return esp_matter::attribute::create(cluster, ValveConfigurationAndControl::Attributes::TargetLevel::Id, ATTRIBUTE_FLAG_NULLABLE, esp_matter_nullable_uint8(value));
}

attribute_t *create_default_open_level(cluster_t *cluster, uint8_t value)
{
return esp_matter::attribute::create(cluster, ValveConfigurationAndControl::Attributes::DefaultOpenLevel::Id, ATTRIBUTE_FLAG_NONVOLATILE | ATTRIBUTE_FLAG_WRITABLE, esp_matter_uint8(value));
}

attribute_t *create_valve_fault(cluster_t *cluster, uint16_t value)
{
return esp_matter::attribute::create(cluster, ValveConfigurationAndControl::Attributes::ValveFault::Id, ATTRIBUTE_FLAG_NONE, esp_matter_bitmap16(value));
}

attribute_t *create_level_step(cluster_t *cluster, const uint8_t value)
{
return esp_matter::attribute::create(cluster, ValveConfigurationAndControl::Attributes::LevelStep::Id, ATTRIBUTE_FLAG_NONE, esp_matter_uint8(value));
}

} /* attribute */
} /* valve_configuration_and_control */

} /* cluster */
} /* esp_matter */
16 changes: 16 additions & 0 deletions components/esp_matter/esp_matter_attribute.h
Original file line number Diff line number Diff line change
Expand Up @@ -1061,5 +1061,21 @@ attribute_t *create_watt_rating(cluster_t *cluster, uint16_t value);
} /* attribute */
} /* microwave_oven_control */

namespace valve_configuration_and_control {
namespace attribute {
attribute_t *create_open_duration(cluster_t *cluster, nullable<uint32_t> value);
attribute_t *create_default_open_duration(cluster_t *cluster, nullable<uint32_t> value);
attribute_t *create_auto_close_time(cluster_t *cluster, nullable<uint64_t> value);
attribute_t *create_remaining_duration(cluster_t *cluster, nullable<uint32_t> value);
attribute_t *create_current_state(cluster_t *cluster, nullable<uint8_t> value);
attribute_t *create_target_state(cluster_t *cluster, nullable<uint8_t> value);
attribute_t *create_current_level(cluster_t *cluster, nullable<uint8_t> value);
attribute_t *create_target_level(cluster_t *cluster, nullable<uint8_t> value);
attribute_t *create_default_open_level(cluster_t *cluster, uint8_t value);
attribute_t *create_valve_fault(cluster_t *cluster, uint16_t value);
attribute_t *create_level_step(cluster_t *cluster, const uint8_t value);
} /* attribute */
} /* valve_configuration_and_control */

} /* cluster */
} /* esp_matter */
62 changes: 61 additions & 1 deletion components/esp_matter/esp_matter_cluster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3921,7 +3921,7 @@ cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags, uint32_
}
}

/* Features */
/* Features */
if (features & feature::charging_preferences::get_id()) {
feature::charging_preferences::add(cluster);
}
Expand All @@ -3946,6 +3946,66 @@ cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags, uint32_
}
} /* energy_evse */

namespace valve_configuration_and_control {
const function_generic_t *function_list = NULL;
const int function_flags = CLUSTER_FLAG_NONE;

cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags, uint32_t features)
{
cluster_t *cluster = cluster::create(endpoint, ValveConfigurationAndControl::Id, flags);
if (!cluster) {
ESP_LOGE(TAG, "Could not create cluster");
return NULL;
}
if (flags & CLUSTER_FLAG_SERVER) {
if (config -> delegate != nullptr) {
static const auto delegate_init_cb = ValveConfigurationAndControlDelegateInitCB;
set_delegate_and_init_callback(cluster, delegate_init_cb, config->delegate);
}
static const auto plugin_server_init_cb = CALL_ONCE(MatterValveConfigurationAndControlPluginServerInitCallback);
set_plugin_server_init_callback(cluster, plugin_server_init_cb);
add_function_list(cluster, function_list, function_flags);
}
if (flags & CLUSTER_FLAG_CLIENT) {
create_default_binding_cluster(endpoint);
}

if (flags & CLUSTER_FLAG_SERVER) {
/* Attributes managed internally */
global::attribute::create_feature_map(cluster, 0);
attribute::create_remaining_duration(cluster, 0);
#if CHIP_CONFIG_ENABLE_EVENTLIST_ATTRIBUTE
global::attribute::create_event_list(cluster, NULL, 0, 0);
#endif

/** Attributes not managed internally **/
if (config) {
global::attribute::create_cluster_revision(cluster, config->cluster_revision);
attribute::create_open_duration(cluster, config->open_duration);
attribute::create_default_open_duration(cluster, config->default_open_duration);
attribute::create_current_state(cluster, config->current_state);
attribute::create_target_state(cluster, config->target_state);
} else {
ESP_LOGE(TAG, "Config is NULL. Cannot add some attributes.");
}
}

/* Commands */
command::create_open(cluster);
command::create_close(cluster);

/* Features */
if (features & feature::time_sync::get_id()) {
feature::time_sync::add(cluster, &(config->time_sync));
}
if (features & feature::level::get_id()) {
feature::level::add(cluster, &(config->level));
}

return cluster;
}
} /* valve_configuration_and_control */

// namespace binary_input_basic {
// // ToDo
// } /* binary_input_basic */
Expand Down
16 changes: 16 additions & 0 deletions components/esp_matter/esp_matter_cluster.h
Original file line number Diff line number Diff line change
Expand Up @@ -943,5 +943,21 @@ typedef struct config {
cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags, uint32_t features);
} /* energy_evse */

namespace valve_configuration_and_control {
typedef struct config {
uint16_t cluster_revision;
nullable<uint32_t> open_duration;
nullable<uint32_t> default_open_duration;
nullable<uint8_t> current_state;
nullable<uint8_t> target_state;
feature::time_sync::config_t time_sync;
feature::level::config_t level;
void *delegate;
config() : cluster_revision(1), open_duration(), default_open_duration(), current_state(), target_state(), delegate(nullptr) {}
} config_t;

cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags, uint32_t features);
} /* valve_configuration_and_control */

} /* cluster */
} /* esp_matter */
35 changes: 35 additions & 0 deletions components/esp_matter/esp_matter_command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1456,6 +1456,26 @@ static esp_err_t esp_matter_command_callback_enable_disable_alarm(const Concrete
return ESP_OK;
}

static esp_err_t esp_matter_command_callback_open(const ConcreteCommandPath &command_path, TLVReader &tlv_data, void *opaque_ptr)
{
chip::app::Clusters::ValveConfigurationAndControl::Commands::Open::DecodableType command_data;
CHIP_ERROR error = Decode(tlv_data, command_data);
if (error == CHIP_NO_ERROR) {
emberAfValveConfigurationAndControlClusterOpenCallback((CommandHandler *)opaque_ptr, command_path, command_data);
}
return ESP_OK;
}

static esp_err_t esp_matter_command_callback_close(const ConcreteCommandPath &command_path, TLVReader &tlv_data, void *opaque_ptr)
{
chip::app::Clusters::ValveConfigurationAndControl::Commands::Close::DecodableType command_data;
CHIP_ERROR error = Decode(tlv_data, command_data);
if (error == CHIP_NO_ERROR) {
emberAfValveConfigurationAndControlClusterCloseCallback((CommandHandler *)opaque_ptr, command_path, command_data);
}
return ESP_OK;
}

namespace esp_matter {
namespace cluster {

Expand Down Expand Up @@ -2779,6 +2799,21 @@ command_t *create_add_more_time(cluster_t *cluster)
} /* command */
} /* microwave_oven_control */

namespace valve_configuration_and_control {
namespace command {
command_t *create_open(cluster_t *cluster)
{
return esp_matter::command::create(cluster, ValveConfigurationAndControl::Commands::Open::Id, COMMAND_FLAG_ACCEPTED, esp_matter_command_callback_open);
}

command_t *create_close(cluster_t *cluster)
{
return esp_matter::command::create(cluster, ValveConfigurationAndControl::Commands::Close::Id, COMMAND_FLAG_ACCEPTED, esp_matter_command_callback_close);
}

} /* command */
} /* valve_configuration_and_control */

} /* cluster */
} /* esp_matter */

Expand Down
7 changes: 7 additions & 0 deletions components/esp_matter/esp_matter_command.h
Original file line number Diff line number Diff line change
Expand Up @@ -397,5 +397,12 @@ command_t *create_add_more_time(cluster_t *cluster);
} /* command */
} /* microwave_oven_control */

namespace valve_configuration_and_control {
namespace command {
command_t *create_open(cluster_t *cluster);
command_t *create_close(cluster_t *cluster);
} /* command */
} /* valve_configuration_and_control */

} /* cluster */
} /* esp_matter */
11 changes: 11 additions & 0 deletions components/esp_matter/esp_matter_delegate_callbacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <app/clusters/resource-monitoring-server/resource-monitoring-server.h>
#include <app/clusters/fan-control-server/fan-control-server.h>
#include <app/clusters/laundry-dryer-controls-server/laundry-dryer-controls-server.h>
#include <app/clusters/valve-configuration-and-control-server/valve-configuration-and-control-server.h>

using namespace chip::app::Clusters;
namespace esp_matter {
Expand Down Expand Up @@ -194,6 +195,16 @@ void LaundryDryerControlsDelegateInitCB(void *delegate, uint16_t endpoint_id)
LaundryDryerControls::LaundryDryerControlsServer::SetDefaultDelegate(endpoint_id, laundry_dryer_controls_delegate);
}

void ValveConfigurationAndControlDelegateInitCB(void *delegate, uint16_t endpoint_id)
{
if(delegate == nullptr)
{
return;
}
ValveConfigurationAndControl::Delegate *valve_configuration_and_control_delegate = static_cast<ValveConfigurationAndControl::Delegate*>(delegate);
ValveConfigurationAndControl::SetDefaultDelegate(endpoint_id, valve_configuration_and_control_delegate);
}

} // namespace delegate_cb

} // namespace cluster
Expand Down
1 change: 1 addition & 0 deletions components/esp_matter/esp_matter_delegate_callbacks.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ void FanControlDelegateInitCB(void *delegate, uint16_t endpoint_id);
void HepaFilterMonitoringDelegateInitCB(void *delegate, uint16_t endpoint_id);
void ActivatedCarbonFilterMonitoringDelegateInitCB(void *delegate, uint16_t endpoint_id);
void LaundryDryerControlsDelegateInitCB(void *delegate, uint16_t endpoint_id);
void ValveConfigurationAndControlDelegateInitCB(void *delegate, uint16_t endpoint_id);
} // namespace delegate_cb

} // namespace cluster
Expand Down
39 changes: 39 additions & 0 deletions components/esp_matter/esp_matter_endpoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1905,6 +1905,45 @@ esp_err_t add(endpoint_t *endpoint, config_t *config)
}
} /* extractor_hood */

namespace water_valve {

uint32_t get_device_type_id()
{
return ESP_MATTER_WATER_VALVE_DEVICE_TYPE_ID;
}

uint8_t get_device_type_version()
{
return ESP_MATTER_WATER_VALVE_DEVICE_TYPE_VERSION;
}

endpoint_t *create(node_t *node, config_t *config, uint8_t flags, void *priv_data)
{
endpoint_t *endpoint = endpoint::create(node, flags, priv_data);
add(endpoint, config);
return endpoint;
}

esp_err_t add(endpoint_t *endpoint, config_t *config)
{
if (!endpoint) {
ESP_LOGE(TAG, "Endpoint cannot be NULL");
return ESP_ERR_INVALID_ARG;
}
esp_err_t err = add_device_type(endpoint, get_device_type_id(), get_device_type_version());
if (err != ESP_OK) {
ESP_LOGE(TAG, "Failed to add device type id:%" PRIu32 ",err: %d", get_device_type_id(), err);
return err;
}

identify::create(endpoint, &(config->identify), CLUSTER_FLAG_SERVER);
descriptor::create(endpoint, &(config->descriptor), CLUSTER_FLAG_SERVER);
valve_configuration_and_control::create(endpoint, &(config->valve_configuration_and_control), CLUSTER_FLAG_SERVER, ESP_MATTER_NONE_FEATURE_ID);

return ESP_OK;
}
} /** water_valve **/

} /* endpoint */

namespace node {
Expand Down
15 changes: 15 additions & 0 deletions components/esp_matter/esp_matter_endpoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@
#define ESP_MATTER_ENERGY_EVSE_DEVICE_TYPE_VERSION 1
#define ESP_MATTER_EXTRACTOR_HOOD_DEVICE_TYPE_ID 0x007A
#define ESP_MATTER_EXTRACTOR_HOOD_DEVICE_TYPE_VERSION 1
#define ESP_MATTER_WATER_VALVE_DEVICE_TYPE_ID 0x0042
#define ESP_MATTER_WATER_VALVE_DEVICE_TYPE_VERSION 1

namespace esp_matter {

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

namespace water_valve {
typedef struct config {
cluster::descriptor::config_t descriptor;
cluster::identify::config_t identify;
cluster::valve_configuration_and_control::config_t valve_configuration_and_control;
} config_t;

uint32_t get_device_type_id();
uint8_t get_device_type_version();
endpoint_t *create(node_t *node, config_t *config, uint8_t flags, void *priv_data);
esp_err_t add(endpoint_t *endpoint, config_t *config);
} /** water_valve **/

} /* endpoint */

namespace node {
Expand Down
14 changes: 14 additions & 0 deletions components/esp_matter/esp_matter_event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -705,5 +705,19 @@ event_t *create_periodic_energy_measured(cluster_t *cluster)
} // namespace event
} // namespace electrical_energy_measurement

namespace valve_configuration_and_control {
namespace event {
event_t *create_valve_state_changed(cluster_t *cluster)
{
return esp_matter::event::create(cluster, ValveConfigurationAndControl::Events::ValveStateChanged::Id);
}

event_t *create_valve_fault(cluster_t *cluster)
{
return esp_matter::event::create(cluster, ValveConfigurationAndControl::Events::ValveFault::Id);
}
} // namespace event
} // namespace valve_configuration_and_control

} // namespace cluster
} // namespace esp_matter
7 changes: 7 additions & 0 deletions components/esp_matter/esp_matter_event.h
Original file line number Diff line number Diff line change
Expand Up @@ -207,5 +207,12 @@ event_t *create_periodic_energy_measured(cluster_t *cluster);
} // namespace event
} // namespace electrical_energy_measurement

namespace valve_configuration_and_control {
namespace event {
event_t *create_valve_state_changed(cluster_t *cluster);
event_t *create_valve_fault(cluster_t *cluster);
} // namespace event
} // namespace valve_configuration_and_control

} // namespace cluster
} // namespace esp_matter
Loading

0 comments on commit f21874c

Please sign in to comment.