From 09d1ef43818bbdf73480793ec996bfcc8c8b654d Mon Sep 17 00:00:00 2001 From: Rohit Jadhav Date: Thu, 4 Apr 2024 15:04:28 +0530 Subject: [PATCH] Add water freeze device type --- SUPPORTED_DEVICE_TYPES.md | 1 + components/esp_matter/esp_matter_endpoint.cpp | 38 +++++++++++++++++++ components/esp_matter/esp_matter_endpoint.h | 15 ++++++++ .../all_device_types_app/main/device_types.h | 4 +- .../main/esp_matter_console_helpers.cpp | 5 +++ 5 files changed, 62 insertions(+), 1 deletion(-) diff --git a/SUPPORTED_DEVICE_TYPES.md b/SUPPORTED_DEVICE_TYPES.md index ab883a8e6..3af90f592 100644 --- a/SUPPORTED_DEVICE_TYPES.md +++ b/SUPPORTED_DEVICE_TYPES.md @@ -55,6 +55,7 @@ g. Sensors 8. Smoke CO Alarm 9. Water Leak Detector 10. Rain Sensor +11. Water Freeze Detector h. Robotic 1. Robotic Vacuum Cleaner diff --git a/components/esp_matter/esp_matter_endpoint.cpp b/components/esp_matter/esp_matter_endpoint.cpp index b2bb68ca5..cf3511354 100644 --- a/components/esp_matter/esp_matter_endpoint.cpp +++ b/components/esp_matter/esp_matter_endpoint.cpp @@ -1561,6 +1561,44 @@ esp_err_t add(endpoint_t *endpoint, config_t *config) } } /* water_leak_detector */ +namespace water_freeze_detector { +uint32_t get_device_type_id() +{ + return ESP_MATTER_WATER_FREEZE_DETECTOR_DEVICE_TYPE_ID; +} + +uint8_t get_device_type_version() +{ + return ESP_MATTER_WATER_FREEZE_DETECTOR_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); + boolean_state::create(endpoint, &(config->boolean_state), CLUSTER_FLAG_SERVER); + + return ESP_OK; +} +} /* water_freeze_detector */ + namespace rain_sensor { uint32_t get_device_type_id() { diff --git a/components/esp_matter/esp_matter_endpoint.h b/components/esp_matter/esp_matter_endpoint.h index 582ea2bbc..27c7ce366 100644 --- a/components/esp_matter/esp_matter_endpoint.h +++ b/components/esp_matter/esp_matter_endpoint.h @@ -104,6 +104,8 @@ #define ESP_MATTER_ELECTRICAL_SENSOR_DEVICE_TYPE_VERSION 1 #define ESP_MATTER_OVEN_DEVICE_TYPE_ID 0x007B #define ESP_MATTER_OVEN_DEVICE_TYPE_VERSION 1 +#define ESP_MATTER_WATER_FREEZE_DETECTOR_DEVICE_TYPE_ID 0x0041 +#define ESP_MATTER_WATER_FREEZE_DETECTOR_DEVICE_TYPE_VERSION 1 namespace esp_matter { @@ -638,6 +640,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 water_freeze_detector { +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); +} /* water_freeze_detector */ + namespace rain_sensor { typedef struct config { cluster::descriptor::config_t descriptor; diff --git a/examples/all_device_types_app/main/device_types.h b/examples/all_device_types_app/main/device_types.h index 6086442df..859c03230 100644 --- a/examples/all_device_types_app/main/device_types.h +++ b/examples/all_device_types_app/main/device_types.h @@ -38,6 +38,7 @@ enum device_type_enum { ESP_MATTER_DISH_WASHER, ESP_MATTER_SMOKE_CO_ALARM, ESP_MATTER_WATER_LEAK_DETECTOR, + ESP_MATTER_WATER_FREEZE_DETECTOR, ESP_MATTER_POWER_SOURCE, ESP_MATTER_RAIN_SENSOR, ESP_MATTER_ELECTRICAL_SENSOR, @@ -86,9 +87,10 @@ const device_type_name device_type_list[ESP_MATTER_DEVICE_TYPE_MAX] = { {"dish_washer", ESP_MATTER_DISH_WASHER}, {"smoke_co_alarm", ESP_MATTER_SMOKE_CO_ALARM}, {"water_leak_detector", ESP_MATTER_WATER_LEAK_DETECTOR}, + {"water_freeze_detector", ESP_MATTER_WATER_FREEZE_DETECTOR}, {"power_source", ESP_MATTER_POWER_SOURCE}, {"rain_sensor", ESP_MATTER_RAIN_SENSOR}, {"electrical_sensor", ESP_MATTER_ELECTRICAL_SENSOR}, {"oven", ESP_MATTER_OVEN} - }; +}; } /* namespace esp_matter */ diff --git a/examples/all_device_types_app/main/esp_matter_console_helpers.cpp b/examples/all_device_types_app/main/esp_matter_console_helpers.cpp index ea63015fc..7bccb738e 100644 --- a/examples/all_device_types_app/main/esp_matter_console_helpers.cpp +++ b/examples/all_device_types_app/main/esp_matter_console_helpers.cpp @@ -375,6 +375,11 @@ int create(uint8_t device_type_index) endpoint = esp_matter::endpoint::water_leak_detector::create(node, &water_leak_detector_config, ENDPOINT_FLAG_NONE, NULL); break; } + case ESP_MATTER_WATER_FREEZE_DETECTOR: { + esp_matter::endpoint::water_freeze_detector::config_t water_freeze_detector_config; + endpoint = esp_matter::endpoint::water_freeze_detector::create(node, &water_freeze_detector_config, ENDPOINT_FLAG_NONE, NULL); + break; + } case ESP_MATTER_POWER_SOURCE: { esp_matter::endpoint::power_source_device::config_t power_source_device_config; endpoint = esp_matter::endpoint::power_source_device::create(node, &power_source_device_config, ENDPOINT_FLAG_NONE, NULL);