Skip to content

Commit ca174c7

Browse files
committed
Merge branch 'device/rain_sensor' into 'main'
Add Rain Sensor device type See merge request app-frameworks/esp-matter!661
2 parents 434aa0b + b3f5a9a commit ca174c7

15 files changed

+419
-4
lines changed

components/esp_matter/esp_matter_attribute.cpp

+54-1
Original file line numberDiff line numberDiff line change
@@ -3316,7 +3316,7 @@ attribute_t *create_occupancy_sensor_type_bitmap(cluster_t *cluster, uint8_t val
33163316
namespace boolean_state {
33173317
namespace attribute {
33183318

3319-
attribute_t *state_value(cluster_t *cluster, bool value)
3319+
attribute_t *create_state_value(cluster_t *cluster, bool value)
33203320
{
33213321
return esp_matter::attribute::create(cluster, BooleanState::Attributes::StateValue::Id, ATTRIBUTE_FLAG_NONE,
33223322
esp_matter_bool(value));
@@ -3325,6 +3325,59 @@ attribute_t *state_value(cluster_t *cluster, bool value)
33253325
} /* attribute */
33263326
} /* boolean_state */
33273327

3328+
namespace boolean_state_configuration {
3329+
namespace attribute {
3330+
attribute_t *create_current_sensitivity_level(cluster_t *cluster, uint8_t value)
3331+
{
3332+
return esp_matter::attribute::create(cluster, BooleanStateConfiguration::Attributes::CurrentSensitivityLevel::Id, ATTRIBUTE_FLAG_NONVOLATILE,
3333+
esp_matter_uint8(value));
3334+
}
3335+
3336+
attribute_t *create_supported_sensitivity_levels(cluster_t *cluster, const uint8_t value)
3337+
{
3338+
return esp_matter::attribute::create(cluster, BooleanStateConfiguration::Attributes::SupportedSensitivityLevels::Id, ATTRIBUTE_FLAG_NONE,
3339+
esp_matter_uint8(value));
3340+
}
3341+
3342+
attribute_t *create_default_sensitivity_level(cluster_t *cluster, const uint8_t value)
3343+
{
3344+
return esp_matter::attribute::create(cluster, BooleanStateConfiguration::Attributes::DefaultSensitivityLevel::Id, ATTRIBUTE_FLAG_NONE,
3345+
esp_matter_uint8(value));
3346+
}
3347+
3348+
attribute_t *create_alarms_active(cluster_t *cluster, uint8_t value)
3349+
{
3350+
return esp_matter::attribute::create(cluster, BooleanStateConfiguration::Attributes::AlarmsActive::Id, ATTRIBUTE_FLAG_NONE,
3351+
esp_matter_bitmap8(value));
3352+
}
3353+
3354+
attribute_t *create_alarms_suppressed(cluster_t *cluster, uint8_t value)
3355+
{
3356+
return esp_matter::attribute::create(cluster, BooleanStateConfiguration::Attributes::AlarmsSuppressed::Id, ATTRIBUTE_FLAG_NONE,
3357+
esp_matter_bitmap8(value));
3358+
}
3359+
3360+
attribute_t *create_alarms_enabled(cluster_t *cluster, uint8_t value)
3361+
{
3362+
return esp_matter::attribute::create(cluster, BooleanStateConfiguration::Attributes::AlarmsEnabled::Id, ATTRIBUTE_FLAG_NONVOLATILE,
3363+
esp_matter_bitmap8(value));
3364+
}
3365+
3366+
attribute_t *create_alarms_supported(cluster_t *cluster, const uint8_t value)
3367+
{
3368+
return esp_matter::attribute::create(cluster, BooleanStateConfiguration::Attributes::AlarmsSupported::Id, ATTRIBUTE_FLAG_NONE,
3369+
esp_matter_bitmap8(value));
3370+
}
3371+
3372+
attribute_t *create_sensor_fault(cluster_t *cluster, uint8_t value)
3373+
{
3374+
return esp_matter::attribute::create(cluster, BooleanStateConfiguration::Attributes::SensorFault::Id, ATTRIBUTE_FLAG_NONE,
3375+
esp_matter_bitmap8(value));
3376+
}
3377+
3378+
} /* attribute */
3379+
} /* boolean_state_configuration */
3380+
33283381
namespace localization_configuration {
33293382
namespace attribute {
33303383

components/esp_matter/esp_matter_attribute.h

+14-1
Original file line numberDiff line numberDiff line change
@@ -762,10 +762,23 @@ attribute_t *create_occupancy_sensor_type_bitmap(cluster_t *cluster, uint8_t val
762762

763763
namespace boolean_state {
764764
namespace attribute {
765-
attribute_t *state_value(cluster_t *cluster, bool value);
765+
attribute_t *create_state_value(cluster_t *cluster, bool value);
766766
} /* attribute */
767767
} /* boolean_state */
768768

769+
namespace boolean_state_configuration {
770+
namespace attribute {
771+
attribute_t *create_current_sensitivity_level(cluster_t *cluster, uint8_t value);
772+
attribute_t *create_supported_sensitivity_levels(cluster_t *cluster, const uint8_t value);
773+
attribute_t *create_default_sensitivity_level(cluster_t *cluster, const uint8_t value);
774+
attribute_t *create_alarms_active(cluster_t *cluster, uint8_t value);
775+
attribute_t *create_alarms_suppressed(cluster_t *cluster, uint8_t value);
776+
attribute_t *create_alarms_enabled(cluster_t *cluster, uint8_t value);
777+
attribute_t *create_alarms_supported(cluster_t *cluster, const uint8_t value);
778+
attribute_t *create_sensor_fault(cluster_t *cluster, uint8_t value);
779+
} /* attribute */
780+
} /* boolean_state_configuration */
781+
769782
namespace localization_configuration {
770783

771784
constexpr uint8_t k_max_active_locale_length = 35;

components/esp_matter/esp_matter_cluster.cpp

+55-1
Original file line numberDiff line numberDiff line change
@@ -2677,7 +2677,7 @@ cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags)
26772677
/* Attributes not managed internally */
26782678
if (config) {
26792679
global::attribute::create_cluster_revision(cluster, config->cluster_revision);
2680-
attribute::state_value(cluster, config->state_value);
2680+
attribute::create_state_value(cluster, config->state_value);
26812681
} else {
26822682
ESP_LOGE(TAG, "Config is NULL. Cannot add some attributes.");
26832683
}
@@ -2687,6 +2687,60 @@ cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags)
26872687
}
26882688
} /* boolean_state */
26892689

2690+
namespace boolean_state_configuration {
2691+
const function_generic_t *function_list = NULL;
2692+
const int function_flags = CLUSTER_FLAG_NONE;
2693+
2694+
cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags, uint32_t features)
2695+
{
2696+
cluster_t *cluster = cluster::create(endpoint, BooleanStateConfiguration::Id, flags);
2697+
if (!cluster) {
2698+
ESP_LOGE(TAG, "Could not create cluster");
2699+
return NULL;
2700+
}
2701+
2702+
if (flags & CLUSTER_FLAG_SERVER) {
2703+
static const auto plugin_server_init_cb = CALL_ONCE(MatterBooleanStateConfigurationPluginServerInitCallback);
2704+
set_plugin_server_init_callback(cluster, plugin_server_init_cb);
2705+
add_function_list(cluster, function_list, function_flags);
2706+
}
2707+
if (flags & CLUSTER_FLAG_CLIENT) {
2708+
create_default_binding_cluster(endpoint);
2709+
}
2710+
2711+
if (flags & CLUSTER_FLAG_SERVER) {
2712+
/* Attributes managed internally */
2713+
global::attribute::create_feature_map(cluster, 0);
2714+
#if CHIP_CONFIG_ENABLE_EVENTLIST_ATTRIBUTE
2715+
global::attribute::create_event_list(cluster, NULL, 0, 0);
2716+
#endif
2717+
2718+
/* Attributes not managed internally */
2719+
if (config) {
2720+
global::attribute::create_cluster_revision(cluster, config->cluster_revision);
2721+
} else {
2722+
ESP_LOGE(TAG, "Config is NULL. Cannot add some attributes.");
2723+
}
2724+
}
2725+
2726+
2727+
/* Features */
2728+
if (features & feature::visual::get_id()) {
2729+
feature::visual::add(cluster, &(config->visual));
2730+
}
2731+
if (features & feature::audible::get_id()) {
2732+
feature::audible::add(cluster, &(config->audible));
2733+
}
2734+
if (features & feature::alarm_suppress::get_id()) {
2735+
feature::alarm_suppress::add(cluster, &(config->alarm_suppress));
2736+
}
2737+
if (features & feature::sensitivity_level::get_id()) {
2738+
feature::sensitivity_level::add(cluster, &(config->sensitivity_level));
2739+
}
2740+
return cluster;
2741+
}
2742+
} /* boolean_state_configuration */
2743+
26902744
namespace localization_configuration {
26912745
const function_generic_t function_list[] = {
26922746
(function_generic_t)emberAfLocalizationConfigurationClusterServerInitCallback,

components/esp_matter/esp_matter_cluster.h

+13
Original file line numberDiff line numberDiff line change
@@ -655,6 +655,19 @@ typedef struct config {
655655
cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags);
656656
} /* boolean_state */
657657

658+
namespace boolean_state_configuration {
659+
typedef struct config {
660+
uint16_t cluster_revision;
661+
feature::visual::config_t visual;
662+
feature::audible::config_t audible;
663+
feature::alarm_suppress::config_t alarm_suppress;
664+
feature::sensitivity_level::config_t sensitivity_level;
665+
config() : cluster_revision(1) {}
666+
} config_t;
667+
668+
cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags, uint32_t features);
669+
} /* boolean_state */
670+
658671
namespace localization_configuration {
659672
typedef struct config {
660673
uint16_t cluster_revision;

components/esp_matter/esp_matter_command.cpp

+35
Original file line numberDiff line numberDiff line change
@@ -1248,6 +1248,26 @@ static esp_err_t esp_matter_command_callback_send_key(const ConcreteCommandPath
12481248
return ESP_OK;
12491249
}
12501250

1251+
static esp_err_t esp_matter_command_callback_suppress_alarm(const ConcreteCommandPath &command_path, TLVReader &tlv_data, void *opaque_ptr)
1252+
{
1253+
chip::app::Clusters::BooleanStateConfiguration::Commands::SuppressAlarm::DecodableType command_data;
1254+
CHIP_ERROR error = Decode(tlv_data, command_data);
1255+
if (error == CHIP_NO_ERROR) {
1256+
emberAfBooleanStateConfigurationClusterSuppressAlarmCallback((CommandHandler *)opaque_ptr, command_path, command_data);
1257+
}
1258+
return ESP_OK;
1259+
}
1260+
1261+
static esp_err_t esp_matter_command_callback_enable_disable_alarm(const ConcreteCommandPath &command_path, TLVReader &tlv_data, void *opaque_ptr)
1262+
{
1263+
chip::app::Clusters::BooleanStateConfiguration::Commands::EnableDisableAlarm::DecodableType command_data;
1264+
CHIP_ERROR error = Decode(tlv_data, command_data);
1265+
if (error == CHIP_NO_ERROR) {
1266+
emberAfBooleanStateConfigurationClusterEnableDisableAlarmCallback((CommandHandler *)opaque_ptr, command_path, command_data);
1267+
}
1268+
return ESP_OK;
1269+
}
1270+
12511271
namespace esp_matter {
12521272
namespace cluster {
12531273

@@ -2381,6 +2401,21 @@ command_t *create_send_key_response(cluster_t *cluster)
23812401
} /* command */
23822402
} /* keypad_input */
23832403

2404+
namespace boolean_state_configuration {
2405+
namespace command {
2406+
command_t *create_suppress_alarm(cluster_t *cluster)
2407+
{
2408+
return esp_matter::command::create(cluster, BooleanStateConfiguration::Commands::SuppressAlarm::Id, COMMAND_FLAG_ACCEPTED, esp_matter_command_callback_suppress_alarm);
2409+
}
2410+
2411+
command_t *create_enable_disable_alarm(cluster_t *cluster)
2412+
{
2413+
return esp_matter::command::create(cluster, BooleanStateConfiguration::Commands::EnableDisableAlarm::Id, COMMAND_FLAG_ACCEPTED, esp_matter_command_callback_enable_disable_alarm);
2414+
}
2415+
2416+
} /* command */
2417+
} /* boolean_state_configuration */
2418+
23842419
} /* cluster */
23852420
} /* esp_matter */
23862421

components/esp_matter/esp_matter_command.h

+7
Original file line numberDiff line numberDiff line change
@@ -364,5 +364,12 @@ command_t *create_send_key_response(cluster_t *cluster);
364364
} /* command */
365365
} /* keypad_input */
366366

