mirror of
https://github.com/esphome/esphome.git
synced 2025-02-24 05:48:14 +00:00
* Renamed Nameable to EntityBase (cpp) * Renamed NAMEABLE_SCHEMA to ENTITY_BASE_SCHEMA (Python) * Renamed cg.Nameable to cg.EntityBase (Python) * Remove redundant use of CONF_NAME from esp32_touch * Remove redundant use of CONF_NAME from mcp3008 * Updated test * Moved EntityBase from Component.h and Component.cpp * Added icon property to EntityBase * Added CONF_ICON to ENTITY_BASE_SCHEMA and added setup_entity function to cpp_helpers * Added MQTT component getters for icon and disabled_by_default * Lint * Removed icon field from MQTT components * Code generation now uses setup_entity to setENTITY_BASE_SCHEMA fields * Removed unused import * Added cstdint include * Optimisation: don't set icon if it is empty * Remove icon from NumberTraits and SelectTraits * Removed unused import * Integration and Total Daily Energy sensors now inherit icons from their parents during code generation * Minor comment correction * Removed redundant icon-handling code from sensor, switch, and text_sensor * Update esphome/components/tsl2591/tsl2591.h Co-authored-by: Oxan van Leeuwen <oxan@oxanvanleeuwen.nl> * Added icon property to binary sensor, climate, cover, and fan component tests * Added icons for Binary Sensor, Climate, Cover, Fan, and Light to API * Consolidated EntityBase fields in MQTT components Co-authored-by: Oxan van Leeuwen <oxan@oxanvanleeuwen.nl>
63 lines
1.8 KiB
Python
63 lines
1.8 KiB
Python
import esphome.codegen as cg
|
|
import esphome.config_validation as cv
|
|
from esphome.components import binary_sensor
|
|
from esphome.const import (
|
|
CONF_PIN,
|
|
CONF_THRESHOLD,
|
|
CONF_ID,
|
|
)
|
|
from esphome.components.esp32 import gpio
|
|
from . import esp32_touch_ns, ESP32TouchComponent
|
|
|
|
DEPENDENCIES = ["esp32_touch", "esp32"]
|
|
|
|
CONF_ESP32_TOUCH_ID = "esp32_touch_id"
|
|
CONF_WAKEUP_THRESHOLD = "wakeup_threshold"
|
|
|
|
TOUCH_PADS = {
|
|
4: cg.global_ns.TOUCH_PAD_NUM0,
|
|
0: cg.global_ns.TOUCH_PAD_NUM1,
|
|
2: cg.global_ns.TOUCH_PAD_NUM2,
|
|
15: cg.global_ns.TOUCH_PAD_NUM3,
|
|
13: cg.global_ns.TOUCH_PAD_NUM4,
|
|
12: cg.global_ns.TOUCH_PAD_NUM5,
|
|
14: cg.global_ns.TOUCH_PAD_NUM6,
|
|
27: cg.global_ns.TOUCH_PAD_NUM7,
|
|
33: cg.global_ns.TOUCH_PAD_NUM8,
|
|
32: cg.global_ns.TOUCH_PAD_NUM9,
|
|
}
|
|
|
|
|
|
def validate_touch_pad(value):
|
|
value = gpio.validate_gpio_pin(value)
|
|
if value not in TOUCH_PADS:
|
|
raise cv.Invalid(f"Pin {value} does not support touch pads.")
|
|
return value
|
|
|
|
|
|
ESP32TouchBinarySensor = esp32_touch_ns.class_(
|
|
"ESP32TouchBinarySensor", binary_sensor.BinarySensor
|
|
)
|
|
|
|
CONFIG_SCHEMA = binary_sensor.BINARY_SENSOR_SCHEMA.extend(
|
|
{
|
|
cv.GenerateID(): cv.declare_id(ESP32TouchBinarySensor),
|
|
cv.GenerateID(CONF_ESP32_TOUCH_ID): cv.use_id(ESP32TouchComponent),
|
|
cv.Required(CONF_PIN): validate_touch_pad,
|
|
cv.Required(CONF_THRESHOLD): cv.uint16_t,
|
|
cv.Optional(CONF_WAKEUP_THRESHOLD, default=0): cv.uint16_t,
|
|
}
|
|
)
|
|
|
|
|
|
async def to_code(config):
|
|
hub = await cg.get_variable(config[CONF_ESP32_TOUCH_ID])
|
|
var = cg.new_Pvariable(
|
|
config[CONF_ID],
|
|
TOUCH_PADS[config[CONF_PIN]],
|
|
config[CONF_THRESHOLD],
|
|
config[CONF_WAKEUP_THRESHOLD],
|
|
)
|
|
await binary_sensor.register_binary_sensor(var, config)
|
|
cg.add(hub.register_touch_pad(var))
|