espHome-NBS-files/external_components/tablesoccer_btn_helper/__init__.py

41 lines
1.3 KiB
Python
Raw Permalink Normal View History

import esphome.codegen as cg
import esphome.config_validation as cv
from esphome import pins
from esphome.components import mqtt, gpio
from esphome.const import CONF_ID
DEPENDENCIES=["mqtt"]
tablesoccer_helper_ns = cg.esphome_ns.namespace('tablesoccer_helper')
BtnHelperClass = tablesoccer_helper_ns.class_('BtnHelperClass', mqtt.MQTTComponent, cg.Component)
#CONF_WS2812_PIN = "pin"
#CONF_WS2812_RGB_MODE = "rgb_mode"
CONF_SENSOR_RED = "sensor_blue"
CONF_SENSOR_BLUE = "sender_red"
CONF_BTN_RESET = "reset_pin"
CONF_BTN_UNDO = "undo_pin"
CONF_KEEP_ALIVE_OUTPUT = "keep_alive"
CONFIG_SCHEMA = cv.COMPONENT_SCHEMA.extend({
cv.GenerateID(CONF_ID): cv.declare_id(BtnHelperClass),
cv.Required(CONF_BTN_RESET): pins.gpio_output_pin_schema,
cv.Required(CONF_BTN_UNDO): pins.gpio_output_pin_schema,
cv.Required(CONF_KEEP_ALIVE_OUTPUT): cv.use_id(gpio.output.GPIOBinaryOutput),
})
def to_code(config):
var = cg.new_Pvariable(config[CONF_ID])
#yield cg.register_component(var, config)
yield mqtt.register_mqtt_component(var, config)
btnReset = yield cg.gpio_pin_expression(config[CONF_BTN_RESET])
cg.add(var.set_reset_pin(btnReset))
btnUndo = yield cg.gpio_pin_expression(config[CONF_BTN_UNDO])
cg.add(var.set_undo_pin(btnUndo))
keep_alive = yield cg.get_variable(config[CONF_KEEP_ALIVE_OUTPUT])
cg.add(var.set_keep_alive_output(keep_alive))