367+
namespace boolean_state_configuration {
368+
namespace command {
369+
command_t *create_suppress_alarm(cluster_t *cluster);
370+
command_t *create_enable_disable_alarm(cluster_t *cluster);
371+
} /* command */
372+
} /* boolean_state_configuration */
373+
367374
} /* cluster */
368375
} /* esp_matter */

components/esp_matter/esp_matter_endpoint.cpp

+39
Original file line numberDiff line numberDiff line change
@@ -1516,6 +1516,45 @@ esp_err_t add(endpoint_t *endpoint, config_t *config)
15161516
}
15171517
} /* water_leak_detector */
15181518

1519+
namespace rain_sensor {
1520+
uint32_t get_device_type_id()
1521+
{
1522+
return ESP_MATTER_RAIN_SENSOR_DEVICE_TYPE_ID;
1523+
}
1524+
1525+
uint8_t get_device_type_version()
1526+
{
1527+
return ESP_MATTER_RAIN_SENSOR_DEVICE_TYPE_VERSION;
1528+
}
1529+
1530+
endpoint_t *create(node_t *node, config_t *config, uint8_t flags, void *priv_data)
1531+
{
1532+
endpoint_t *endpoint = endpoint::create(node, flags, priv_data);
1533+
add(endpoint, config);
1534+
return endpoint;
1535+
}
1536+
1537+
esp_err_t add(endpoint_t *endpoint, config_t *config)
1538+
{
1539+
if (!endpoint) {
1540+
ESP_LOGE(TAG, "Endpoint cannot be NULL");
1541+
return ESP_ERR_INVALID_ARG;
1542+
}
1543+
esp_err_t err = add_device_type(endpoint, get_device_type_id(), get_device_type_version());
1544+
if (err != ESP_OK) {
1545+
ESP_LOGE(TAG, "Failed to add device type id:%" PRIu32 ",err: %d", get_device_type_id(), err);
1546+
return err;
1547+
}
1548+
1549+
descriptor::create(endpoint, &(config->descriptor), CLUSTER_FLAG_SERVER);
1550+
identify::create(endpoint, &(config->identify), CLUSTER_FLAG_SERVER);
1551+
cluster_t *cluster = boolean_state::create(endpoint, &(config->boolean_state), CLUSTER_FLAG_SERVER);
1552+
1553+
boolean_state::event::create_state_change(cluster);
1554+
return ESP_OK;
1555+
}
1556+
} /* rain_sensor */
1557+
15191558
} /* endpoint */
15201559

15211560
namespace node {

components/esp_matter/esp_matter_endpoint.h

+15
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@
9898
#define ESP_MATTER_ROBOTIC_VACCUM_CLEANER_DEVICE_TYPE_VERSION 1
9999
#define ESP_MATTER_WATER_LEAK_DETECTOR_DEVICE_TYPE_ID 0x0043
100100
#define ESP_MATTER_WATER_LEAK_DETECTOR_DEVICE_TYPE_VERSION 1
101+
#define ESP_MATTER_RAIN_SENSOR_DEVICE_TYPE_ID 0x0044
102+
#define ESP_MATTER_RAIN_SENSOR_DEVICE_TYPE_VERSION 1
101103

102104
namespace esp_matter {
103105

@@ -621,6 +623,19 @@ endpoint_t *create(node_t *node, config_t *config, uint8_t flags, void *priv_dat
621623
esp_err_t add(endpoint_t *endpoint, config_t *config);
622624
} /* water_leak_detector */
623625

626+
namespace rain_sensor {
627+
typedef struct config {
628+
cluster::descriptor::config_t descriptor;
629+
cluster::identify::config_t identify;
630+
cluster::boolean_state::config_t boolean_state;
631+
} config_t;
632+
633+
uint32_t get_device_type_id();
634+
uint8_t get_device_type_version();
635+
endpoint_t *create(node_t *node, config_t *config, uint8_t flags, void *priv_data);
636+
esp_err_t add(endpoint_t *endpoint, config_t *config);
637+
} /* rain_sensor */
638+
624639
} /* endpoint */
625640

626641
namespace node {

components/esp_matter/esp_matter_event.cpp

+16
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,22 @@ event_t *create_state_change(cluster_t *cluster)
453453
} // namespace event
454454
} // namespace boolean_state
455455

456+
namespace boolean_state_configuration {
457+
namespace event {
458+
459+
event_t *create_alarms_state_changed(cluster_t *cluster)
460+
{
461+
return esp_matter::event::create(cluster, BooleanStateConfiguration::Events::AlarmsStateChanged::Id);
462+
}
463+
464+
event_t *create_sensor_fault(cluster_t *cluster)
465+
{
466+
return esp_matter::event::create(cluster, BooleanStateConfiguration::Events::SensorFault::Id);
467+
}
468+
469+
} // namespace event
470+
} // namespace boolean_state_configuration
471+
456472
namespace operational_state {
457473
namespace event {
458474

components/esp_matter/esp_matter_event.h

+7
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,13 @@ event_t *create_state_change(cluster_t *cluster);
158158
} // namespace event
159159
} // namespace boolean_state
160160

161+
namespace boolean_state_configuration {
162+
namespace event {
163+
event_t *create_alarms_state_changed(cluster_t *cluster);
164+
event_t *create_sensor_fault(cluster_t *cluster);
165+
} // namespace event
166+
} // namespace boolean_state_configuration
167+
161168
namespace operational_state {
162169
namespace event {
163170
event_t *create_operational_error(cluster_t *cluster);

0 commit comments

Comments
 (0)