using consts from consts.py

This commit is contained in:
Anton Viktorov 2024-05-23 05:48:24 +02:00
parent 9c24d199e5
commit 43e6fe3913

View file

@ -2,6 +2,9 @@ import esphome.codegen as cg
import esphome.config_validation as cv
from esphome.components import sensor
from esphome.const import (
CONF_ACCELERATION_X,
CONF_ACCELERATION_Y,
CONF_ACCELERATION_Z,
CONF_NAME,
ICON_BRIEFCASE_DOWNLOAD,
STATE_CLASS_MEASUREMENT,
@ -11,10 +14,6 @@ from . import MSA3xxComponent, CONF_MSA3XX_ID
DEPENDENCIES = ["msa3xx"]
CONF_ACCEL_X = "accel_x"
CONF_ACCEL_Y = "accel_y"
CONF_ACCEL_Z = "accel_z"
accel_schema = cv.maybe_simple_value(
sensor.sensor_schema(
@ -31,9 +30,9 @@ CONFIG_SCHEMA = cv.All(
cv.Schema(
{
cv.GenerateID(CONF_MSA3XX_ID): cv.use_id(MSA3xxComponent),
cv.Optional(CONF_ACCEL_X): accel_schema,
cv.Optional(CONF_ACCEL_Y): accel_schema,
cv.Optional(CONF_ACCEL_Z): accel_schema,
cv.Optional(CONF_ACCELERATION_X): accel_schema,
cv.Optional(CONF_ACCELERATION_Y): accel_schema,
cv.Optional(CONF_ACCELERATION_Z): accel_schema,
}
).extend(cv.COMPONENT_SCHEMA)
)
@ -43,7 +42,7 @@ async def to_code(config):
hub = await cg.get_variable(config[CONF_MSA3XX_ID])
for d in ["x", "y", "z"]:
accel_key = f"accel_{d}"
accel_key = f"acceleration_{d}"
if accel_key in config:
sens = await sensor.new_sensor(config[accel_key])
cg.add(getattr(hub, f"set_accel_{d}_sensor")(sens))