From d1c6368283ac5231dfaf0edc8822105773b70a89 Mon Sep 17 00:00:00 2001 From: Stefan Agner Date: Mon, 31 May 2021 21:40:57 +0200 Subject: [PATCH] Use built-in validation for altitude (#1831) Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com> --- esphome/components/scd30/sensor.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/esphome/components/scd30/sensor.py b/esphome/components/scd30/sensor.py index a5eb5d8ca4..aad2a1811c 100644 --- a/esphome/components/scd30/sensor.py +++ b/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 @@ -28,10 +27,6 @@ CONF_AMBIENT_PRESSURE_COMPENSATION = "ambient_pressure_compensation" 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( { @@ -47,7 +42,7 @@ CONFIG_SCHEMA = ( ), 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,