mirror of
https://github.com/Threnklyn/esphome-dev.git
synced 2026-05-19 04:33:27 +02:00
d2648657fb
* Add testing branch to workflow * Add workflow * Checkpoint * Align SPI data rates in c++ code with Python code. * Checkpoint * CI fixes * Update codeowners * Workflow cleanup * Rename to spi_rgb_led * Rename header file * Clang tidy * Disable spi after transfer. * Move enable() to where it belongs * Call spi_setup before enable * Clang tidy * Add test * Rename to spi_led_strip * Include 'defines.h' * Fix CODEOWNERS * Migrate data rate to new style setting. * Remove defines.h * Fix class name * Fix name in .py * And more more name tidy up. --------- Co-authored-by: Keith Burzinski <kbx81x@gmail.com>
28 lines
1.0 KiB
Python
28 lines
1.0 KiB
Python
import esphome.codegen as cg
|
|
import esphome.config_validation as cv
|
|
from esphome.components import light
|
|
from esphome.components import spi
|
|
from esphome.const import CONF_OUTPUT_ID, CONF_NUM_LEDS, CONF_DATA_RATE
|
|
|
|
spi_led_strip_ns = cg.esphome_ns.namespace("spi_led_strip")
|
|
SpiLedStrip = spi_led_strip_ns.class_(
|
|
"SpiLedStrip", light.AddressableLight, spi.SPIDevice
|
|
)
|
|
|
|
CONFIG_SCHEMA = light.ADDRESSABLE_LIGHT_SCHEMA.extend(
|
|
{
|
|
cv.GenerateID(CONF_OUTPUT_ID): cv.declare_id(SpiLedStrip),
|
|
cv.Optional(CONF_NUM_LEDS, default=1): cv.positive_not_null_int,
|
|
cv.Optional(CONF_DATA_RATE, default="1MHz"): spi.SPI_DATA_RATE_SCHEMA,
|
|
}
|
|
).extend(spi.spi_device_schema(False))
|
|
|
|
|
|
async def to_code(config):
|
|
var = cg.new_Pvariable(config[CONF_OUTPUT_ID])
|
|
cg.add(var.set_data_rate(spi.SPI_DATA_RATE_OPTIONS[config[CONF_DATA_RATE]]))
|
|
cg.add(var.set_num_leds(config[CONF_NUM_LEDS]))
|
|
await light.register_light(var, config)
|
|
await spi.register_spi_device(var, config)
|
|
await cg.register_component(var, config)
|