2023-06-05 17:27:06 +00:00
|
|
|
import esphome.codegen as cg
|
|
|
|
import esphome.config_validation as cv
|
2023-06-07 23:48:59 +00:00
|
|
|
from esphome import pins
|
2023-06-09 20:54:28 +00:00
|
|
|
from esphome.const import CONF_ID
|
2023-06-05 17:27:06 +00:00
|
|
|
|
2023-06-17 14:50:38 +00:00
|
|
|
DEPENDENCIES = ["preferences"]
|
2023-06-07 15:39:44 +00:00
|
|
|
MULTI_CONF = True
|
2023-06-05 17:27:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
ratgdo_ns = cg.esphome_ns.namespace("ratgdo")
|
2023-06-17 14:50:38 +00:00
|
|
|
RATGDO = ratgdo_ns.class_("RATGDOComponent", cg.Component)
|
2023-06-05 17:27:06 +00:00
|
|
|
|
2023-06-05 19:39:46 +00:00
|
|
|
|
|
|
|
CONF_OUTPUT_GDO = "output_gdo_pin"
|
2023-06-07 15:37:51 +00:00
|
|
|
DEFAULT_OUTPUT_GDO = (
|
2023-06-09 16:08:16 +00:00
|
|
|
"D4" # D4 red control terminal / GarageDoorOpener (UART1 TX) pin is D4 on D1 Mini
|
2023-06-07 15:37:51 +00:00
|
|
|
)
|
2023-06-05 23:19:52 +00:00
|
|
|
CONF_INPUT_GDO = "input_gdo_pin"
|
2023-06-09 20:54:28 +00:00
|
|
|
DEFAULT_INPUT_GDO = (
|
|
|
|
"D2" # D2 red control terminal / GarageDoorOpener (UART1 RX) pin is D2 on D1 Mini
|
|
|
|
)
|
2023-06-05 23:19:52 +00:00
|
|
|
CONF_INPUT_OBST = "input_obst_pin"
|
2023-06-09 16:08:16 +00:00
|
|
|
DEFAULT_INPUT_OBST = "D7" # D7 black obstruction sensor terminal
|
2023-06-05 23:19:52 +00:00
|
|
|
|
2023-06-07 16:08:13 +00:00
|
|
|
CONF_RATGDO_ID = "ratgdo_id"
|
2023-06-07 15:37:51 +00:00
|
|
|
|
2023-06-17 14:50:38 +00:00
|
|
|
CONFIG_SCHEMA = cv.Schema(
|
|
|
|
{
|
|
|
|
cv.GenerateID(): cv.declare_id(RATGDO),
|
|
|
|
cv.Optional(
|
|
|
|
CONF_OUTPUT_GDO, default=DEFAULT_OUTPUT_GDO
|
|
|
|
): pins.gpio_output_pin_schema,
|
|
|
|
cv.Optional(
|
|
|
|
CONF_INPUT_GDO, default=DEFAULT_INPUT_GDO
|
|
|
|
): pins.gpio_input_pin_schema,
|
|
|
|
cv.Optional(
|
|
|
|
CONF_INPUT_OBST, default=DEFAULT_INPUT_OBST
|
|
|
|
): pins.gpio_input_pin_schema,
|
|
|
|
}
|
|
|
|
).extend(cv.COMPONENT_SCHEMA)
|
2023-06-05 23:54:37 +00:00
|
|
|
|
2023-06-07 16:08:13 +00:00
|
|
|
RATGDO_CLIENT_SCHMEA = cv.Schema(
|
|
|
|
{
|
|
|
|
cv.Required(CONF_RATGDO_ID): cv.use_id(RATGDO),
|
|
|
|
}
|
|
|
|
)
|
2023-06-05 23:54:37 +00:00
|
|
|
|
2023-06-07 23:49:13 +00:00
|
|
|
|
2023-06-07 15:37:51 +00:00
|
|
|
async def register_ratgdo_child(var, config):
|
2023-06-07 16:08:13 +00:00
|
|
|
parent = await cg.get_variable(config[CONF_RATGDO_ID])
|
2023-06-07 15:37:51 +00:00
|
|
|
cg.add(parent.register_child(var))
|
2023-06-05 17:27:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
async def to_code(config):
|
|
|
|
var = cg.new_Pvariable(config[CONF_ID])
|
|
|
|
await cg.register_component(var, config)
|
2023-06-05 19:39:46 +00:00
|
|
|
pin = await cg.gpio_pin_expression(config[CONF_OUTPUT_GDO])
|
|
|
|
cg.add(var.set_output_gdo_pin(pin))
|
2023-06-05 23:19:52 +00:00
|
|
|
pin = await cg.gpio_pin_expression(config[CONF_INPUT_GDO])
|
2023-06-07 15:37:51 +00:00
|
|
|
cg.add(var.set_input_gdo_pin(pin))
|
2023-06-05 23:19:52 +00:00
|
|
|
pin = await cg.gpio_pin_expression(config[CONF_INPUT_OBST])
|
|
|
|
cg.add(var.set_input_obst_pin(pin))
|
|
|
|
|
2023-06-05 17:50:25 +00:00
|
|
|
cg.add_library(
|
|
|
|
name="secplus",
|
2023-06-09 20:45:04 +00:00
|
|
|
repository="https://github.com/esphome-ratgdo/secplus",
|
2023-06-05 17:50:25 +00:00
|
|
|
version="f98c3220356c27717a25102c0b35815ebbd26ccc",
|
2023-06-05 17:52:42 +00:00
|
|
|
)
|
2023-06-17 14:50:38 +00:00
|
|
|
cg.add_library(
|
|
|
|
name="espsoftwareserial",
|
|
|
|
repository="https://github.com/esphome-ratgdo/espsoftwareserial",
|
|
|
|
version="2f408224633316b997f82339e5b2731b1e561060",
|
|
|
|
)
|