Skip to content

Commit

Permalink
Merge branch 'device/rain_sensor' into 'main'
Browse files Browse the repository at this point in the history
Add Rain Sensor device type

See merge request app-frameworks/esp-matter!661
  • Loading branch information
dhrishi committed Apr 2, 2024
2 parents 434aa0b + b3f5a9a commit ca174c7
Show file tree
Hide file tree
Showing 15 changed files with 419 additions and 4 deletions.
55 changes: 54 additions & 1 deletion components/esp_matter/esp_matter_attribute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3316,7 +3316,7 @@ attribute_t *create_occupancy_sensor_type_bitmap(cluster_t *cluster, uint8_t val
namespace boolean_state {
namespace attribute {

attribute_t *state_value(cluster_t *cluster, bool value)
attribute_t *create_state_value(cluster_t *cluster, bool value)
{
return esp_matter::attribute::create(cluster, BooleanState::Attributes::StateValue::Id, ATTRIBUTE_FLAG_NONE,
esp_matter_bool(value));
Expand All @@ -3325,6 +3325,59 @@ attribute_t *state_value(cluster_t *cluster, bool value)
} /* attribute */
} /* boolean_state */

namespace boolean_state_configuration {
namespace attribute {
attribute_t *create_current_sensitivity_level(cluster_t *cluster, uint8_t value)
{
return esp_matter::attribute::create(cluster, BooleanStateConfiguration::Attributes::CurrentSensitivityLevel::Id, ATTRIBUTE_FLAG_NONVOLATILE,
esp_matter_uint8(value));
}

attribute_t *create_supported_sensitivity_levels(cluster_t *cluster, const uint8_t value)
{
return esp_matter::attribute::create(cluster, BooleanStateConfiguration::Attributes::SupportedSensitivityLevels::Id, ATTRIBUTE_FLAG_NONE,
esp_matter_uint8(value));
}

attribute_t *create_default_sensitivity_level(cluster_t *cluster, const uint8_t value)
{
return esp_matter::attribute::create(cluster, BooleanStateConfiguration::Attributes::DefaultSensitivityLevel::Id, ATTRIBUTE_FLAG_NONE,
esp_matter_uint8(value));
}

attribute_t *create_alarms_active(cluster_t *cluster, uint8_t value)
{
return esp_matter::attribute::create(cluster, BooleanStateConfiguration::Attributes::AlarmsActive::Id, ATTRIBUTE_FLAG_NONE,
esp_matter_bitmap8(value));
}

attribute_t *create_alarms_suppressed(cluster_t *cluster, uint8_t value)
{
return esp_matter::attribute::create(cluster, BooleanStateConfiguration::Attributes::AlarmsSuppressed::Id, ATTRIBUTE_FLAG_NONE,
esp_matter_bitmap8(value));
}

attribute_t *create_alarms_enabled(cluster_t *cluster, uint8_t value)
{
return esp_matter::attribute::create(cluster, BooleanStateConfiguration::Attributes::AlarmsEnabled::Id, ATTRIBUTE_FLAG_NONVOLATILE,
esp_matter_bitmap8(value));
}

attribute_t *create_alarms_supported(cluster_t *cluster, const uint8_t value)
{
return esp_matter::attribute::create(cluster, BooleanStateConfiguration::Attributes::AlarmsSupported::Id, ATTRIBUTE_FLAG_NONE,
esp_matter_bitmap8(value));
}

attribute_t *create_sensor_fault(cluster_t *cluster, uint8_t value)
{
return esp_matter::attribute::create(cluster, BooleanStateConfiguration::Attributes::SensorFault::Id, ATTRIBUTE_FLAG_NONE,
esp_matter_bitmap8(value));
}

} /* attribute */
} /* boolean_state_configuration */

namespace localization_configuration {
namespace attribute {

Expand Down
15 changes: 14 additions & 1 deletion components/esp_matter/esp_matter_attribute.h
Original file line number Diff line number Diff line change
Expand Up @@ -762,10 +762,23 @@ attribute_t *create_occupancy_sensor_type_bitmap(cluster_t *cluster, uint8_t val

namespace boolean_state {
namespace attribute {
attribute_t *state_value(cluster_t *cluster, bool value);
attribute_t *create_state_value(cluster_t *cluster, bool value);
} /* attribute */
} /* boolean_state */

namespace boolean_state_configuration {
namespace attribute {
attribute_t *create_current_sensitivity_level(cluster_t *cluster, uint8_t value);
attribute_t *create_supported_sensitivity_levels(cluster_t *cluster, const uint8_t value);
attribute_t *create_default_sensitivity_level(cluster_t *cluster, const uint8_t value);
attribute_t *create_alarms_active(cluster_t *cluster, uint8_t value);
attribute_t *create_alarms_suppressed(cluster_t *cluster, uint8_t value);
attribute_t *create_alarms_enabled(cluster_t *cluster, uint8_t value);
attribute_t *create_alarms_supported(cluster_t *cluster, const uint8_t value);
attribute_t *create_sensor_fault(cluster_t *cluster, uint8_t value);
} /* attribute */
} /* boolean_state_configuration */

namespace localization_configuration {

constexpr uint8_t k_max_active_locale_length = 35;
Expand Down
56 changes: 55 additions & 1 deletion components/esp_matter/esp_matter_cluster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2677,7 +2677,7 @@ cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags)
/* Attributes not managed internally */
if (config) {
global::attribute::create_cluster_revision(cluster, config->cluster_revision);
attribute::state_value(cluster, config->state_value);
attribute::create_state_value(cluster, config->state_value);
} else {
ESP_LOGE(TAG, "Config is NULL. Cannot add some attributes.");
}
Expand All @@ -2687,6 +2687,60 @@ cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags)
}
} /* boolean_state */

namespace boolean_state_configuration {
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, BooleanStateConfiguration::Id, flags);
if (!cluster) {
ESP_LOGE(TAG, "Could not create cluster");
return NULL;
}

if (flags & CLUSTER_FLAG_SERVER) {
static const auto plugin_server_init_cb = CALL_ONCE(MatterBooleanStateConfigurationPluginServerInitCallback);
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);
#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);
} else {
ESP_LOGE(TAG, "Config is NULL. Cannot add some attributes.");
}
}


