From f9b6cea100bff3ddbc77e6e0879fffdaeb78e186 Mon Sep 17 00:00:00 2001 From: Michiel van Turnhout Date: Mon, 27 May 2019 11:04:18 +0200 Subject: [PATCH] fixed issues --- esphome/components/mpr121/__init__.py | 15 ++++++++------- esphome/components/mpr121/binary_sensor.py | 3 +-- esphome/components/mpr121/mpr121.cpp | 2 -- esphome/components/mpr121/mpr121.h | 7 ++----- esphome/components/mpr121/mpr121_const.py | 4 ---- 5 files changed, 11 insertions(+), 20 deletions(-) delete mode 100644 esphome/components/mpr121/mpr121_const.py diff --git a/esphome/components/mpr121/__init__.py b/esphome/components/mpr121/__init__.py index 5cbaee5fc1..86d92bb28e 100644 --- a/esphome/components/mpr121/__init__.py +++ b/esphome/components/mpr121/__init__.py @@ -2,8 +2,11 @@ import esphome.codegen as cg import esphome.config_validation as cv from esphome.components import i2c from esphome.const import CONF_ID -from esphome.components.mpr121.mpr121_const import CONF_RELEASE_DEBOUNCE, \ - CONF_TOUCH_DEBOUNCE, CONF_TOUCH_THRESHOLD, CONF_RELEASE_THRESHOLD + +CONF_TOUCH_THRESHOLD = "touch_threshold" +CONF_RELEASE_THRESHOLD = "release_threshold" +CONF_TOUCH_DEBOUNCE = "touch_debounce" +CONF_RELEASE_DEBOUNCE = "release_debounce" DEPENDENCIES = ['i2c'] AUTO_LOAD = ['binary_sensor'] @@ -16,11 +19,9 @@ MULTI_CONF = True CONFIG_SCHEMA = cv.Schema({ cv.GenerateID(): cv.declare_id(MPR121Component), cv.Optional(CONF_RELEASE_DEBOUNCE, default=0): cv.int_range(min=0, max=7), - cv.Optional(CONF_TOUCH_DEBOUNCE, default=0): cv.All(cv.Coerce(int), cv.Range(min=0, max=7)), - cv.Optional(CONF_TOUCH_THRESHOLD, default=0x06): cv.All(cv.Coerce(int), - cv.Range(min=0x05, max=0x30)), - cv.Optional(CONF_RELEASE_THRESHOLD, default=0x0b): cv.All(cv.Coerce(int), - cv.Range(min=0x05, max=0x30)), + cv.Optional(CONF_TOUCH_DEBOUNCE, default=0): cv.int_range(min=0, max=7), + cv.Optional(CONF_TOUCH_THRESHOLD, default=0x06): cv.int_range(min=0x05, max=0x30), + cv.Optional(CONF_RELEASE_THRESHOLD, default=0x0b): cv.int_range(min=0x05, max=0x30), }).extend(cv.COMPONENT_SCHEMA).extend(i2c.i2c_device_schema(0x5A)) diff --git a/esphome/components/mpr121/binary_sensor.py b/esphome/components/mpr121/binary_sensor.py index 0e5fe2f6ea..00ea19b6c8 100644 --- a/esphome/components/mpr121/binary_sensor.py +++ b/esphome/components/mpr121/binary_sensor.py @@ -2,9 +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 esphome.components.mpr121.mpr121_const import CONF_TOUCH_THRESHOLD, \ +from . import mpr121_ns, MPR121Component, CONF_MPR121_ID, CONF_TOUCH_THRESHOLD, \ CONF_RELEASE_THRESHOLD -from . import mpr121_ns, MPR121Component, CONF_MPR121_ID DEPENDENCIES = ['mpr121'] MPR121Channel = mpr121_ns.class_('MPR121Channel', binary_sensor.BinarySensor) diff --git a/esphome/components/mpr121/mpr121.cpp b/esphome/components/mpr121/mpr121.cpp index 7e47c51915..2ba6161cd5 100644 --- a/esphome/components/mpr121/mpr121.cpp +++ b/esphome/components/mpr121/mpr121.cpp @@ -49,14 +49,12 @@ void MPR121Component::set_touch_debounce(uint8_t debounce) { uint8_t mask = debounce << 4; this->debounce_ &= 0x0f; this->debounce_ |= mask; - ESP_LOGD(TAG, "debounce:%02x", this->debounce_); } void MPR121Component::set_release_debounce(uint8_t debounce) { uint8_t mask = debounce & 0x0f; this->debounce_ &= 0xf0; this->debounce_ |= mask; - ESP_LOGD(TAG, "debounce:%02x", this->debounce_); }; void MPR121Component::dump_config() { diff --git a/esphome/components/mpr121/mpr121.h b/esphome/components/mpr121/mpr121.h index 5ddcc6e4bc..3312a275c0 100644 --- a/esphome/components/mpr121/mpr121.h +++ b/esphome/components/mpr121/mpr121.h @@ -7,9 +7,6 @@ namespace esphome { namespace mpr121 { -#define DEFAULT_TOUCH_THRESHOLD 12 -#define DEFAULT_RELEASE_THRESHOLD 6 - enum { MPR121_TOUCHSTATUS_L = 0x00, MPR121_TOUCHSTATUS_H = 0x01, @@ -81,8 +78,8 @@ class MPR121Component : public Component, public i2c::I2CDevice { protected: std::vector channels_{}; uint8_t debounce_{0}; - uint8_t touch_threshold_{DEFAULT_TOUCH_THRESHOLD}; - uint8_t release_threshold_{DEFAULT_RELEASE_THRESHOLD}; + uint8_t touch_threshold_{12}; + uint8_t release_threshold_{6}; enum ErrorCode { NONE = 0, COMMUNICATION_FAILED, diff --git a/esphome/components/mpr121/mpr121_const.py b/esphome/components/mpr121/mpr121_const.py deleted file mode 100644 index 0118950e5a..0000000000 --- a/esphome/components/mpr121/mpr121_const.py +++ /dev/null @@ -1,4 +0,0 @@ -CONF_TOUCH_THRESHOLD = "touch_threshold" -CONF_RELEASE_THRESHOLD = "release_threshold" -CONF_TOUCH_DEBOUNCE = "touch_debounce" -CONF_RELEASE_DEBOUNCE = "release_debounce"