Skip to content

Conversation

bilalahmaddev
Copy link

@bilalahmaddev bilalahmaddev commented Jun 17, 2025

This commit fixes a bug in the Power Source cluster feature implementation where the Battery and Wired feature checks were incorrectly swapped:

In the Wired feature section:

  • Previously checked for Battery feature instead of Wired feature
  • Now correctly checks for Wired feature and shows appropriate error message

In the Battery feature section:

  • Previously checked for Wired feature instead of Battery feature
  • Now correctly checks for Battery feature and shows appropriate error message

This also fixes setting both Wired and Battery features in Power Source cluster in battery storage end device as disallowed by conformance. A power source cluster can not have both wired and battery features under one endpoint. Therefore for a battery storage device only battery feature should be enabled while creating battery storage endpoint.

Impact:
This fix ensures that the feature validation logic correctly identifies when a cluster already supports the respective Battery or Wired features, preventing incorrect error messages and ensuring proper feature management in the ESP Matter framework.

Fixes #1462

@CLAassistant
Copy link

CLAassistant commented Jun 17, 2025

CLA assistant check
All committers have signed the CLA.

@github-actions github-actions bot changed the title Fix incorrect Battery and Wired feature usage in Power Source cluster Fix incorrect Battery and Wired feature usage in Power Source cluster (CON-1728) Jun 17, 2025
Comment on lines +237 to +239
uint32_t wired_feature_map = feature::wired::get_id();
if ((get_feature_map_value(cluster) & wired_feature_map) == wired_feature_map) {
ESP_LOGE(TAG, "Cluster already supports Wired feature");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not how it works, the battery and wired features for Power Source cluster are mutually exclusive, only one of them can be present on an endpoint. This check was to prevent addition of both features on the same endpoint.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This mutually exclusive check is not correct, you can try to create a battery storage device then it will not add battery feature to power source at all.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The check is correct, but the device type requirement is incorrect as mentioned in the Spec issue.

you can try to create a battery storage device then it will not add battery feature to power source at all.

Because you already have added wired feature, only one should be there on an endpoint.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This means it is mandatory to remove this from battery storage endpoint to add battery feature to power source cluster:

power_source::feature::wired::add(power_source_cluster, &config->power_source_device.power_source.wired);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We cannot break the spec compliance, for your use case please maintain a patch to allow battery feature on the Battery Storage device type. Once the spec is updated, we will update the sdk accordingly.

ESP_LOGE(TAG, "Cluster already supports Wired feature");
uint32_t battery_feature_map = feature::battery::get_id();
if ((get_feature_map_value(cluster) & battery_feature_map) == battery_feature_map) {
ESP_LOGE(TAG, "Cluster already supports Battery feature");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the bug in the specification PTAL https://github.com/CHIP-Specifications/connectedhomeip-spec/issues/10912, one of the wired and battery feature should be present on one endpoint. Once the spec is fixed then we should change this code.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only one should be present, not both wired or battery

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Has it been corrected now?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants