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

41 lines
1.3 KiB
Python
Raw Normal View History

2023-06-09 22:36:56 +00:00
import esphome.codegen as cg
import esphome.config_validation as cv
from esphome.components import sensor
from esphome.const import CONF_ID
from .. import RATGDO_CLIENT_SCHMEA, ratgdo_ns, register_ratgdo_child
DEPENDENCIES = ["ratgdo"]
RATGDOSensor = ratgdo_ns.class_("RATGDOSensor", sensor.Sensor, cg.Component)
2023-06-09 22:38:30 +00:00
RATGDOSensorType = ratgdo_ns.enum("RATGDOSensorType")
2023-06-09 22:36:56 +00:00
CONF_TYPE = "type"
TYPES = {
2023-06-09 22:38:30 +00:00
"openings": RATGDOSensorType.RATGDO_OPENINGS,
"paired_devices_total": RATGDOSensorType.RATGDO_PAIRED_DEVICES_TOTAL,
"paired_devices_remotes": RATGDOSensorType.RATGDO_PAIRED_REMOTES,
"paired_devices_keypads": RATGDOSensorType.RATGDO_PAIRED_KEYPADS,
"paired_devices_wall_controls": RATGDOSensorType.RATGDO_PAIRED_WALL_CONTROLS,
"paired_devices_accessories": RATGDOSensorType.RATGDO_PAIRED_ACCESSORIES,
2023-06-09 22:36:56 +00:00
}
CONFIG_SCHEMA = (
sensor.sensor_schema(RATGDOSensor)
.extend(
{
cv.Required(CONF_TYPE): cv.enum(TYPES, lower=True),
}
)
.extend(RATGDO_CLIENT_SCHMEA)
)
async def to_code(config):
var = cg.new_Pvariable(config[CONF_ID])
await sensor.register_sensor(var, config)
await cg.register_component(var, config)
2023-06-09 22:40:08 +00:00
cg.add(var.set_ratgdo_sensor_type(config[CONF_TYPE]))
2023-06-09 22:36:56 +00:00
await register_ratgdo_child(var, config)