[xiaomi_hhccjcy10] Use the sub_* helpers for optional child entities (#19919)

This commit is contained in:
J. Nick Koston
2026-09-29 21:32:02 -04:00
committed by GitHub
parent 203a7f70a3
commit 83d689d944
+6 -15
View File
@@ -81,18 +81,9 @@ async def to_code(config: ConfigType) -> None:
cg.add(var.set_address(config[CONF_MAC_ADDRESS].as_hex))
if temperature_config := config.get(CONF_TEMPERATURE):
sens = await sensor.new_sensor(temperature_config)
cg.add(var.set_temperature(sens))
if moisture_config := config.get(CONF_MOISTURE):
sens = await sensor.new_sensor(moisture_config)
cg.add(var.set_moisture(sens))
if illuminance_config := config.get(CONF_ILLUMINANCE):
sens = await sensor.new_sensor(illuminance_config)
cg.add(var.set_illuminance(sens))
if conductivity_config := config.get(CONF_CONDUCTIVITY):
sens = await sensor.new_sensor(conductivity_config)
cg.add(var.set_conductivity(sens))
if battery_level_config := config.get(CONF_BATTERY_LEVEL):
sens = await sensor.new_sensor(battery_level_config)
cg.add(var.set_battery_level(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)
await sensors(CONF_BATTERY_LEVEL, var.set_battery_level)