esphome-ratgdo/components/ratgdo/button/__init__.py

35 lines
883 B
Python
Raw Normal View History

2023-06-07 23:44:58 +00:00
import esphome.codegen as cg
import esphome.config_validation as cv
from esphome.const import CONF_ID
from esphome.components import button
2023-06-07 23:49:13 +00:00
from .. import ratgdo_ns, register_ratgdo_child, RATGDO_CLIENT_SCHMEA
2023-06-07 23:44:58 +00:00
DEPENDENCIES = ["ratgdo"]
2023-06-07 23:49:13 +00:00
RATGDOButton = ratgdo_ns.class_("RATGDOButton", button.Button, cg.Component)
2023-06-07 23:44:58 +00:00
ButtonType = ratgdo_ns.enum("ButtonType")
CONF_TYPE = "type"
TYPES = {
"sync": ButtonType.RATGDO_SYNC,
}
2023-06-07 23:49:13 +00:00
CONFIG_SCHEMA = (
button.button_schema(RATGDOButton)
.extend(
{
cv.Required(CONF_TYPE): cv.enum(TYPES, lower=True),
}
)
.extend(RATGDO_CLIENT_SCHMEA)
)
2023-06-07 23:44:58 +00:00
async def to_code(config):
var = cg.new_Pvariable(config[CONF_ID])
await button.register_button(var, config)
await cg.register_component(var, config)
cg.add(var.set_button_type(config[CONF_TYPE]))
await register_ratgdo_child(var, config)