Binary Sensor codegen tidyup (#3217)

This commit is contained in:
Jesse Hills
2022-02-18 10:39:59 +13:00
committed by GitHub
parent 3b8bb09ae3
commit 7a242bb4ed
38 changed files with 196 additions and 222 deletions
+3 -5
View File
@@ -1,7 +1,7 @@
import esphome.codegen as cg
import esphome.config_validation as cv
from esphome.components import binary_sensor
from esphome.const import CONF_CHANNEL, CONF_ID
from esphome.const import CONF_CHANNEL
from . import (
mpr121_ns,
MPR121Component,
@@ -13,9 +13,8 @@ from . import (
DEPENDENCIES = ["mpr121"]
MPR121Channel = mpr121_ns.class_("MPR121Channel", binary_sensor.BinarySensor)
CONFIG_SCHEMA = binary_sensor.BINARY_SENSOR_SCHEMA.extend(
CONFIG_SCHEMA = binary_sensor.binary_sensor_schema(MPR121Channel).extend(
{
cv.GenerateID(): cv.declare_id(MPR121Channel),
cv.GenerateID(CONF_MPR121_ID): cv.use_id(MPR121Component),
cv.Required(CONF_CHANNEL): cv.int_range(min=0, max=11),
cv.Optional(CONF_TOUCH_THRESHOLD): cv.int_range(min=0x05, max=0x30),
@@ -25,8 +24,7 @@ CONFIG_SCHEMA = binary_sensor.BINARY_SENSOR_SCHEMA.extend(
async def to_code(config):
var = cg.new_Pvariable(config[CONF_ID])
await binary_sensor.register_binary_sensor(var, config)
var = await binary_sensor.new_binary_sensor(config)
hub = await cg.get_variable(config[CONF_MPR121_ID])
cg.add(var.set_channel(config[CONF_CHANNEL]))