mirror of
https://github.com/Threnklyn/esphome-dev.git
synced 2026-05-19 12:43:28 +02:00
92f8b043ce
* module mpr121 * added mpr121 sensor and binary sensor * added tests * removed CONF_CHANNELS, it is not supported in the esphome-code mpr121 code * changed namespace for mpr121 to binary_sensor * Update esphome/components/binary_sensor/mpr121.py Co-Authored-By: mvturnho <qris.online@gmail.com> * fixed class names * fix lint errors
29 lines
1.0 KiB
Python
29 lines
1.0 KiB
Python
import voluptuous as vol
|
|
|
|
from esphome.components import binary_sensor
|
|
from esphome.components.mpr121 import MPR121Component, CONF_MPR121_ID
|
|
import esphome.config_validation as cv
|
|
from esphome.const import CONF_CHANNEL, CONF_NAME
|
|
from esphome.cpp_generator import get_variable
|
|
|
|
DEPENDENCIES = ['mpr121']
|
|
MPR121Channel = binary_sensor.binary_sensor_ns.class_(
|
|
'MPR121Channel', binary_sensor.BinarySensor)
|
|
|
|
PLATFORM_SCHEMA = cv.nameable(binary_sensor.BINARY_SENSOR_PLATFORM_SCHEMA.extend({
|
|
cv.GenerateID(): cv.declare_variable_id(MPR121Channel),
|
|
cv.GenerateID(CONF_MPR121_ID): cv.use_variable_id(MPR121Component),
|
|
vol.Required(CONF_CHANNEL): vol.All(vol.Coerce(int), vol.Range(min=0, max=11))
|
|
}))
|
|
|
|
|
|
def to_code(config):
|
|
for hub in get_variable(config[CONF_MPR121_ID]):
|
|
yield
|
|
rhs = MPR121Channel.new(config[CONF_NAME], config[CONF_CHANNEL])
|
|
binary_sensor.register_binary_sensor(hub.add_channel(rhs), config)
|
|
|
|
|
|
def to_hass_config(data, config):
|
|
return binary_sensor.core_to_hass_config(data, config)
|