/* Features */
if (features & feature::visual::get_id()) {
feature::visual::add(cluster, &(config->visual));
}
if (features & feature::audible::get_id()) {
feature::audible::add(cluster, &(config->audible));
}
if (features & feature::alarm_suppress::get_id()) {
feature::alarm_suppress::add(cluster, &(config->alarm_suppress));
}
if (features & feature::sensitivity_level::get_id()) {
feature::sensitivity_level::add(cluster, &(config->sensitivity_level));
}
return cluster;
}
} /* boolean_state_configuration */

namespace localization_configuration {
const function_generic_t function_list[] = {
(function_generic_t)emberAfLocalizationConfigurationClusterServerInitCallback,
Expand Down
13 changes: 13 additions & 0 deletions components/esp_matter/esp_matter_cluster.h
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,19 @@ typedef struct config {
cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags);
} /* boolean_state */

namespace boolean_state_configuration {
typedef struct config {
uint16_t cluster_revision;
feature::visual::config_t visual;
feature::audible::config_t audible;
feature::alarm_suppress::config_t alarm_suppress;
feature::sensitivity_level::config_t sensitivity_level;
config() : cluster_revision(1) {}
} config_t;

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

namespace localization_configuration {
typedef struct config {
uint16_t cluster_revision;
Expand Down
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 @@ -1248,6 +1248,26 @@ static esp_err_t esp_matter_command_callback_send_key(const ConcreteCommandPath
return ESP_OK;
}

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

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

namespace esp_matter {
namespace cluster {

Expand Down Expand Up @@ -2381,6 +2401,21 @@ command_t *create_send_key_response(cluster_t *cluster)
} /* command */
} /* keypad_input */

namespace boolean_state_configuration {
namespace command {
command_t *create_suppress_alarm(cluster_t *cluster)
{
return esp_matter::command::create(cluster, BooleanStateConfiguration::Commands::SuppressAlarm::Id, COMMAND_FLAG_ACCEPTED, esp_matter_command_callback_suppress_alarm);
}

command_t *create_enable_disable_alarm(cluster_t *cluster)
{
return esp_matter::command::create(cluster, BooleanStateConfiguration::Commands::EnableDisableAlarm::Id, COMMAND_FLAG_ACCEPTED, esp_matter_command_callback_enable_disable_alarm);
}

} /* command */
} /* boolean_state_configuration */

} /* 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 @@ -364,5 +364,12 @@ command_t *create_send_key_response(cluster_t *cluster);
} /* command */
} /* keypad_input */

namespace boolean_state_configuration {
namespace command {
command_t *create_suppress_alarm(cluster_t *cluster);
command_t *create_enable_disable_alarm(cluster_t *cluster);
} /* command */
} /* boolean_state_configuration */

} /* cluster */
} /* esp_matter */
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 @@ -1516,6 +1516,45 @@ esp_err_t add(endpoint_t *endpoint, config_t *config)
}
} /* water_leak_detector */

