Use built-in validation for altitude (#1831)

Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>
This commit is contained in:
Stefan Agner 2021-05-31 21:40:57 +02:00 committed by GitHub
parent 5c3268b8d4
commit d1c6368283
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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,