mirror of
https://github.com/Threnklyn/esphome-dev.git
synced 2026-06-01 02:28:28 +02:00
Mpr121 added debounce and thresholds config (#558)
* fixed code issues from previous PR * travis line to long * travis * more travis * Update esphome/components/mpr121/mpr121.h Co-Authored-By: Otto Winter <otto@otto-winter.com> * fixed issues * fixed issues * fixes remove duplicate line remove threshold settings * fixed touch release thresholds mixup
This commit is contained in:
committed by
Otto Winter
parent
2570f2d6f2
commit
9e56318498
@@ -2,7 +2,8 @@ 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 . import mpr121_ns, MPR121Component, CONF_MPR121_ID
|
||||
from . import mpr121_ns, MPR121Component, CONF_MPR121_ID, CONF_TOUCH_THRESHOLD, \
|
||||
CONF_RELEASE_THRESHOLD
|
||||
|
||||
DEPENDENCIES = ['mpr121']
|
||||
MPR121Channel = mpr121_ns.class_('MPR121Channel', binary_sensor.BinarySensor)
|
||||
@@ -11,14 +12,20 @@ CONFIG_SCHEMA = binary_sensor.BINARY_SENSOR_SCHEMA.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),
|
||||
cv.Optional(CONF_RELEASE_THRESHOLD): cv.int_range(min=0x05, max=0x30),
|
||||
})
|
||||
|
||||
|
||||
def to_code(config):
|
||||
var = cg.new_Pvariable(config[CONF_ID])
|
||||
yield binary_sensor.register_binary_sensor(var, config)
|
||||
|
||||
hub = yield cg.get_variable(config[CONF_MPR121_ID])
|
||||
cg.add(var.set_channel(config[CONF_CHANNEL]))
|
||||
|
||||
hub = yield cg.get_variable(config[CONF_MPR121_ID])
|
||||
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]))
|
||||
|
||||
cg.add(hub.register_channel(var))
|
||||
|
||||
Reference in New Issue
Block a user