mirror of
https://github.com/esphome/esphome.git
synced 2026-10-07 11:26:39 +00:00
[iaqcore][t6615][hc8][as3935][tx20] Use the sub_* helpers for optional child entities (#20048)
This commit is contained in:
@@ -35,10 +35,6 @@ CONFIG_SCHEMA = cv.Schema(
|
||||
async def to_code(config: ConfigType) -> None:
|
||||
hub = await cg.get_variable(config[CONF_AS3935_ID])
|
||||
|
||||
if distance_config := config.get(CONF_DISTANCE):
|
||||
sens = await sensor.new_sensor(distance_config)
|
||||
cg.add(hub.set_distance_sensor(sens))
|
||||
|
||||
if lightning_energy_config := config.get(CONF_LIGHTNING_ENERGY):
|
||||
sens = await sensor.new_sensor(lightning_energy_config)
|
||||
cg.add(hub.set_energy_sensor(sens))
|
||||
sensors = sensor.sub_sensors(config)
|
||||
await sensors(CONF_DISTANCE, hub.set_distance_sensor)
|
||||
await sensors(CONF_LIGHTNING_ENERGY, hub.set_energy_sensor)
|
||||
|
||||
@@ -55,9 +55,8 @@ async def to_code(config: ConfigType) -> None:
|
||||
await cg.register_component(var, config)
|
||||
await uart.register_uart_device(var, config)
|
||||
|
||||
if co2 := config.get(CONF_CO2):
|
||||
sens = await sensor.new_sensor(co2)
|
||||
cg.add(var.set_co2_sensor(sens))
|
||||
sensors = sensor.sub_sensors(config)
|
||||
await sensors(CONF_CO2, var.set_co2_sensor)
|
||||
|
||||
cg.add(var.set_warmup_seconds(config[CONF_WARMUP_TIME]))
|
||||
|
||||
|
||||
@@ -47,12 +47,8 @@ async def to_code(config: ConfigType) -> None:
|
||||
var = cg.new_Pvariable(config[CONF_ID])
|
||||
await cg.register_component(var, config)
|
||||
|
||||
if co2_config := config.get(CONF_CO2):
|
||||
sens = await sensor.new_sensor(co2_config)
|
||||
cg.add(var.set_co2(sens))
|
||||
|
||||
if tvoc_config := config.get(CONF_TVOC):
|
||||
sens = await sensor.new_sensor(tvoc_config)
|
||||
cg.add(var.set_tvoc(sens))
|
||||
sensors = sensor.sub_sensors(config)
|
||||
await sensors(CONF_CO2, var.set_co2)
|
||||
await sensors(CONF_TVOC, var.set_tvoc)
|
||||
|
||||
await i2c.register_i2c_device(var, config)
|
||||
|
||||
@@ -48,6 +48,5 @@ async def to_code(config: ConfigType) -> None:
|
||||
await cg.register_component(var, config)
|
||||
await uart.register_uart_device(var, config)
|
||||
|
||||
if co2 := config.get(CONF_CO2):
|
||||
sens = await sensor.new_sensor(co2)
|
||||
cg.add(var.set_co2_sensor(sens))
|
||||
sensors = sensor.sub_sensors(config)
|
||||
await sensors(CONF_CO2, var.set_co2_sensor)
|
||||
|
||||
@@ -44,15 +44,9 @@ async def to_code(config: ConfigType) -> None:
|
||||
var = cg.new_Pvariable(config[CONF_ID])
|
||||
await cg.register_component(var, config)
|
||||
|
||||
if CONF_WIND_SPEED in config:
|
||||
conf = config[CONF_WIND_SPEED]
|
||||
sens = await sensor.new_sensor(conf)
|
||||
cg.add(var.set_wind_speed_sensor(sens))
|
||||
|
||||
if CONF_WIND_DIRECTION_DEGREES in config:
|
||||
conf = config[CONF_WIND_DIRECTION_DEGREES]
|
||||
sens = await sensor.new_sensor(conf)
|
||||
cg.add(var.set_wind_direction_degrees_sensor(sens))
|
||||
sensors = sensor.sub_sensors(config)
|
||||
await sensors(CONF_WIND_SPEED, var.set_wind_speed_sensor)
|
||||
await sensors(CONF_WIND_DIRECTION_DEGREES, var.set_wind_direction_degrees_sensor)
|
||||
|
||||
pin = await cg.gpio_pin_expression(config[CONF_PIN])
|
||||
cg.add(var.set_pin(pin))
|
||||
|
||||
Reference in New Issue
Block a user