2019-04-17 12:06:00 +02:00
|
|
|
import esphome.codegen as cg
|
2019-04-22 21:56:30 +02:00
|
|
|
import esphome.config_validation as cv
|
|
|
|
from esphome.components import binary_sensor
|
2022-02-17 22:39:59 +01:00
|
|
|
from esphome.const import CONF_CHANNEL
|
2021-03-07 20:03:16 +01:00
|
|
|
from . import (
|
|
|
|
mpr121_ns,
|
|
|
|
MPR121Component,
|
|
|
|
CONF_MPR121_ID,
|
|
|
|
CONF_TOUCH_THRESHOLD,
|
|
|
|
CONF_RELEASE_THRESHOLD,
|
|
|
|
)
|
2019-04-17 12:06:00 +02:00
|
|
|
|
2021-03-07 20:03:16 +01:00
|
|
|
DEPENDENCIES = ["mpr121"]
|
|
|
|
MPR121Channel = mpr121_ns.class_("MPR121Channel", binary_sensor.BinarySensor)
|
2019-04-17 12:06:00 +02:00
|
|
|
|
2022-02-17 22:39:59 +01:00
|
|
|
CONFIG_SCHEMA = binary_sensor.binary_sensor_schema(MPR121Channel).extend(
|
2021-03-07 20:03:16 +01:00
|
|
|
{
|
|
|
|
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),
|
|
|
|
cv.Optional(CONF_RELEASE_THRESHOLD): cv.int_range(min=0x05, max=0x30),
|
|
|
|
}
|
|
|
|
)
|
2019-04-17 12:06:00 +02:00
|
|
|
|
|
|
|
|
2021-05-24 10:58:29 +02:00
|
|
|
async def to_code(config):
|
2022-02-17 22:39:59 +01:00
|
|
|
var = await binary_sensor.new_binary_sensor(config)
|
2021-05-24 10:58:29 +02:00
|
|
|
hub = await cg.get_variable(config[CONF_MPR121_ID])
|
2019-04-22 21:56:30 +02:00
|
|
|
cg.add(var.set_channel(config[CONF_CHANNEL]))
|
|
|
|
|
2019-05-28 20:39:20 +02:00
|
|
|
if CONF_TOUCH_THRESHOLD in config:
|
|
|
|
cg.add(var.set_touch_threshold(config[CONF_TOUCH_THRESHOLD]))
|
|
|
|
if CONF_RELEASE_THRESHOLD in config:
|
|
|
|
cg.add(var.set_release_threshold(config[CONF_RELEASE_THRESHOLD]))
|
|
|
|
|
2019-04-17 12:06:00 +02:00
|
|
|
cg.add(hub.register_channel(var))
|