diff --git a/SUPPORTED_DEVICE_TYPES.md b/SUPPORTED_DEVICE_TYPES.md index 1eace386b..7564cab58 100644 --- a/SUPPORTED_DEVICE_TYPES.md +++ b/SUPPORTED_DEVICE_TYPES.md @@ -84,6 +84,7 @@ j. Energy 1. EVSE (Electric Vehicle Supply Equipment) 2. Water Heater 3. Solar Power +4. Battery Storage 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 05b7507d4..38a95cc6f 100644 --- a/components/esp_matter/esp_matter_endpoint.cpp +++ b/components/esp_matter/esp_matter_endpoint.cpp @@ -2083,21 +2083,79 @@ esp_err_t add(endpoint_t *endpoint, config_t *config) cluster_t *power_source_cluster = cluster::get(endpoint, PowerSource::Id); power_source::feature::wired::add(power_source_cluster, &config->power_source_device.power_source.wired); - electrical_sensor::add(endpoint, &config->electrical_sensor); electrical_energy_measurement::create(endpoint, &(config->electrical_energy_measurement), CLUSTER_FLAG_SERVER, electrical_energy_measurement::feature::exported_energy::get_id() | electrical_energy_measurement::feature::cumulative_energy::get_id()); - cluster_t *ele_power_measurement_cluster = cluster::get(endpoint, ElectricalPowerMeasurement::Id); + cluster_t *elec_power_measurement_cluster = cluster::get(endpoint, ElectricalPowerMeasurement::Id); nullable voltage = 0, active_current = 0; - electrical_power_measurement::attribute::create_voltage(ele_power_measurement_cluster, voltage); - electrical_power_measurement::attribute::create_active_current(ele_power_measurement_cluster, active_current); + electrical_power_measurement::attribute::create_voltage(elec_power_measurement_cluster, voltage); + electrical_power_measurement::attribute::create_active_current(elec_power_measurement_cluster, active_current); return ESP_OK; } } /* solar_power */ +namespace battery_storage { +uint32_t get_device_type_id() +{ + return ESP_MATTER_BATTERY_STORAGE_DEVICE_TYPE_ID; +} + +uint8_t get_device_type_version() +{ + return ESP_MATTER_BATTERY_STORAGE_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_t *descriptor_cluster = cluster::get(endpoint, Descriptor::Id); + descriptor::feature::taglist::add(descriptor_cluster); + + power_source_device::add(endpoint, &config->power_source_device); + + cluster_t *power_source_cluster = cluster::get(endpoint, PowerSource::Id); + power_source::feature::wired::add(power_source_cluster, &config->power_source_device.power_source.wired); + power_source::feature::battery::add(power_source_cluster, &config->power_source_device.power_source.battery); + + power_source::attribute::create_bat_voltage(power_source_cluster, config->bat_voltage, 0x00, 0xFFFF); + power_source::attribute::create_bat_percent_remaining(power_source_cluster, config->bat_percent_remaining, 0, 200); + power_source::attribute::create_bat_time_remaining(power_source_cluster, config->bat_time_remaining, 0x00, 0xFFFF); + power_source::attribute::create_active_bat_faults(power_source_cluster, NULL, 0, 0); + power_source::attribute::create_bat_capacity(power_source_cluster, config->bat_capacity, 0x00, 0xFFFF); + power_source::attribute::create_bat_time_to_full_charge(power_source_cluster, config->bat_time_to_full_charge, 0x00, 0xFFFF); + power_source::attribute::create_bat_charging_current(power_source_cluster, config->bat_charging_current, 0x00, 0xFFFF); + power_source::attribute::create_active_bat_charge_faults(power_source_cluster, NULL, 0, 0); + + electrical_sensor::add(endpoint, &config->electrical_sensor); + electrical_energy_measurement::create(endpoint, &(config->electrical_energy_measurement), CLUSTER_FLAG_SERVER, electrical_energy_measurement::feature::exported_energy::get_id() | electrical_energy_measurement::feature::cumulative_energy::get_id()); + + cluster_t *elec_power_measurement_cluster = cluster::get(endpoint, ElectricalPowerMeasurement::Id); + + electrical_power_measurement::attribute::create_voltage(elec_power_measurement_cluster, config->voltage); + electrical_power_measurement::attribute::create_active_current(elec_power_measurement_cluster, config->active_current); + + device_energy_management::add(endpoint, &config->device_energy_management); + + cluster_t *device_energy_management_cluster = cluster::get(endpoint, DeviceEnergyManagement::Id); + cluster::device_energy_management::feature::power_adjustment::add(device_energy_management_cluster); + return ESP_OK; +} +} /* battery_storage */ + } /* endpoint */ namespace node { diff --git a/components/esp_matter/esp_matter_endpoint.h b/components/esp_matter/esp_matter_endpoint.h index 8315ef2b8..cec651ff9 100644 --- a/components/esp_matter/esp_matter_endpoint.h +++ b/components/esp_matter/esp_matter_endpoint.h @@ -140,6 +140,8 @@ #define ESP_MATTER_WATER_HEATER_DEVICE_TYPE_VERSION 1 #define ESP_MATTER_SOLAR_POWER_DEVICE_TYPE_ID 0x0017 #define ESP_MATTER_SOLAR_POWER_DEVICE_TYPE_VERSION 1 +#define ESP_MATTER_BATTERY_STORAGE_DEVICE_TYPE_ID 0x0018 +#define ESP_MATTER_BATTERY_STORAGE_DEVICE_TYPE_VERSION 1 #define ESP_MATTER_THREAD_BORDER_ROUTER_DEVICE_TYPE_ID 0x0091 #define ESP_MATTER_THREAD_BORDER_ROUTER_DEVICE_TYPE_VERSION 1 @@ -860,6 +862,33 @@ 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); } /* solar_power */ +namespace battery_storage { +typedef struct config { + cluster::descriptor::config_t descriptor; + power_source_device::config_t power_source_device; + electrical_sensor::config_t electrical_sensor; + device_energy_management::config_t device_energy_management; + cluster::electrical_energy_measurement::config_t electrical_energy_measurement; + + nullable bat_voltage; + nullable bat_percent_remaining; + nullable bat_time_remaining; + uint32_t bat_capacity; + nullable bat_time_to_full_charge; + nullable bat_charging_current; + + nullable voltage; + nullable active_current; + + config(): bat_voltage(), bat_percent_remaining(), bat_capacity(0), bat_time_to_full_charge(), bat_charging_current(), voltage(0), active_current(0) {} +} 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); +} /** battery_storage **/ + } /* 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 4dbe4a49e..097e2e49f 100644 --- a/examples/all_device_types_app/main/device_types.h +++ b/examples/all_device_types_app/main/device_types.h @@ -57,6 +57,7 @@ enum device_type_enum { ESP_MATTER_MOUNTED_DIMMABLE_LOAD_CONTROL, ESP_MATTER_WATER_HEATER, ESP_MATTER_SOLAR_POWER, + ESP_MATTER_BATTERY_STORAGE, ESP_MATTER_DEVICE_TYPE_MAX }; @@ -120,5 +121,6 @@ const device_type_name device_type_list[ESP_MATTER_DEVICE_TYPE_MAX] = { {"mounted_dimmable_load_control", ESP_MATTER_MOUNTED_DIMMABLE_LOAD_CONTROL}, {"water_heater", ESP_MATTER_WATER_HEATER}, {"solar_power", ESP_MATTER_SOLAR_POWER}, + {"battery_storage", ESP_MATTER_BATTERY_STORAGE}, }; } /* 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 2461607f6..901ed7a85 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 @@ -539,6 +539,11 @@ int create(uint8_t device_type_index) endpoint = esp_matter::endpoint::solar_power::create(node, &solar_power_config, ENDPOINT_FLAG_NONE, NULL); break; } + case ESP_MATTER_BATTERY_STORAGE: { + esp_matter::endpoint::battery_storage::config_t battery_storage_config; + endpoint = esp_matter::endpoint::battery_storage::create(node, &battery_storage_config, ENDPOINT_FLAG_NONE, NULL); + break; + } default: { ESP_LOGE(TAG, "Please input a valid device type"); break;