[scd4x] Fix ambient_pressure_compensation unit handling (#19888)

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-authored-by: J. Nick Koston <nick@home-assistant.io>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
zerafachris
2026-10-18 21:54:33 -10:00
committed by GitHub
co-authored by Claude Sonnet 4.6 J. Nick Koston Copilot Autofix powered by AI
parent 4498ad2c77
commit b919b692f7
2 changed files with 28 additions and 1 deletions
+12 -1
View File
@@ -42,6 +42,15 @@ MEASUREMENT_MODE_OPTIONS = MeasurementMode.options(
)
def pressure_hpa(value: str | float) -> float:
"""Pressure in hPa. A bare number is hPa, matching what the C++ sends to the sensor."""
try:
return cv.float_(value)
except cv.Invalid:
pass
return cv.pressure(value) * 1000 # bar, mbar, mBar
CONFIG_SCHEMA = (
cv.Schema(
{
@@ -72,7 +81,9 @@ CONFIG_SCHEMA = (
cv.float_with_unit("altitude", "(m|m a.s.l.|MAMSL|MASL)"),
cv.int_range(min=0, max=0xFFFF, max_included=False),
),
cv.Optional(CONF_AMBIENT_PRESSURE_COMPENSATION): cv.pressure,
cv.Optional(CONF_AMBIENT_PRESSURE_COMPENSATION): cv.All(
pressure_hpa, cv.Any(cv.float_range(min=700, max=1200), 0)
),
cv.Optional(CONF_TEMPERATURE_OFFSET, default="4°C"): cv.temperature_delta,
cv.Optional(CONF_AMBIENT_PRESSURE_COMPENSATION_SOURCE): cv.use_id(
sensor.Sensor
+16
View File
@@ -14,3 +14,19 @@ sensor:
ambient_pressure_compensation: 961mBar
temperature_offset: 4.2C
update_interval: 15s
- platform: scd4x
i2c_id: i2c_bus
co2:
name: SCD4X CO2 (bare hPa)
ambient_pressure_compensation: 961
- platform: scd4x
i2c_id: i2c_bus
co2:
name: SCD4X CO2 (bar)
ambient_pressure_compensation: 0.961bar
- platform: scd4x
i2c_id: i2c_bus
co2:
name: SCD4X CO2 (altitude only)
altitude_compensation: 500m
ambient_pressure_compensation: 0