Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use built-in validation for altitude #1831

Merged
merged 4 commits into from May 31, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 1 addition & 6 deletions esphome/components/scd30/sensor.py
@@ -1,4 +1,3 @@
import re
import esphome.codegen as cg
import esphome.config_validation as cv
from esphome.components import i2c, sensor
Expand Down Expand Up @@ -28,10 +27,6 @@
CONF_TEMPERATURE_OFFSET = "temperature_offset"


def remove_altitude_suffix(value):
return re.sub(r"\s*(?:m(?:\s+a\.s\.l)?)|(?:MAM?SL)$", "", value)


CONFIG_SCHEMA = (
cv.Schema(
{
Expand All @@ -47,7 +42,7 @@ def remove_altitude_suffix(value):
),
cv.Optional(CONF_AUTOMATIC_SELF_CALIBRATION, default=True): cv.boolean,
cv.Optional(CONF_ALTITUDE_COMPENSATION): cv.All(
remove_altitude_suffix,
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, default=0): cv.pressure,
Expand Down