Update __init__.py
This commit is contained in:
committed by
GitHub
parent
ec1a694de9
commit
44ed70ecf7
@@ -1,20 +1,25 @@
|
||||
import esphome.codegen as cg
|
||||
import esphome.config_validation as cv
|
||||
from esphome.components import i2c
|
||||
import esphome.pins as pins
|
||||
from esphome.components import i2c, gpio
|
||||
from esphome.const import CONF_ID, CONF_ADDRESS, CONF_INTERRUPT_PIN
|
||||
from esphome import pins
|
||||
|
||||
DEPENDENCIES = ["i2c"]
|
||||
|
||||
tca6408_ns = cg.esphome_ns.namespace("tca6408")
|
||||
TCA6408Component = tca6408_ns.class_("TCA6408Component", cg.Component, i2c.I2CDevice)
|
||||
|
||||
TCA6408Component = tca6408_ns.class_(
|
||||
"TCA6408Component", cg.Component, i2c.I2CDevice
|
||||
)
|
||||
|
||||
TCA6408GPIOPin = tca6408_ns.class_("TCA6408GPIOPin", cg.GPIOPin)
|
||||
|
||||
CONFIG_SCHEMA = (
|
||||
cv.Schema(
|
||||
{
|
||||
cv.GenerateID(): cv.declare_id(TCA6408Component),
|
||||
cv.Optional(CONF_ADDRESS, default=0x20): cv.i2c_address,
|
||||
cv.Optional(CONF_INTERRUPT_PIN): pins.gpio_input_pin_schema, # ← Fixed
|
||||
cv.Optional(CONF_INTERRUPT_PIN): gpio.gpio_input_pin_schema,
|
||||
}
|
||||
)
|
||||
.extend(cv.COMPONENT_SCHEMA)
|
||||
@@ -27,10 +32,22 @@ async def to_code(config):
|
||||
await cg.register_component(var, config)
|
||||
await i2c.register_i2c_device(var, config)
|
||||
|
||||
if CONF_ADDRESS in config:
|
||||
cg.add(var.set_address(config[CONF_ADDRESS]))
|
||||
cg.add(var.set_address(config[CONF_ADDRESS]))
|
||||
|
||||
if CONF_INTERRUPT_PIN in config:
|
||||
pin = await gpio.register_gpio_pin(var, config[CONF_INTERRUPT_PIN])
|
||||
cg.add(var.set_interrupt_pin(pin))
|
||||
|
||||
|
||||
# ===== PIN REGISTRATION =====
|
||||
|
||||
TCA6408_PIN_SCHEMA = gpio.gpio_base_schema(TCA6408GPIOPin).extend(
|
||||
{
|
||||
cv.Required("number"): cv.int_range(min=0, max=7),
|
||||
}
|
||||
)
|
||||
|
||||
@pins.PIN_SCHEMA_REGISTRY.register("tca6408", TCA6408_PIN_SCHEMA)
|
||||
async def tca6408_pin_to_code(config):
|
||||
var = cg.new_Pvariable(config["number"])
|
||||
yield var
|
||||
|
||||
Reference in New Issue
Block a user