[mmc5983] Use the sub_* helpers for optional child entities (#20007)

This commit is contained in:
J. Nick Koston
2026-10-02 09:07:39 -05:00
committed by GitHub
parent 7b018b9dca
commit 54cb4c711a
+4 -9
View File
@@ -45,12 +45,7 @@ async def to_code(config: ConfigType) -> None:
await cg.register_component(var, config)
await i2c.register_i2c_device(var, config)
if x_config := config.get(CONF_FIELD_STRENGTH_X):
sens = await sensor.new_sensor(x_config)
cg.add(var.set_x_sensor(sens))
if y_config := config.get(CONF_FIELD_STRENGTH_Y):
sens = await sensor.new_sensor(y_config)
cg.add(var.set_y_sensor(sens))
if z_config := config.get(CONF_FIELD_STRENGTH_Z):
sens = await sensor.new_sensor(z_config)
cg.add(var.set_z_sensor(sens))
sensors = sensor.sub_sensors(config)
await sensors(CONF_FIELD_STRENGTH_X, var.set_x_sensor)
await sensors(CONF_FIELD_STRENGTH_Y, var.set_y_sensor)
await sensors(CONF_FIELD_STRENGTH_Z, var.set_z_sensor)