[xiaomi_gcls002] Use the sub_* helpers for optional child entities (#19973)

This commit is contained in:
J. Nick Koston
2026-10-01 12:37:55 -04:00
committed by GitHub
parent b4cb164e5d
commit 879c5cfc5b
+5 -12
View File
@@ -71,15 +71,8 @@ async def to_code(config: ConfigType) -> None:
cg.add(var.set_address(config[CONF_MAC_ADDRESS].as_hex))
if CONF_TEMPERATURE in config:
sens = await sensor.new_sensor(config[CONF_TEMPERATURE])
cg.add(var.set_temperature(sens))
if CONF_MOISTURE in config:
sens = await sensor.new_sensor(config[CONF_MOISTURE])
cg.add(var.set_moisture(sens))
if CONF_ILLUMINANCE in config:
sens = await sensor.new_sensor(config[CONF_ILLUMINANCE])
cg.add(var.set_illuminance(sens))
if CONF_CONDUCTIVITY in config:
sens = await sensor.new_sensor(config[CONF_CONDUCTIVITY])
cg.add(var.set_conductivity(sens))
sensors = sensor.sub_sensors(config)
await sensors(CONF_TEMPERATURE, var.set_temperature)
await sensors(CONF_MOISTURE, var.set_moisture)
await sensors(CONF_ILLUMINANCE, var.set_illuminance)
await sensors(CONF_CONDUCTIVITY, var.set_conductivity)