2019-05-31 15:05:37 +02:00
|
|
|
import esphome.codegen as cg
|
|
|
|
import esphome.config_validation as cv
|
|
|
|
from esphome import pins
|
2021-03-07 20:03:16 +01:00
|
|
|
from esphome.const import (
|
|
|
|
CONF_CLOCK_PIN,
|
|
|
|
CONF_DATA_PIN,
|
|
|
|
CONF_ID,
|
|
|
|
CONF_NUM_CHANNELS,
|
|
|
|
CONF_NUM_CHIPS,
|
|
|
|
)
|
2019-05-31 15:05:37 +02:00
|
|
|
|
2021-03-07 20:03:16 +01:00
|
|
|
AUTO_LOAD = ["output"]
|
|
|
|
sm16716_ns = cg.esphome_ns.namespace("sm16716")
|
|
|
|
SM16716 = sm16716_ns.class_("SM16716", cg.Component)
|
2019-05-31 15:05:37 +02:00
|
|
|
|
|
|
|
MULTI_CONF = True
|
2021-03-07 20:03:16 +01:00
|
|
|
CONFIG_SCHEMA = cv.Schema(
|
|
|
|
{
|
|
|
|
cv.GenerateID(): cv.declare_id(SM16716),
|
|
|
|
cv.Required(CONF_DATA_PIN): pins.gpio_output_pin_schema,
|
|
|
|
cv.Required(CONF_CLOCK_PIN): pins.gpio_output_pin_schema,
|
|
|
|
cv.Optional(CONF_NUM_CHANNELS, default=3): cv.int_range(min=3, max=255),
|
|
|
|
cv.Optional(CONF_NUM_CHIPS, default=1): cv.int_range(min=1, max=85),
|
|
|
|
}
|
|
|
|
).extend(cv.COMPONENT_SCHEMA)
|
2019-05-31 15:05:37 +02:00
|
|
|
|
|
|
|
|
2021-05-24 10:58:29 +02:00
|
|
|
async def to_code(config):
|
2019-05-31 15:05:37 +02:00
|
|
|
var = cg.new_Pvariable(config[CONF_ID])
|
2021-05-24 10:58:29 +02:00
|
|
|
await cg.register_component(var, config)
|
2019-05-31 15:05:37 +02:00
|
|
|
|
2021-05-24 10:58:29 +02:00
|
|
|
data = await cg.gpio_pin_expression(config[CONF_DATA_PIN])
|
2019-05-31 15:05:37 +02:00
|
|
|
cg.add(var.set_data_pin(data))
|
2021-05-24 10:58:29 +02:00
|
|
|
clock = await cg.gpio_pin_expression(config[CONF_CLOCK_PIN])
|
2019-05-31 15:05:37 +02:00
|
|
|
cg.add(var.set_clock_pin(clock))
|
|
|
|
|
|
|
|
cg.add(var.set_num_channels(config[CONF_NUM_CHANNELS]))
|
|
|
|
cg.add(var.set_num_chips(config[CONF_NUM_CHIPS]))
|