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

33 lines
820 B
Python

import esphome.codegen as cg
import esphome.config_validation as cv
from esphome.const import CONF_ID
from esphome.components import binary_sensor
from .. import (
ratgdo_ns,
register_ratgdo_child,
)
DEPENDENCIES = ["ratgdo"]
RATGDOBinarySensor = ratgdo_ns.class_(
"RATGDOBinarySensor", binary_sensor.BinarySensor, cg.Component
)
CONF_TYPE = "type"
TYPES = {"motion", "obstruction"}
CONFIG_SCHEMA = binary_sensor.BINARY_SENSOR_SCHEMA.extend(
{
cv.GenerateID(): cv.declare_id(RATGDOBinarySensor),
cv.Required(CONF_TYPE): str
}
).extend(cv.COMPONENT_SCHEMA)
async def to_code(config):
var = cg.new_Pvariable(config[CONF_ID])
await cg.register_component(var, config)
await binary_sensor.register_binary_sensor(var, config)
await register_ratgdo_child(var, config)