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

36 lines
917 B
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,
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)