36 lines
1.0 KiB
Python
36 lines
1.0 KiB
Python
import esphome.codegen as cg
|
|
import esphome.config_validation as cv
|
|
from esphome.components import mqtt, number
|
|
from esphome.const import CONF_ID
|
|
|
|
ws2812_table_tennis_ns = cg.esphome_ns.namespace('ws2812_table_tennis')
|
|
W2812Display = ws2812_table_tennis_ns.class_('CustomNumberDisplayComponent', mqtt.MQTTComponent, cg.Component)
|
|
|
|
DEPENDENCIES = ['mqtt', 'number']
|
|
|
|
#CONF_WS2812_PIN = "pin"
|
|
#CONF_WS2812_RGB_MODE = "rgb_mode"
|
|
|
|
CONF_RED_NUM = "red_number"
|
|
CONF_BLUE_NUM = "blue_number"
|
|
|
|
|
|
CONFIG_SCHEMA = cv.Schema({
|
|
cv.GenerateID(CONF_ID): cv.declare_id(W2812Display),
|
|
cv.Required(CONF_RED_NUM): cv.use_id(number.Number),
|
|
cv.Required(CONF_BLUE_NUM): cv.use_id(number.Number)
|
|
})
|
|
|
|
|
|
def to_code(config):
|
|
var = cg.new_Pvariable(config[CONF_ID])
|
|
#yield cg.register_component(var, config)
|
|
yield mqtt.register_mqtt_component(var, config)
|
|
|
|
red = yield cg.get_variable(config[CONF_RED_NUM])
|
|
cg.add(var.set_red_number(red))
|
|
|
|
blue = yield cg.get_variable(config[CONF_BLUE_NUM])
|
|
cg.add(var.set_blue_number(blue))
|
|
|
|
cg.add_library("makuna/NeoPixelBus", "2.7.3") |