diff --git a/components/esp_matter/esp_matter_attribute.cpp b/components/esp_matter/esp_matter_attribute.cpp index c8f842a66..646529377 100644 --- a/components/esp_matter/esp_matter_attribute.cpp +++ b/components/esp_matter/esp_matter_attribute.cpp @@ -1285,13 +1285,13 @@ attribute_t *create_pi_heating_demand(cluster_t *cluster, uint8_t value) attribute_t *create_hvac_system_type_config(cluster_t *cluster, uint8_t value) { - return esp_matter::attribute::create(cluster, Thermostat::Attributes::HVACSystemTypeConfiguration::Id, + return esp_matter::attribute::create(cluster, Thermostat::Attributes::HVACSystemTypeConfiguration::Id, ATTRIBUTE_FLAG_NONVOLATILE | ATTRIBUTE_FLAG_WRITABLE, esp_matter_bitmap8(value)); } attribute_t *create_local_temperature_calibration(cluster_t *cluster, int8_t value) { - return esp_matter::attribute::create(cluster, Thermostat::Attributes::LocalTemperatureCalibration::Id, + return esp_matter::attribute::create(cluster, Thermostat::Attributes::LocalTemperatureCalibration::Id, ATTRIBUTE_FLAG_NONVOLATILE | ATTRIBUTE_FLAG_WRITABLE, esp_matter_int8(value)); } @@ -1414,7 +1414,7 @@ attribute_t *create_temperature_setpoint_hold(cluster_t *cluster, uint8_t value) attribute_t *create_temperature_setpoint_hold_duration(cluster_t *cluster, nullable value) { return esp_matter::attribute::create(cluster, Thermostat::Attributes::TemperatureSetpointHoldDuration::Id, - ATTRIBUTE_FLAG_NULLABLE | ATTRIBUTE_FLAG_NONVOLATILE | ATTRIBUTE_FLAG_WRITABLE, + ATTRIBUTE_FLAG_NULLABLE | ATTRIBUTE_FLAG_NONVOLATILE | ATTRIBUTE_FLAG_WRITABLE, esp_matter_nullable_uint16(value)); } @@ -1783,6 +1783,36 @@ attribute_t *create_temperature_max_measured_value(cluster_t *cluster, nullable< } /* attribute */ } /* temperature_measurement */ +namespace relative_humidity_measurement { +namespace attribute { + +attribute_t *create_relative_humidity_measured_value(cluster_t *cluster, nullable value) +{ + return esp_matter::attribute::create(cluster, RelativeHumidityMeasurement::Attributes::MeasuredValue::Id, + ATTRIBUTE_FLAG_NULLABLE, esp_matter_nullable_uint16(value)); +} + +attribute_t *create_relative_humidity_min_measured_value(cluster_t *cluster, nullable value) +{ + return esp_matter::attribute::create(cluster, RelativeHumidityMeasurement::Attributes::MinMeasuredValue::Id, + ATTRIBUTE_FLAG_NULLABLE, esp_matter_nullable_uint16(value)); +} + +attribute_t *create_relative_humidity_max_measured_value(cluster_t *cluster, nullable value) +{ + return esp_matter::attribute::create(cluster, RelativeHumidityMeasurement::Attributes::MaxMeasuredValue::Id, + ATTRIBUTE_FLAG_NULLABLE, esp_matter_nullable_uint16(value)); +} + +attribute_t *create_relative_humidity_tolerance(cluster_t *cluster, nullable value) +{ + return esp_matter::attribute::create(cluster, RelativeHumidityMeasurement::Attributes::Tolerance::Id, + ATTRIBUTE_FLAG_NULLABLE, esp_matter_nullable_uint16(value)); +} + +} /* attribute */ +} /* relative_humidity_measurement */ + namespace occupancy_sensing { namespace attribute { diff --git a/components/esp_matter/esp_matter_attribute.h b/components/esp_matter/esp_matter_attribute.h index c01f4ab62..567e033d9 100644 --- a/components/esp_matter/esp_matter_attribute.h +++ b/components/esp_matter/esp_matter_attribute.h @@ -424,6 +424,15 @@ attribute_t *create_temperature_max_measured_value(cluster_t *cluster, nullable< } /* attribute */ } /* temperature_measurement */ +namespace relative_humidity_measurement { +namespace attribute { +attribute_t *create_relative_humidity_measured_value(cluster_t *cluster, nullable value); +attribute_t *create_relative_humidity_min_measured_value(cluster_t *cluster, nullable value); +attribute_t *create_relative_humidity_max_measured_value(cluster_t *cluster, nullable value); +attribute_t *create_relative_humidity_tolerance(cluster_t *cluster, nullable value); +} /* attribute */ +} /* relative_humidity_measurement */ + namespace occupancy_sensing { namespace attribute { attribute_t *create_occupancy(cluster_t *cluster, uint8_t value); diff --git a/components/esp_matter/esp_matter_cluster.cpp b/components/esp_matter/esp_matter_cluster.cpp index 77b8300f0..e7106ce6c 100644 --- a/components/esp_matter/esp_matter_cluster.cpp +++ b/components/esp_matter/esp_matter_cluster.cpp @@ -1483,6 +1483,46 @@ cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags) } } /* temperature_measurement */ +namespace relative_humidity_measurement { +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) +{ + cluster_t *cluster = cluster::create(endpoint, RelativeHumidityMeasurement::Id, flags); + if (!cluster) { + ESP_LOGE(TAG, "Could not create cluster"); + return NULL; + } + + if (flags & CLUSTER_FLAG_SERVER) { + set_plugin_server_init_callback(cluster, MatterRelativeHumidityMeasurementPluginServerInitCallback); + add_function_list(cluster, function_list, function_flags); + } + if (flags & CLUSTER_FLAG_CLIENT) { + set_plugin_client_init_callback(cluster, MatterRelativeHumidityMeasurementPluginClientInitCallback); + create_default_binding_cluster(endpoint); + } + + if (flags & CLUSTER_FLAG_SERVER) { + /* Attributes managed internally */ + global::attribute::create_feature_map(cluster, 0); + + /* Attributes not managed internally */ + if (config) { + global::attribute::create_cluster_revision(cluster, config->cluster_revision); + attribute::create_relative_humidity_measured_value(cluster, config->measured_value); + attribute::create_relative_humidity_min_measured_value(cluster, config->min_measured_value); + attribute::create_relative_humidity_max_measured_value(cluster, config->max_measured_value); + } else { + ESP_LOGE(TAG, "Config is NULL. Cannot add some attributes."); + } + } + + return cluster; +} +} /* relative_humidity_measurement */ + namespace occupancy_sensing { const function_generic_t *function_list = NULL; const int function_flags = CLUSTER_FLAG_NONE; @@ -1789,11 +1829,11 @@ cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags) set_plugin_client_init_callback(cluster, MatterPumpConfigurationAndControlPluginClientInitCallback); create_default_binding_cluster(endpoint); } - + if (flags & CLUSTER_FLAG_SERVER) { /* Attributes managed internally */ global::attribute::create_feature_map(cluster, 0); - + /** Attributes not managed internally **/ if (config) { global::attribute::create_cluster_revision(cluster, config->cluster_revision); @@ -1808,7 +1848,7 @@ cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags) ESP_LOGE(TAG, "Config is NULL. Cannot add some attributes."); } } - + return cluster; } } /* pump_configuration_and_control */ diff --git a/components/esp_matter/esp_matter_cluster.h b/components/esp_matter/esp_matter_cluster.h index e4f4fb808..8fbb364ca 100644 --- a/components/esp_matter/esp_matter_cluster.h +++ b/components/esp_matter/esp_matter_cluster.h @@ -354,6 +354,18 @@ typedef struct config { cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags); } /* temperature_measurement */ +namespace relative_humidity_measurement { +typedef struct config { + uint16_t cluster_revision; + nullable measured_value; + nullable min_measured_value; + nullable max_measured_value; + config() : cluster_revision(3), measured_value(), min_measured_value(0), max_measured_value(10000) {} +} config_t; + +cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags); +} /* relative_humidity_measurement */ + namespace occupancy_sensing { typedef struct config { uint16_t cluster_revision; diff --git a/components/esp_matter/esp_matter_endpoint.cpp b/components/esp_matter/esp_matter_endpoint.cpp index 2a8d21a6a..6aceccefc 100644 --- a/components/esp_matter/esp_matter_endpoint.cpp +++ b/components/esp_matter/esp_matter_endpoint.cpp @@ -676,6 +676,39 @@ endpoint_t *add(endpoint_t *endpoint, config_t *config) } } /* temperature_sensor */ +namespace humidity_sensor { +uint32_t get_device_type_id() +{ + return ESP_MATTER_HUMIDITY_SENSOR_DEVICE_TYPE_ID; +} + +uint8_t get_device_type_version() +{ + return ESP_MATTER_HUMIDITY_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); + return add(endpoint, config); +} + +endpoint_t *add(endpoint_t *endpoint, config_t *config) +{ + if (!endpoint) { + ESP_LOGE(TAG, "Endpoint cannot be NULL"); + return NULL; + } + add_device_type(endpoint, get_device_type_id(), get_device_type_version()); + + descriptor::create(endpoint, CLUSTER_FLAG_SERVER); + identify::create(endpoint, &(config->identify), CLUSTER_FLAG_SERVER); + relative_humidity_measurement::create(endpoint, &(config->relative_humidity_measurement), CLUSTER_FLAG_SERVER); + + return endpoint; +} +} /* humidity_sensor */ + namespace occupancy_sensor { uint32_t get_device_type_id() { @@ -866,12 +899,12 @@ endpoint_t *add(endpoint_t *endpoint, config_t *config) return NULL; } add_device_type(endpoint, get_device_type_id(), get_device_type_version()); - + identify::create(endpoint, &(config->identify), CLUSTER_FLAG_SERVER); descriptor::create(endpoint, CLUSTER_FLAG_SERVER); on_off::create(endpoint, &(config->on_off), CLUSTER_FLAG_SERVER, ESP_MATTER_NONE_FEATURE_ID); pump_configuration_and_control::create(endpoint, &(config->pump_configuration_and_control), CLUSTER_FLAG_SERVER); - + return endpoint; } } /** pump **/ diff --git a/components/esp_matter/esp_matter_endpoint.h b/components/esp_matter/esp_matter_endpoint.h index 4294fa873..4b7ce0422 100644 --- a/components/esp_matter/esp_matter_endpoint.h +++ b/components/esp_matter/esp_matter_endpoint.h @@ -61,6 +61,8 @@ #define ESP_MATTER_PRESSURE_SENSOR_DEVICE_TYPE_VERSION 2 #define ESP_MATTER_FLOW_SENSOR_DEVICE_TYPE_ID 0x0306 #define ESP_MATTER_FLOW_SENSOR_DEVICE_TYPE_VERSION 2 +#define ESP_MATTER_HUMIDITY_SENSOR_DEVICE_TYPE_ID 0x0307 +#define ESP_MATTER_HUMIDITY_SENSOR_DEVICE_TYPE_VERSION 2 #define ESP_MATTER_FAN_DEVICE_TYPE_ID 0x002B #define ESP_MATTER_FAN_DEVICE_TYPE_VERSION 1 @@ -325,6 +327,18 @@ endpoint_t *create(node_t *node, config_t *config, uint8_t flags, void *priv_dat endpoint_t *add(endpoint_t *endpoint, config_t *config); } /* temperature_sensor */ +namespace humidity_sensor { +typedef struct config { + cluster::identify::config_t identify; + cluster::relative_humidity_measurement::config_t relative_humidity_measurement; +} 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); +endpoint_t *add(endpoint_t *endpoint, config_t *config); +} /* humidity_sensor */ + namespace occupancy_sensor { typedef struct config { cluster::identify::config_t identify;