[pzemac] Use the sub_* helpers for optional child entities (#19808)

This commit is contained in:
J. Nick Koston
2026-09-27 20:52:00 -04:00
committed by GitHub
parent b8fc2f2d43
commit 8be570f369
+7 -24
View File
@@ -103,27 +103,10 @@ async def to_code(config: ConfigType) -> None:
await cg.register_component(var, config)
await modbus.register_modbus_client_device(var, config)
if CONF_VOLTAGE in config:
conf = config[CONF_VOLTAGE]
sens = await sensor.new_sensor(conf)
cg.add(var.set_voltage_sensor(sens))
if CONF_CURRENT in config:
conf = config[CONF_CURRENT]
sens = await sensor.new_sensor(conf)
cg.add(var.set_current_sensor(sens))
if CONF_POWER in config:
conf = config[CONF_POWER]
sens = await sensor.new_sensor(conf)
cg.add(var.set_power_sensor(sens))
if CONF_ENERGY in config:
conf = config[CONF_ENERGY]
sens = await sensor.new_sensor(conf)
cg.add(var.set_energy_sensor(sens))
if CONF_FREQUENCY in config:
conf = config[CONF_FREQUENCY]
sens = await sensor.new_sensor(conf)
cg.add(var.set_frequency_sensor(sens))
if CONF_POWER_FACTOR in config:
conf = config[CONF_POWER_FACTOR]
sens = await sensor.new_sensor(conf)
cg.add(var.set_power_factor_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)
await sensors(CONF_FREQUENCY, var.set_frequency_sensor)
await sensors(CONF_POWER_FACTOR, var.set_power_factor_sensor)