From 8692a149b849c0aa1ddb26839104f07600cc1bdb Mon Sep 17 00:00:00 2001 From: Rohit Jadhav Date: Thu, 4 Apr 2024 12:42:48 +0530 Subject: [PATCH] Add laundry dryer device type --- SUPPORTED_DEVICE_TYPES.md | 1 + .../esp_matter/esp_matter_attribute.cpp | 34 +++++++++++++++ components/esp_matter/esp_matter_attribute.h | 14 +++++++ components/esp_matter/esp_matter_cluster.cpp | 42 +++++++++++++++++++ components/esp_matter/esp_matter_cluster.h | 10 +++++ components/esp_matter/esp_matter_endpoint.cpp | 37 ++++++++++++++++ components/esp_matter/esp_matter_endpoint.h | 13 ++++++ .../all_device_types_app/main/device_types.h | 4 +- .../main/esp_matter_console_helpers.cpp | 5 +++ 9 files changed, 159 insertions(+), 1 deletion(-) diff --git a/SUPPORTED_DEVICE_TYPES.md b/SUPPORTED_DEVICE_TYPES.md index ec3b28f4b..6fc51eeec 100644 --- a/SUPPORTED_DEVICE_TYPES.md +++ b/SUPPORTED_DEVICE_TYPES.md @@ -72,3 +72,4 @@ i. Appliance 9. Energy Evse 10. Microwave Oven 11. Extractor Hood +12. Laundry Dryer diff --git a/components/esp_matter/esp_matter_attribute.cpp b/components/esp_matter/esp_matter_attribute.cpp index 26411fa92..42236110e 100644 --- a/components/esp_matter/esp_matter_attribute.cpp +++ b/components/esp_matter/esp_matter_attribute.cpp @@ -2898,6 +2898,40 @@ attribute_t *create_supported_rinses(cluster_t *cluster, uint8_t *value, uint16_ } /* attribute */ } /* laundry_washer_controls */ +namespace laundry_dryer_controls { +namespace attribute { +attribute_t *create_supported_dryness_levels(cluster_t *cluster, uint8_t *value, uint16_t length, uint16_t count) +{ + return esp_matter::attribute::create(cluster, LaundryDryerControls::Attributes::SupportedDrynessLevels::Id, + ATTRIBUTE_FLAG_NONE, esp_matter_array(value, length, count)); +} + +attribute_t *create_selected_dryness_level(cluster_t *cluster, nullable value) +{ + return esp_matter::attribute::create(cluster, LaundryDryerControls::Attributes::SelectedDrynessLevel::Id, + ATTRIBUTE_FLAG_NULLABLE | ATTRIBUTE_FLAG_WRITABLE, esp_matter_nullable_uint8(value)); + +} + +} /* attribute */ +} /* laundry_dryer_controls */ + +namespace dish_washer_mode { +namespace attribute { + +attribute_t *create_supported_modes(cluster_t *cluster, const uint8_t * value, uint16_t length, uint16_t count) +{ + return esp_matter::attribute::create(cluster, LaundryWasherMode::Attributes::SupportedModes::Id, ATTRIBUTE_FLAG_NONE, esp_matter_array((uint8_t*)value, length, count)); +} + +attribute_t *create_current_mode(cluster_t *cluster, uint8_t value) +{ + return esp_matter::attribute::create(cluster, LaundryWasherMode::Attributes::CurrentMode::Id, ATTRIBUTE_FLAG_NONVOLATILE, esp_matter_uint8(value)); +} + +} /* attribute */ +} /* dish_washer_mode */ + namespace smoke_co_alarm { namespace attribute { attribute_t *create_expressed_state(cluster_t *cluster, uint8_t value) diff --git a/components/esp_matter/esp_matter_attribute.h b/components/esp_matter/esp_matter_attribute.h index 00818ae0f..6f280aa29 100644 --- a/components/esp_matter/esp_matter_attribute.h +++ b/components/esp_matter/esp_matter_attribute.h @@ -703,6 +703,20 @@ attribute_t *create_supported_rinses(cluster_t *cluster, uint8_t *value, uint16_ } /* attribute */ } /* laundry_washer_controls */ +namespace laundry_dryer_controls { +namespace attribute { +attribute_t *create_supported_dryness_levels(cluster_t *cluster, uint8_t *value, uint16_t length, uint16_t count); +attribute_t *create_selected_dryness_level(cluster_t *cluster, nullable value); +} /* attribute */ +} /* laundry_dryer_controls */ + +namespace dish_washer_mode { +namespace attribute { +attribute_t *create_supported_modes(cluster_t *cluster, const uint8_t * value, uint16_t length, uint16_t count); +attribute_t *create_current_mode(cluster_t *cluster, uint8_t value); +} /* attribute */ +} /* dish_washer_mode */ + namespace smoke_co_alarm { namespace attribute { attribute_t *create_expressed_state(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 b3e3ddf0d..b3537d911 100644 --- a/components/esp_matter/esp_matter_cluster.cpp +++ b/components/esp_matter/esp_matter_cluster.cpp @@ -2333,6 +2333,48 @@ cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags) } } /* laundry_washer_controls */ +namespace laundry_dryer_controls { + +const function_generic_t function_list[] = { + (function_generic_t)MatterLaundryDryerControlsClusterServerPreAttributeChangedCallback, +}; +const int function_flags = CLUSTER_FLAG_PRE_ATTRIBUTE_CHANGED_FUNCTION; + +cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags) +{ + cluster_t *cluster = cluster::create(endpoint, LaundryDryerControls::Id, flags); + if (!cluster) { + ESP_LOGE(TAG, "Could not create cluster"); + return NULL; + } + + if (flags & CLUSTER_FLAG_SERVER) { + 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 + attribute::create_supported_dryness_levels(cluster, NULL, 0, 0); + /* Attributes not managed internally */ + if (config) { + global::attribute::create_cluster_revision(cluster, config->cluster_revision); + attribute::create_selected_dryness_level(cluster, config->selected_dryness_level); + } else { + ESP_LOGE(TAG, "Config is NULL. Cannot add some attributes."); + } + } + + return cluster; +} +} /* laundry_dryer_controls */ + namespace dish_washer_mode { const function_generic_t *function_list = NULL; const int function_flags = CLUSTER_FLAG_NONE; diff --git a/components/esp_matter/esp_matter_cluster.h b/components/esp_matter/esp_matter_cluster.h index 23234856e..821146975 100644 --- a/components/esp_matter/esp_matter_cluster.h +++ b/components/esp_matter/esp_matter_cluster.h @@ -565,6 +565,16 @@ typedef struct config { cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags); } /* laundry_washer_controls */ +namespace laundry_dryer_controls { +typedef struct config { + uint16_t cluster_revision; + nullable selected_dryness_level; + config() : cluster_revision(1), selected_dryness_level(0) {} +} config_t; + +cluster_t *create(endpoint_t *endpoint, config_t *config, uint8_t flags); +} /* laundry_dryer_controls */ + namespace dish_washer_mode { 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 1d9e50f80..647b93f6d 100644 --- a/components/esp_matter/esp_matter_endpoint.cpp +++ b/components/esp_matter/esp_matter_endpoint.cpp @@ -816,6 +816,43 @@ esp_err_t add(endpoint_t *endpoint, config_t *config) } } /* laundry_washer */ +namespace laundry_dryer { +uint32_t get_device_type_id() +{ + return ESP_MATTER_LAUNDRY_DRYER_DEVICE_TYPE_ID; +} + +uint8_t get_device_type_version() +{ + return ESP_MATTER_LAUNDRY_DRYER_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); + operational_state::create(endpoint, &(config->operational_state), CLUSTER_FLAG_SERVER); + + return ESP_OK; +} +} /* laundry_dryer */ + namespace smoke_co_alarm { 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 215192f07..cd511f589 100644 --- a/components/esp_matter/esp_matter_endpoint.h +++ b/components/esp_matter/esp_matter_endpoint.h @@ -79,6 +79,8 @@ #define ESP_MATTER_MICROWAVE_OVEN_DEVICE_TYPE_VERSION 1 #define ESP_MATTER_SMOKE_CO_ALARM_DEVICE_TYPE_ID 0x0076 #define ESP_MATTER_SMOKE_CO_ALARM_DEVICE_TYPE_VERSION 1 +#define ESP_MATTER_LAUNDRY_DRYER_DEVICE_TYPE_ID 0x007C +#define ESP_MATTER_LAUNDRY_DRYER_DEVICE_TYPE_VERSION 1 #define ESP_MATTER_FAN_DEVICE_TYPE_ID 0x002B #define ESP_MATTER_FAN_DEVICE_TYPE_VERSION 1 @@ -388,6 +390,17 @@ 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); } /* laundry_washer */ +namespace laundry_dryer { +typedef struct config { + cluster::descriptor::config_t descriptor; + cluster::operational_state::config_t operational_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); +} /* laundry_dryer */ + namespace smoke_co_alarm { 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 b5f05d03b..cfd6a4d0b 100644 --- a/examples/all_device_types_app/main/device_types.h +++ b/examples/all_device_types_app/main/device_types.h @@ -47,6 +47,7 @@ enum device_type_enum { ESP_MATTER_ENERGY_EVSE, ESP_MATTER_MICROWAVE_OVEN, ESP_MATTER_EXTRACTOR_HOOD, + ESP_MATTER_LAUNDRY_DRYER, ESP_MATTER_DEVICE_TYPE_MAX }; @@ -99,6 +100,7 @@ const device_type_name device_type_list[ESP_MATTER_DEVICE_TYPE_MAX] = { {"cooktop", ESP_MATTER_COOKTOP}, {"energy_evse", ESP_MATTER_ENERGY_EVSE}, {"microwave_oven", ESP_MATTER_MICROWAVE_OVEN}, - {"extractor_hood", ESP_MATTER_EXTRACTOR_HOOD} + {"extractor_hood", ESP_MATTER_EXTRACTOR_HOOD}, + {"laundry_dryer", ESP_MATTER_LAUNDRY_DRYER} }; } /* 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 9424f93da..494ab70a2 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 @@ -429,6 +429,11 @@ int create(uint8_t device_type_index) endpoint = esp_matter::endpoint::extractor_hood::create(node, &extractor_hood_config, ENDPOINT_FLAG_NONE, NULL); break; } + case ESP_MATTER_LAUNDRY_DRYER: { + esp_matter::endpoint::laundry_dryer::config_t laundry_dryer_config; + endpoint = esp_matter::endpoint::laundry_dryer::create(node, &laundry_dryer_config, ENDPOINT_FLAG_NONE, NULL); + break; + } default: { ESP_LOGE(TAG, "Please input a valid device type"); break;