2023-06-07 15:37:51 +00:00
|
|
|
import esphome.codegen as cg
|
|
|
|
import esphome.config_validation as cv
|
2023-06-07 16:04:56 +00:00
|
|
|
from esphome.const import CONF_ID
|
2023-06-07 15:37:51 +00:00
|
|
|
from esphome.components import binary_sensor
|
|
|
|
from .. import (
|
|
|
|
ratgdo_ns,
|
|
|
|
register_ratgdo_child,
|
2023-06-07 16:08:51 +00:00
|
|
|
RATGDO_CLIENT_SCHMEA
|
2023-06-07 15:37:51 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
DEPENDENCIES = ["ratgdo"]
|
|
|
|
|
|
|
|
RATGDOBinarySensor = ratgdo_ns.class_(
|
|
|
|
"RATGDOBinarySensor", binary_sensor.BinarySensor, cg.Component
|
|
|
|
)
|
|
|
|
|
2023-06-07 16:06:05 +00:00
|
|
|
CONF_TYPE = "type"
|
2023-06-07 15:37:51 +00:00
|
|
|
TYPES = {"motion", "obstruction"}
|
|
|
|
|
|
|
|
|
2023-06-07 16:20:14 +00:00
|
|
|
CONFIG_SCHEMA = binary_sensor.binary_sensor_schema(RATGDOBinarySensor).extend(
|
2023-06-07 16:05:43 +00:00
|
|
|
{
|
|
|
|
cv.Required(CONF_TYPE): str
|
|
|
|
}
|
2023-06-07 16:08:51 +00:00
|
|
|
).extend(RATGDO_CLIENT_SCHMEA)
|
2023-06-07 15:37:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
async def to_code(config):
|
2023-06-07 16:04:56 +00:00
|
|
|
var = cg.new_Pvariable(config[CONF_ID])
|
|
|
|
await binary_sensor.register_binary_sensor(var, config)
|
2023-06-07 16:20:14 +00:00
|
|
|
await cg.register_component(var, config)
|
2023-06-07 16:00:08 +00:00
|
|
|
await register_ratgdo_child(var, config)
|
2023-06-07 16:31:02 +00:00
|
|
|
cg.add(var.set_type(var, config[CONF_TYPE]))
|