2023-06-07 15:37:51 +00:00
|
|
|
import esphome.codegen as cg
|
|
|
|
import esphome.config_validation as cv
|
|
|
|
from esphome.components import binary_sensor
|
2023-06-09 20:54:28 +00:00
|
|
|
from esphome.const import CONF_ID
|
|
|
|
|
|
|
|
from .. import RATGDO_CLIENT_SCHMEA, ratgdo_ns, register_ratgdo_child
|
2023-06-07 15:37:51 +00:00
|
|
|
|
|
|
|
DEPENDENCIES = ["ratgdo"]
|
|
|
|
|
|
|
|
RATGDOBinarySensor = ratgdo_ns.class_(
|
|
|
|
"RATGDOBinarySensor", binary_sensor.BinarySensor, cg.Component
|
|
|
|
)
|
2023-06-07 16:37:34 +00:00
|
|
|
SensorType = ratgdo_ns.enum("SensorType")
|
2023-06-07 15:37:51 +00:00
|
|
|
|
2023-06-07 16:06:05 +00:00
|
|
|
CONF_TYPE = "type"
|
2023-06-07 16:37:34 +00:00
|
|
|
TYPES = {
|
|
|
|
"motion": SensorType.RATGDO_SENSOR_MOTION,
|
|
|
|
"obstruction": SensorType.RATGDO_SENSOR_OBSTRUCTION,
|
2023-06-08 02:40:30 +00:00
|
|
|
"motor": SensorType.RATGDO_SENSOR_MOTOR,
|
2023-06-09 23:04:29 +00:00
|
|
|
"button": SensorType.RATGDO_SENSOR_BUTTON,
|
2023-06-07 16:37:34 +00:00
|
|
|
}
|
2023-06-07 15:37:51 +00:00
|
|
|
|
|
|
|
|
2023-06-07 23:49:13 +00:00
|
|
|
CONFIG_SCHEMA = (
|
|
|
|
binary_sensor.binary_sensor_schema(RATGDOBinarySensor)
|
|
|
|
.extend(
|
|
|
|
{
|
|
|
|
cv.Required(CONF_TYPE): cv.enum(TYPES, lower=True),
|
|
|
|
}
|
|
|
|
)
|
|
|
|
.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 19:48:20 +00:00
|
|
|
cg.add(var.set_binary_sensor_type(config[CONF_TYPE]))
|
2023-06-07 16:37:34 +00:00
|
|
|
await register_ratgdo_child(var, config)
|