[hlw8012] Use the sub_* helpers for optional child entities (#19792)

This commit is contained in:
J. Nick Koston
2026-09-28 01:13:13 +02:00
committed by GitHub
parent f3e7603a2f
commit 9b7f9b694e
+5 -12
View File
@@ -107,18 +107,11 @@ async def to_code(config: ConfigType) -> None:
cf1 = await cg.gpio_pin_expression(config[CONF_CF1_PIN])
cg.add(var.set_cf1_pin(cf1))
if CONF_VOLTAGE in config:
sens = await sensor.new_sensor(config[CONF_VOLTAGE])
cg.add(var.set_voltage_sensor(sens))
if CONF_CURRENT in config:
sens = await sensor.new_sensor(config[CONF_CURRENT])
cg.add(var.set_current_sensor(sens))
if CONF_POWER in config:
sens = await sensor.new_sensor(config[CONF_POWER])
cg.add(var.set_power_sensor(sens))
if CONF_ENERGY in config:
sens = await sensor.new_sensor(config[CONF_ENERGY])
cg.add(var.set_energy_sensor(sens))
sensors = sensor.sub_sensors(config)
await sensors(CONF_VOLTAGE, var.set_voltage_sensor)
await sensors(CONF_CURRENT, var.set_current_sensor)
await sensors(CONF_POWER, var.set_power_sensor)
await sensors(CONF_ENERGY, var.set_energy_sensor)
cg.add(var.set_current_resistor(config[CONF_CURRENT_RESISTOR]))
cg.add(var.set_voltage_divider(config[CONF_VOLTAGE_DIVIDER]))
cg.add(var.set_initial_mode(INITIAL_MODES[config[CONF_INITIAL_MODE]]))