From ddbc6e27b09237057d45deeb7e3e3e7bbcf9b280 Mon Sep 17 00:00:00 2001 From: Rohit Jadhav Date: Tue, 19 Nov 2024 13:47:00 +0530 Subject: [PATCH] components/esp-matter: Add Water Heater device type --- SUPPORTED_DEVICE_TYPES.md | 1 + components/esp_matter/esp_matter_endpoint.cpp | 33 +++++++++++++++++++ components/esp_matter/esp_matter_endpoint.h | 16 +++++++++ .../all_device_types_app/main/device_types.h | 2 ++ .../main/esp_matter_console_helpers.cpp | 5 +++ 5 files changed, 57 insertions(+) diff --git a/SUPPORTED_DEVICE_TYPES.md b/SUPPORTED_DEVICE_TYPES.md index 51ada4f0c..7b610817d 100644 --- a/SUPPORTED_DEVICE_TYPES.md +++ b/SUPPORTED_DEVICE_TYPES.md @@ -82,6 +82,7 @@ i. Appliances j. Energy 1. EVSE (Electric Vehicle Supply Equipment) +2. Water Heater k. Network Infrastructure 1. Thread Border Router diff --git a/components/esp_matter/esp_matter_endpoint.cpp b/components/esp_matter/esp_matter_endpoint.cpp index f1c6a6c9b..c7c0cb953 100644 --- a/components/esp_matter/esp_matter_endpoint.cpp +++ b/components/esp_matter/esp_matter_endpoint.cpp @@ -2017,6 +2017,39 @@ esp_err_t add(endpoint_t *endpoint, config_t *config) } } /* mounted_dimmable_load_control */ +namespace water_heater { +uint32_t get_device_type_id() +{ + return ESP_MATTER_WATER_HEATER_DEVICE_TYPE_ID; +} + +uint8_t get_device_type_version() +{ + return ESP_MATTER_WATER_HEATER_DEVICE_TYPE_VERSION; +} + +endpoint_t *create(node_t *node, config_t *config, uint8_t flags, void *priv_data) +{ + return common::create(node, config, flags, priv_data, add); +} + +esp_err_t add(endpoint_t *endpoint, config_t *config) +{ + VerifyOrReturnError(endpoint != nullptr, ESP_ERR_INVALID_ARG, ESP_LOGE(TAG, "Endpoint cannot be NULL")); + 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; + } + + cluster::thermostat::create(endpoint, &(config->thermostat), CLUSTER_FLAG_SERVER, cluster::thermostat::feature::heating::get_id()); + water_heater_management::create(endpoint, &(config->water_heater_management), CLUSTER_FLAG_SERVER, ESP_MATTER_NONE_FEATURE_ID); + water_heater_mode::create(endpoint, &(config->water_heater_mode), CLUSTER_FLAG_SERVER); + + return ESP_OK; +} +} /* water_heater */ + } /* endpoint */ namespace node { diff --git a/components/esp_matter/esp_matter_endpoint.h b/components/esp_matter/esp_matter_endpoint.h index 58be8a9e8..cec0912d3 100644 --- a/components/esp_matter/esp_matter_endpoint.h +++ b/components/esp_matter/esp_matter_endpoint.h @@ -136,6 +136,8 @@ #define ESP_MATTER_DEVICE_ENERGY_MANAGEMENT_DEVICE_TYPE_VERSION 2 #define ESP_MATTER_SECONDARY_NETWORK_INTERFACE_DEVICE_TYPE_ID 0x0019 #define ESP_MATTER_SECONDARY_NETWORK_INTERFACE_DEVICE_TYPE_VERSION 1 +#define ESP_MATTER_WATER_HEATER_DEVICE_TYPE_ID 0x050F +#define ESP_MATTER_WATER_HEATER_DEVICE_TYPE_VERSION 1 #define ESP_MATTER_THREAD_BORDER_ROUTER_DEVICE_TYPE_ID 0x0091 #define ESP_MATTER_THREAD_BORDER_ROUTER_DEVICE_TYPE_VERSION 1 @@ -828,6 +830,20 @@ 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); } /** mounted_dimmable_load_control **/ +namespace water_heater { +typedef struct config { + cluster::descriptor::config_t descriptor; + cluster::thermostat::config_t thermostat; + cluster::water_heater_management::config_t water_heater_management; + cluster::water_heater_mode::config_t water_heater_mode; +} 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_heater */ + } /* endpoint */ namespace node { diff --git a/examples/all_device_types_app/main/device_types.h b/examples/all_device_types_app/main/device_types.h index 48efb20be..4802381b5 100644 --- a/examples/all_device_types_app/main/device_types.h +++ b/examples/all_device_types_app/main/device_types.h @@ -55,6 +55,7 @@ enum device_type_enum { ESP_MATTER_THREAD_BORDER_ROUTER, ESP_MATTER_MOUNTED_ON_OFF_CONTROL, ESP_MATTER_MOUNTED_DIMMABLE_LOAD_CONTROL, + ESP_MATTER_WATER_HEATER, ESP_MATTER_DEVICE_TYPE_MAX }; @@ -116,5 +117,6 @@ const device_type_name device_type_list[ESP_MATTER_DEVICE_TYPE_MAX] = { {"thread_border_router", ESP_MATTER_THREAD_BORDER_ROUTER}, {"mounted_on_off_control", ESP_MATTER_MOUNTED_ON_OFF_CONTROL}, {"mounted_dimmable_load_control", ESP_MATTER_MOUNTED_DIMMABLE_LOAD_CONTROL}, + {"water_heater", ESP_MATTER_WATER_HEATER}, }; } /* 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 b7d13a8a1..c2d2a68fc 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 @@ -529,6 +529,11 @@ int create(uint8_t device_type_index) endpoint = esp_matter::endpoint::mounted_dimmable_load_control::create(node, &mounted_dimmable_load_control_config, ENDPOINT_FLAG_NONE, NULL); break; } + case ESP_MATTER_WATER_HEATER: { + esp_matter::endpoint::water_heater::config_t water_heater_config; + endpoint = esp_matter::endpoint::water_heater::create(node, &water_heater_config, ENDPOINT_FLAG_NONE, NULL); + break; + } default: { ESP_LOGE(TAG, "Please input a valid device type"); break;