Update __init__.py

This commit is contained in:
Dave Williams | DitroniX | G8PUO
2026-06-13 09:23:24 +01:00
committed by GitHub
parent 0c212e3807
commit 3863d71791
+11 -17
View File
@@ -22,41 +22,35 @@ CONFIG_SCHEMA = (
# I²C address of the TCA6408 (default 0x20 when ADDR pins are grounded) # I²C address of the TCA6408 (default 0x20 when ADDR pins are grounded)
cv.Optional(CONF_ADDRESS, default=0x20): cv.i2c_address, cv.Optional(CONF_ADDRESS, default=0x20): cv.i2c_address,
# Optional ESP GPIO connected to the TCA6408 INT pin (recommended for fast input response) # Optional ESP GPIO connected to the TCA6408 INT pin (recommended)
cv.Optional(CONF_INTERRUPT_PIN): gpio.validate_gpio_pin("internal"), cv.Optional(CONF_INTERRUPT_PIN): gpio.validate_gpio_pin("internal"),
} }
) )
.extend(cv.COMPONENT_SCHEMA) # Standard ESPHome component settings .extend(cv.COMPONENT_SCHEMA)
.extend(i2c.i2c_device_schema()) # I²C device configuration (SDA/SCL) .extend(i2c.i2c_device_schema())
) )
async def to_code(config): async def to_code(config):
"""Generate C++ code from the YAML configuration""" """Generate C++ code from the YAML configuration."""
# Create a new instance of the C++ component
var = cg.new_Pvariable(config[CONF_ID]) var = cg.new_Pvariable(config[CONF_ID])
# Register as a standard ESPHome component
await cg.register_component(var, config) await cg.register_component(var, config)
# Register as an I²C device
await i2c.register_i2c_device(var, config) await i2c.register_i2c_device(var, config)
# Set the I²C address
cg.add(var.set_address(config[CONF_ADDRESS])) cg.add(var.set_address(config[CONF_ADDRESS]))
# Configure interrupt pin if specified in YAML
if CONF_INTERRUPT_PIN in config: if CONF_INTERRUPT_PIN in config:
pin = await gpio.register_gpio_pin(var, config[CONF_INTERRUPT_PIN]) pin = await gpio.register_gpio_pin(var, config[CONF_INTERRUPT_PIN])
cg.add(var.set_interrupt_pin(pin)) cg.add(var.set_interrupt_pin(pin))
# ================================================ # ================================================
# YAML USAGE EXAMPLES (for documentation) # YAML USAGE EXAMPLES
# ================================================ # ================================================
""" """
# Basic Configuration (Outputs Only) # Example 1: Basic Outputs Only
tca6408: tca6408:
- id: tca6408_hub - id: tca6408_hub
address: 0x20 address: 0x20
@@ -70,7 +64,7 @@ switch:
mode: OUTPUT mode: OUTPUT
# Full Configuration with Interrupt (Recommended) # Example 2: Full Configuration with Interrupt (Recommended)
i2c: i2c:
sda: GPIO4 sda: GPIO4
scl: GPIO5 scl: GPIO5
@@ -79,19 +73,19 @@ i2c:
tca6408: tca6408:
- id: tca6408_hub - id: tca6408_hub
address: 0x20 address: 0x20
interrupt_pin: GPIO6 # Connect to TCA6408 INT pin (with pull-up) interrupt_pin: GPIO6
# Outputs # Outputs
switch: switch:
- platform: gpio - platform: gpio
name: "Relay 1 (Active Low)" name: "Relay (Active Low)"
pin: pin:
tca6408: tca6408_hub tca6408: tca6408_hub
number: 1 number: 1
mode: OUTPUT mode: OUTPUT
inverted: true inverted: true
# Inputs (Binary Sensors) # Inputs
binary_sensor: binary_sensor:
- platform: gpio - platform: gpio
name: "Door Sensor" name: "Door Sensor"
@@ -99,5 +93,5 @@ binary_sensor:
tca6408: tca6408_hub tca6408: tca6408_hub
number: 3 number: 3
mode: INPUT mode: INPUT
inverted: true # Hardware polarity inversion inverted: true
""" """