mirror of
https://github.com/esphome/esphome.git
synced 2024-11-24 16:08:10 +01:00
Use built-in validation for altitude (#1831)
Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>
This commit is contained in:
parent
5c3268b8d4
commit
d1c6368283
1 changed files with 1 additions and 6 deletions
|
@ -1,4 +1,3 @@
|
||||||
import re
|
|
||||||
import esphome.codegen as cg
|
import esphome.codegen as cg
|
||||||
import esphome.config_validation as cv
|
import esphome.config_validation as cv
|
||||||
from esphome.components import i2c, sensor
|
from esphome.components import i2c, sensor
|
||||||
|
@ -28,10 +27,6 @@ CONF_AMBIENT_PRESSURE_COMPENSATION = "ambient_pressure_compensation"
|
||||||
CONF_TEMPERATURE_OFFSET = "temperature_offset"
|
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 = (
|
CONFIG_SCHEMA = (
|
||||||
cv.Schema(
|
cv.Schema(
|
||||||
{
|
{
|
||||||
|
@ -47,7 +42,7 @@ CONFIG_SCHEMA = (
|
||||||
),
|
),
|
||||||
cv.Optional(CONF_AUTOMATIC_SELF_CALIBRATION, default=True): cv.boolean,
|
cv.Optional(CONF_AUTOMATIC_SELF_CALIBRATION, default=True): cv.boolean,
|
||||||
cv.Optional(CONF_ALTITUDE_COMPENSATION): cv.All(
|
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.int_range(min=0, max=0xFFFF, max_included=False),
|
||||||
),
|
),
|
||||||
cv.Optional(CONF_AMBIENT_PRESSURE_COMPENSATION, default=0): cv.pressure,
|
cv.Optional(CONF_AMBIENT_PRESSURE_COMPENSATION, default=0): cv.pressure,
|
||||||
|
|
Loading…
Reference in a new issue