esphome icon indicating copy to clipboard operation
esphome copied to clipboard

[api] Add new feature changes for Power Management PR 12325

Open rwrozelle opened this issue 1 month ago • 5 comments

What does this implement/fix?

These are api component changes for the new power_management that enables esp-idf power management. See https://docs.espressif.com/projects/esp-idf/en/stable/esp32/api-reference/system/power_management.html

Types of changes

  • [ ] Bugfix (non-breaking change which fixes an issue)
  • [x] New feature (non-breaking change which adds functionality)
  • [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • [ ] Developer breaking change (an API change that could break external components)
  • [ ] Code quality improvements to existing code or addition of tests
  • [ ] Other

Related issue or feature (if applicable):

  • fixes

Pull request in esphome-docs with documentation (if applicable):

  • esphome/esphome-docs#5736

Depends on to use new functionality:

  • esphome/esphome#12325

Test Environment

  • [ ] ESP32
  • [x] ESP32 IDF
  • [ ] ESP8266
  • [ ] RP2040
  • [ ] BK72xx
  • [ ] RTL87xx
  • [ ] nRF52840

Example entry for config.yaml:

# Example config.yaml

Checklist:

  • [x] The code change is tested and works locally.
  • [x] Tests have been added to verify that the new code works (under tests/ folder).

If user exposed functionality or configuration variables are added/changed:

rwrozelle avatar Dec 06 '25 18:12 rwrozelle

To use the changes from this PR as an external component, add the following to your ESPHome configuration YAML file:

external_components:
  - source: github://pr#12327
    components: [api]
    refresh: 1h

(Added by the PR bot)

github-actions[bot] avatar Dec 06 '25 18:12 github-actions[bot]

Codecov Report

:white_check_mark: All modified and coverable lines are covered by tests. :white_check_mark: Project coverage is 72.57%. Comparing base (e0ce66e) to head (83a6be4).

Additional details and impacted files
@@            Coverage Diff             @@
##              dev   #12327      +/-   ##
==========================================
- Coverage   72.60%   72.57%   -0.03%     
==========================================
  Files          53       53              
  Lines       11192    11192              
  Branches     1517     1517              
==========================================
- Hits         8126     8123       -3     
- Misses       2674     2676       +2     
- Partials      392      393       +1     

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

:rocket: New features to boost your workflow:
  • :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

codecov-commenter avatar Dec 06 '25 18:12 codecov-commenter

Memory Impact Analysis

Components: api Platform: esp8266-ard

Metric Target Branch This PR Change
RAM 33,588 bytes 33,588 bytes ➡️ +0 bytes (0.00%)
Flash 452,447 bytes 452,447 bytes ➡️ +0 bytes (0.00%)

Note: This analysis measures static RAM and Flash usage only (compile-time allocation). Dynamic memory (heap) cannot be measured automatically. ⚠️ You must test this PR on a real device to measure free heap and ensure no runtime memory issues.

This analysis runs automatically when components change. Memory usage is measured from a representative test configuration.

github-actions[bot] avatar Dec 06 '25 19:12 github-actions[bot]

Are you sure this is needed? Wifi and websockets should work with power management.

luar123 avatar Dec 08 '25 22:12 luar123

Are you sure this is needed? Wifi and websockets should work with power management.

I built this based on openthread where tasks were not completing (device was going to sleep) and not finishing until next polling cycle. I'm looking for collaborators to flesh this out. https://discord.com/channels/429907082951524364/1446957955156021258 My thinking is that power_management component is robust enough to help with openthread light sleep use cases and if an audience could be found for wifi/ethernet, we could improve via future PR's. I separated these API changes because it is most likely this PR of the api component would end up back in draft while it is improved.

rwrozelle avatar Dec 08 '25 23:12 rwrozelle

In #12325 I stated that api works without this PR, but that might be only true for wifi. If sleep mode in thread is implemented like it is in the zigbee sdk, then there might be the issue that the thread task activates sleep mode even if other tasks could still run and only locks can prevent this. If that is true maybe guard the locks here with USE_OPENTHREAD.

Edit: quick test with the zigbee light sleep example suggests that at least there it is no issue.

luar123 avatar Dec 12 '25 20:12 luar123

I will go back and test esp32-h2 openthread without this PR and see if its functional without.

rwrozelle avatar Dec 14 '25 22:12 rwrozelle

Closing request, functionality is no longer needed.

rwrozelle avatar Dec 15 '25 14:12 rwrozelle