mirror of
https://github.com/Threnklyn/esphome-dev.git
synced 2026-06-05 04:18:29 +02:00
Add cd74hc4067 multiplexer (#2431)
Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com> Co-authored-by: asoehlke <git@soehlke.de>
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
import esphome.codegen as cg
|
||||
from esphome import pins
|
||||
import esphome.config_validation as cv
|
||||
from esphome.const import (
|
||||
CONF_DELAY,
|
||||
CONF_ID,
|
||||
)
|
||||
|
||||
CODEOWNERS = ["@asoehlke"]
|
||||
AUTO_LOAD = ["sensor", "voltage_sampler"]
|
||||
|
||||
cd74hc4067_ns = cg.esphome_ns.namespace("cd74hc4067")
|
||||
|
||||
CD74HC4067Component = cd74hc4067_ns.class_(
|
||||
"CD74HC4067Component", cg.Component, cg.PollingComponent
|
||||
)
|
||||
|
||||
CONF_PIN_S0 = "pin_s0"
|
||||
CONF_PIN_S1 = "pin_s1"
|
||||
CONF_PIN_S2 = "pin_s2"
|
||||
CONF_PIN_S3 = "pin_s3"
|
||||
|
||||
DEFAULT_DELAY = "2ms"
|
||||
|
||||
|
||||
CONFIG_SCHEMA = cv.Schema(
|
||||
{
|
||||
cv.GenerateID(): cv.declare_id(CD74HC4067Component),
|
||||
cv.Required(CONF_PIN_S0): pins.internal_gpio_output_pin_schema,
|
||||
cv.Required(CONF_PIN_S1): pins.internal_gpio_output_pin_schema,
|
||||
cv.Required(CONF_PIN_S2): pins.internal_gpio_output_pin_schema,
|
||||
cv.Required(CONF_PIN_S3): pins.internal_gpio_output_pin_schema,
|
||||
cv.Optional(
|
||||
CONF_DELAY, default=DEFAULT_DELAY
|
||||
): cv.positive_time_period_milliseconds,
|
||||
}
|
||||
).extend(cv.COMPONENT_SCHEMA)
|
||||
|
||||
|
||||
async def to_code(config):
|
||||
var = cg.new_Pvariable(config[CONF_ID])
|
||||
await cg.register_component(var, config)
|
||||
|
||||
pin_s0 = await cg.gpio_pin_expression(config[CONF_PIN_S0])
|
||||
cg.add(var.set_pin_s0(pin_s0))
|
||||
pin_s1 = await cg.gpio_pin_expression(config[CONF_PIN_S1])
|
||||
cg.add(var.set_pin_s1(pin_s1))
|
||||
pin_s2 = await cg.gpio_pin_expression(config[CONF_PIN_S2])
|
||||
cg.add(var.set_pin_s2(pin_s2))
|
||||
pin_s3 = await cg.gpio_pin_expression(config[CONF_PIN_S3])
|
||||
cg.add(var.set_pin_s3(pin_s3))
|
||||
|
||||
cg.add(var.set_switch_delay(config[CONF_DELAY]))
|
||||
Reference in New Issue
Block a user