[apollo_air-1] Add configurable DPS310 pressure offset#78
[apollo_air-1] Add configurable DPS310 pressure offset#78TrevorSchirmer merged 4 commits intobetafrom
Conversation
|
Warning Rate limit exceeded
⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. 📒 Files selected for processing (1)
WalkthroughAdded a new public numeric template entity Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
Integrations/ESPHome/Core.yaml (1)
460-460:⚠️ Potential issue | 🟡 MinorDPS310 self-test checks offset-corrected pressure value, risking spurious failures
The condition at line 460 evaluates
id(dps310pressure).state, which applies the offset filter (x + id(dps310_pressure_offset).state). With the offset range set to ±100 hPa, a user configuring a large offset before running the test could cause a healthy sensor to fail or a faulty one to pass. The test should either read the raw pre-filter pressure value or document this behavior and require the offset to be reset to 0.0 before testing.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@Integrations/ESPHome/Core.yaml` at line 460, The self-test currently compares the offset-corrected value via id(dps310pressure).state (which includes id(dps310_pressure_offset).state), so large user offsets can cause false failures; change the lambda used for the test to read the sensor's raw/pre-filter pressure value instead of the filtered .state (e.g., use the sensor's raw/get_raw API or .raw_state accessor) or alternatively add a precondition and documentation requiring id(dps310_pressure_offset).state == 0.0 before running the test; update the lambda reference (the lambda comparing id(dps310pressure).state) and any docs to reflect the chosen approach.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@Integrations/ESPHome/Core.yaml`:
- Around line 228-229: The DPS310 pressure filter currently adds the stored
offset (lambda: return x + id(dps310_pressure_offset).state) which reverses the
sign convention used by SEN55 offsets; change the DPS310 filter lambda to
subtract the stored offset (use id(dps310_pressure_offset).state with a minus)
so a positive offset lowers the reported pressure like the existing
sen55_temperature_offset and sen55_humidity_offset do, and scan for other DPS310
or SEN55 offset usages to ensure consistent sign handling across filters.
- Around line 228-229: Add a NaN guard to the filter lambda so it does not
propagate NaN from the offset sensor into dps310pressure: inside the lambda used
in the sensor filters (the one referencing id(dps310_pressure_offset).state)
check whether id(dps310_pressure_offset).state is NaN (e.g. using isnan(...) or
std::isnan(...)) and if it is return the raw reading (x) unchanged, otherwise
return x + id(dps310_pressure_offset).state; update only that lambda to perform
this conditional check.
---
Outside diff comments:
In `@Integrations/ESPHome/Core.yaml`:
- Line 460: The self-test currently compares the offset-corrected value via
id(dps310pressure).state (which includes id(dps310_pressure_offset).state), so
large user offsets can cause false failures; change the lambda used for the test
to read the sensor's raw/pre-filter pressure value instead of the filtered
.state (e.g., use the sensor's raw/get_raw API or .raw_state accessor) or
alternatively add a precondition and documentation requiring
id(dps310_pressure_offset).state == 0.0 before running the test; update the
lambda reference (the lambda comparing id(dps310pressure).state) and any docs to
reflect the chosen approach.
| filters: | ||
| - lambda: return x + id(dps310_pressure_offset).state; |
There was a problem hiding this comment.
Offset sign convention is the opposite of existing SEN55 offsets — will confuse users
The existing temperature and humidity offsets both subtract the stored value:
# lines 257, 263 — existing pattern
lambda: return x - id(sen55_temperature_offset).state;
lambda: return x - id(sen55_humidity_offset).state;The DPS310 filter adds the stored value:
lambda: return x + id(dps310_pressure_offset).state;This creates an opposite semantic: for SEN55 a positive offset lowers the reported value ("sensor reads high, dial it down"), while for DPS310 a positive offset raises the reported value. A user who has already learned the SEN55 convention will enter the wrong sign when calibrating the DPS310.
For consistency with the existing offset pattern, consider flipping the sign (or, if the additive convention is intentional, apply it consistently to SEN55 too and document the difference explicitly):
🐛 Proposed fix to align sign convention
filters:
- - lambda: return x + id(dps310_pressure_offset).state;
+ - lambda: return x - id(dps310_pressure_offset).state;🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@Integrations/ESPHome/Core.yaml` around lines 228 - 229, The DPS310 pressure
filter currently adds the stored offset (lambda: return x +
id(dps310_pressure_offset).state) which reverses the sign convention used by
SEN55 offsets; change the DPS310 filter lambda to subtract the stored offset
(use id(dps310_pressure_offset).state with a minus) so a positive offset lowers
the reported pressure like the existing sen55_temperature_offset and
sen55_humidity_offset do, and scan for other DPS310 or SEN55 offset usages to
ensure consistent sign handling across filters.
Add a NaN guard in the filter lambda
If dps310_pressure_offset has not yet restored its value from flash when the first DPS310 reading arrives, id(dps310_pressure_offset).state will be NaN, which would propagate NaN into dps310pressure—and then straight into the SCD40 ambient_pressure_compensation_source. The guard is cheap and prevents silent compensation errors.
🛡️ Proposed fix
filters:
- - lambda: return x + id(dps310_pressure_offset).state;
+ - lambda: |-
+ float offset = id(dps310_pressure_offset).state;
+ return isnan(offset) ? x : x + offset;🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@Integrations/ESPHome/Core.yaml` around lines 228 - 229, Add a NaN guard to
the filter lambda so it does not propagate NaN from the offset sensor into
dps310pressure: inside the lambda used in the sensor filters (the one
referencing id(dps310_pressure_offset).state) check whether
id(dps310_pressure_offset).state is NaN (e.g. using isnan(...) or
std::isnan(...)) and if it is return the raw reading (x) unchanged, otherwise
return x + id(dps310_pressure_offset).state; update only that lambda to perform
this conditional check.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Version: 26.2.24.1
What does this implement/fix?
Adds a user-configurable pressure offset (
DPS310 Pressure Offset) to the DPS310 sensor, following the same pattern already used for the SEN55 temperature and humidity offsets. The offset is exposed as anumberentity (CONFIG category, ±100 hPa range, 0.1 hPa step, persists across reboots). A lambda filter applies it to the reported pressure value.The offset is applied in hPa (the sensor's native unit) regardless of how Home Assistant displays the value. The SCD40's ambient pressure compensation source (
dps310pressure) automatically benefits from the corrected value.Types of changes
Checklist / Checklijst:
If user-visible functionality or configuration variables are added/modified:
Summary by CodeRabbit