namespace rain_sensor {
uint32_t get_device_type_id()
{
return ESP_MATTER_RAIN_SENSOR_DEVICE_TYPE_ID;
}

uint8_t get_device_type_version()
{
return ESP_MATTER_RAIN_SENSOR_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;
}

descriptor::create(endpoint, &(config->descriptor), CLUSTER_FLAG_SERVER);
identify::create(endpoint, &(config->identify), CLUSTER_FLAG_SERVER);
cluster_t *cluster = boolean_state::create(endpoint, &(config->boolean_state), CLUSTER_FLAG_SERVER);

boolean_state::event::create_state_change(cluster);
return ESP_OK;
}
} /* rain_sensor */

} /* 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 @@ -98,6 +98,8 @@
#define ESP_MATTER_ROBOTIC_VACCUM_CLEANER_DEVICE_TYPE_VERSION 1
#define ESP_MATTER_WATER_LEAK_DETECTOR_DEVICE_TYPE_ID 0x0043
#define ESP_MATTER_WATER_LEAK_DETECTOR_DEVICE_TYPE_VERSION 1
#define ESP_MATTER_RAIN_SENSOR_DEVICE_TYPE_ID 0x0044
#define ESP_MATTER_RAIN_SENSOR_DEVICE_TYPE_VERSION 1

namespace esp_matter {

Expand Down Expand Up @@ -621,6 +623,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);
} /* water_leak_detector */

namespace rain_sensor {
typedef struct config {
cluster::descriptor::config_t descriptor;
cluster::identify::config_t identify;
cluster::boolean_state::config_t boolean_state;
} 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);
} /* rain_sensor */

} /* endpoint */

namespace node {
Expand Down
16 changes: 16 additions & 0 deletions components/esp_matter/esp_matter_event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,22 @@ event_t *create_state_change(cluster_t *cluster)
} // namespace event
} // namespace boolean_state

namespace boolean_state_configuration {
namespace event {

event_t *create_alarms_state_changed(cluster_t *cluster)
{
return esp_matter::event::create(cluster, BooleanStateConfiguration::Events::AlarmsStateChanged::Id);
}

event_t *create_sensor_fault(cluster_t *cluster)
{
return esp_matter::event::create(cluster, BooleanStateConfiguration::Events::SensorFault::Id);
}

} // namespace event
} // namespace boolean_state_configuration

namespace operational_state {
namespace event {

Expand Down
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 @@ -158,6 +158,13 @@ event_t *create_state_change(cluster_t *cluster);
} // namespace event
} // namespace boolean_state

namespace boolean_state_configuration {
namespace event {
event_t *create_alarms_state_changed(cluster_t *cluster);
event_t *create_sensor_fault(cluster_t *cluster);
} // namespace event
} // namespace boolean_state_configuration

namespace operational_state {
namespace event {
event_t *create_operational_error(cluster_t *cluster);
Expand Down
Loading

0 comments on commit ca174c7

Please sign in to comment.