73 lines
2.1 KiB
Python
73 lines
2.1 KiB
Python
import esphome.codegen as cg
|
|
import esphome.config_validation as cv
|
|
from esphome import pins, automation
|
|
from esphome.components import uart
|
|
from esphome.const import (
|
|
CONF_ID
|
|
)
|
|
|
|
CODEOWNERS = ["@nbsgames"]
|
|
DEPENDENCIES=["uart"]
|
|
|
|
hoermann_door_ns = cg.esphome_ns.namespace('hoermann_door')
|
|
HoermannDoor = hoermann_door_ns.class_('HoermannMainComponent', cg.Component)
|
|
StopPolling = hoermann_door_ns.class_('StopPollingAction', automation.Action)
|
|
StartPolling = hoermann_door_ns.class_('StartPollingAction', automation.Action)
|
|
|
|
CONF_UART_ENTRY = "uart_connection"
|
|
CONF_TX_PIN = "tx_pin"
|
|
CONF_LOG_LEVEL = "log_level"
|
|
|
|
#define LL_OFF 0
|
|
#define LL_ERROR 1
|
|
#define LL_WARN 2
|
|
#define LL_INFO 3
|
|
#define LL_DEBUG 4
|
|
|
|
CONF_LOG_LEVELS = {
|
|
"NONE": 0,
|
|
"ERROR": 1,
|
|
"WARN": 2,
|
|
"INFO": 3,
|
|
"DEBUG": 4,
|
|
}
|
|
|
|
def validate_config(config):
|
|
return config
|
|
|
|
CONFIG_SCHEMA = cv.All(
|
|
cv.COMPONENT_SCHEMA.extend({
|
|
cv.GenerateID(): cv.declare_id(HoermannDoor),
|
|
cv.Required(CONF_UART_ENTRY): cv.use_id(uart.UARTComponent),
|
|
cv.Required(CONF_TX_PIN): pins.internal_gpio_output_pin_schema,
|
|
cv.Optional(CONF_LOG_LEVEL, default="INFO"): cv.enum(CONF_LOG_LEVELS, upper=True),
|
|
}),
|
|
validate_config
|
|
)
|
|
|
|
ACTION_SCHEMA = automation.maybe_simple_id({
|
|
cv.GenerateID(): cv.use_id(HoermannDoor)
|
|
})
|
|
|
|
@automation.register_action("hoermann_door.stop_polling", StopPolling, ACTION_SCHEMA)
|
|
async def stop_polling(config, action_id, template_arg, args):
|
|
parent = await cg.get_variable(config[CONF_ID])
|
|
return cg.new_Pvariable(action_id, template_arg, parent)
|
|
|
|
@automation.register_action("hoermann_door.start_polling", StartPolling, ACTION_SCHEMA)
|
|
async def start_polling(config, action_id, template_arg, args):
|
|
parent = await cg.get_variable(config[CONF_ID])
|
|
return cg.new_Pvariable(action_id, template_arg, parent)
|
|
|
|
async def to_code(config):
|
|
var = cg.new_Pvariable(config[CONF_ID])
|
|
await cg.register_component(var, config)
|
|
|
|
code = await cg.get_variable(config[CONF_UART_ENTRY])
|
|
cg.add(var.set_seriel_connection(code))
|
|
|
|
code2 = await cg.gpio_pin_expression(config[CONF_TX_PIN])
|
|
cg.add(var.set_tx_on_pin(code2))
|
|
|
|
log_level = config[CONF_LOG_LEVEL]
|
|
cg.add(var.set_log_level(log_level)) |