Compare commits

...
Author SHA1 Message Date
J. Nick Koston 47f1da0a8d [components] Use options() and sub_text_sensors in recently added components
Build the dfrobot_sen0465 alarm types and mics_5524 conversion models with
options(), and register the systa_bus error code text sensor with
sub_text_sensors. The generated C++ is unchanged.
2026-10-17 17:32:55 -10:00
3 changed files with 7 additions and 11 deletions
@@ -34,10 +34,7 @@ DFRobotSEN0465Component = dfrobot_sen0465_base_ns.class_(
"DFRobotSEN0465Component", cg.PollingComponent
)
AlarmType = dfrobot_sen0465_base_ns.enum("AlarmType", is_class=True)
ALARM_TYPES = {
"LOW": AlarmType.ALARM_TYPE_LOW,
"HIGH": AlarmType.ALARM_TYPE_HIGH,
}
ALARM_TYPES = AlarmType.options("LOW", "HIGH", prefix="ALARM_TYPE_")
# One piece of the temperature compensation from the DFRobot_MultiGasSensor library:
# for low < T <= high, compensated = raw / (a * T + b) - (c * T + d)
+3 -4
View File
@@ -43,10 +43,9 @@ CONF_RATIO_SENSOR = "ratio_sensor"
CONF_RS_SENSOR = "rs_sensor"
CONF_VOLTAGE_SENSOR = "voltage_sensor"
CONVERSION_MODELS = {
"dfrobot": ConversionModel.CONVERSION_MODEL_DFROBOT,
"datasheet": ConversionModel.CONVERSION_MODEL_DATASHEET,
}
CONVERSION_MODELS = ConversionModel.options(
"dfrobot", "datasheet", prefix="CONVERSION_MODEL_"
)
# Divider guard limits (input max, pin max) in volts by target platform. ESP32 and RP2: VDD and
# the absolute maximum VDD + 0.3 V; a bare ESP8266 A0 measures 0 - 1 V, boards with an onboard
@@ -37,9 +37,9 @@ async def to_code(config: ConfigType) -> None:
var = cg.new_Pvariable(config[CONF_ID])
await cg.register_component(var, config)
if config[CONF_MODEL] == CONF_SYSTASOLAR_AQUA and CONF_ERROR_CODE in config:
sens = await text_sensor.new_text_sensor(config[CONF_ERROR_CODE])
cg.add(var.set_error_code_text_sensor(sens))
# The schema only lets a model's own keys through, so unconfigured ones are skipped here
text_sensors = text_sensor.sub_text_sensors(config)
await text_sensors(CONF_ERROR_CODE, var.set_error_code_text_sensor)
systa_bus = await cg.get_variable(config[CONF_SYSTA_BUS_ID])
await register_systa_bus_listener(systa_bus, var)