[mcp9600][tem3200][kmeteriso][ufire_ec][ufire_ise] Use the sub_* helpers for optional child entities (#20045)

This commit is contained in:
J. Nick Koston
2026-10-02 14:30:01 -04:00
committed by GitHub
parent 690227f6d8
commit b15bc083f6
5 changed files with 15 additions and 36 deletions
+3 -6
View File
@@ -48,9 +48,6 @@ async def to_code(config: ConfigType) -> None:
await cg.register_component(var, config)
await i2c.register_i2c_device(var, config)
if temperature_config := config.get(CONF_TEMPERATURE):
sens = await sensor.new_sensor(temperature_config)
cg.add(var.set_temperature_sensor(sens))
if internal_temperature_config := config.get(CONF_INTERNAL_TEMPERATURE):
sens = await sensor.new_sensor(internal_temperature_config)
cg.add(var.set_internal_temperature_sensor(sens))
sensors = sensor.sub_sensors(config)
await sensors(CONF_TEMPERATURE, var.set_temperature_sensor)
await sensors(CONF_INTERNAL_TEMPERATURE, var.set_internal_temperature_sensor)
+3 -9
View File
@@ -71,12 +71,6 @@ async def to_code(config: ConfigType) -> None:
cg.add(var.set_thermocouple_type(config[CONF_THERMOCOUPLE_TYPE]))
if CONF_HOT_JUNCTION in config:
conf = config[CONF_HOT_JUNCTION]
sens = await sensor.new_sensor(conf)
cg.add(var.set_hot_junction(sens))
if CONF_COLD_JUNCTION in config:
conf = config[CONF_COLD_JUNCTION]
sens = await sensor.new_sensor(conf)
cg.add(var.set_cold_junction(sens))
sensors = sensor.sub_sensors(config)
await sensors(CONF_HOT_JUNCTION, var.set_hot_junction)
await sensors(CONF_COLD_JUNCTION, var.set_cold_junction)
+3 -7
View File
@@ -46,10 +46,6 @@ async def to_code(config: ConfigType) -> None:
await cg.register_component(var, config)
await i2c.register_i2c_device(var, config)
if temperature_config := config.get(CONF_TEMPERATURE):
sens = await sensor.new_sensor(temperature_config)
cg.add(var.set_temperature_sensor(sens))
if raw_pressure_config := config.get(CONF_RAW_PRESSURE):
sens = await sensor.new_sensor(raw_pressure_config)
cg.add(var.set_raw_pressure_sensor(sens))
sensors = sensor.sub_sensors(config)
await sensors(CONF_TEMPERATURE, var.set_temperature_sensor)
await sensors(CONF_RAW_PRESSURE, var.set_raw_pressure_sensor)
+3 -7
View File
@@ -64,13 +64,9 @@ async def to_code(config: ConfigType) -> None:
cg.add(var.set_temperature_compensation(config[CONF_TEMPERATURE_COMPENSATION]))
cg.add(var.set_temperature_coefficient(config[CONF_TEMPERATURE_COEFFICIENT]))
if CONF_TEMPERATURE in config:
sens = await sensor.new_sensor(config[CONF_TEMPERATURE])
cg.add(var.set_temperature_sensor(sens))
if CONF_EC in config:
sens = await sensor.new_sensor(config[CONF_EC])
cg.add(var.set_ec_sensor(sens))
sensors = sensor.sub_sensors(config)
await sensors(CONF_TEMPERATURE, var.set_temperature_sensor)
await sensors(CONF_EC, var.set_ec_sensor)
if CONF_TEMPERATURE_SENSOR in config:
sens = await cg.get_variable(config[CONF_TEMPERATURE_SENSOR])
+3 -7
View File
@@ -56,13 +56,9 @@ async def to_code(config: ConfigType) -> None:
var = cg.new_Pvariable(config[CONF_ID])
await cg.register_component(var, config)
if CONF_TEMPERATURE in config:
sens = await sensor.new_sensor(config[CONF_TEMPERATURE])
cg.add(var.set_temperature_sensor(sens))
if CONF_PH in config:
sens = await sensor.new_sensor(config[CONF_PH])
cg.add(var.set_ph_sensor(sens))
sensors = sensor.sub_sensors(config)
await sensors(CONF_TEMPERATURE, var.set_temperature_sensor)
await sensors(CONF_PH, var.set_ph_sensor)
if CONF_TEMPERATURE_SENSOR in config:
sens = await cg.get_variable(config[CONF_TEMPERATURE_SENSOR])