[climate] Save 48 bytes per entity by conditionally compiling visual overrides - #12406
Conversation
|
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#12406
components: [climate]
refresh: 1h(Added by the PR bot) |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #12406 +/- ##
==========================================
+ Coverage 72.56% 72.58% +0.02%
==========================================
Files 53 53
Lines 11192 11192
Branches 1517 1517
==========================================
+ Hits 8121 8124 +3
+ Misses 2677 2675 -2
+ Partials 394 393 -1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Memory Impact AnalysisComponents:
📊 Component Memory Breakdown
🔍 Symbol-Level Changes (click to expand)Changed Symbols
This analysis runs automatically when components change. Memory usage is measured from a representative test configuration. |
There was a problem hiding this comment.
Pull request overview
This PR optimizes memory usage for climate entities by conditionally compiling visual override fields, saving 24-48 bytes per climate entity depending on whether visual overrides are used. The visual override feature allows users to customize the min/max temperature/humidity ranges and temperature steps displayed to frontends, but is rarely used in practice.
Key Changes
- Replaced
optional<float>withfloatusingNANas sentinel value (saves 4 bytes per field due to alignment) - Wrapped 6 visual override fields and their setter methods with
#ifdef USE_CLIMATE_VISUAL_OVERRIDES - Updated Python code generation to define
USE_CLIMATE_VISUAL_OVERRIDESwhen any visual override is configured
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| esphome/core/defines.h | Added USE_CLIMATE_VISUAL_OVERRIDES define for IDE/static analysis (auto-generated file) |
| esphome/components/climate/climate.h | Guarded visual override setter methods and member fields with #ifdef USE_CLIMATE_VISUAL_OVERRIDES |
| esphome/components/climate/climate.cpp | Guarded setter implementations and get_traits() override logic with #ifdef, replaced has_value() checks with std::isnan() |
| esphome/components/climate/init.py | Added cg.add_define("USE_CLIMATE_VISUAL_OVERRIDES") when any visual config is used |
|
Thanks |
What does this implement/fix?
Conditionally compile climate visual override fields to save 24 bytes per climate entity when the feature is unused.
The
visual:config option (min/max temperature, temperature step, min/max humidity overrides) has been present since the original climate implementation in April 2019, but is rarely used. Most climate configurations don't override the visual limits reported by the device.Changes
optional<float>withfloatusingNANas sentinel (saves 4 bytes per field due to alignment padding)#ifdef USE_CLIMATE_VISUAL_OVERRIDESUSE_CLIMATE_VISUAL_OVERRIDESwhen at least one climate uses thevisual:configMemory savings
Before: 6 ×
optional<float>= 48 bytes per climate entity (always allocated)After:
float= 24 bytes → 24 bytes savedMost users don't use
visual:overrides, so they save the full 48 bytes per climate entity.Types of changes
Related issue or feature (if applicable):
Pull request in esphome-docs with documentation (if applicable):
Test Environment
Example entry for
config.yaml:Checklist:
tests/folder).If user exposed functionality or configuration variables are 8000 added/changed: