diff --git a/esphome/components/absolute_humidity/sensor.py b/esphome/components/absolute_humidity/sensor.py index f11ba5af990..10ad57a8828 100644 --- a/esphome/components/absolute_humidity/sensor.py +++ b/esphome/components/absolute_humidity/sensor.py @@ -44,10 +44,7 @@ async def to_code(config: ConfigType) -> None: var = await sensor.new_sensor(config) await cg.register_component(var, config) - temperature_sensor = await cg.get_variable(config[CONF_TEMPERATURE]) - cg.add(var.set_temperature_sensor(temperature_sensor)) - - humidity_sensor = await cg.get_variable(config[CONF_HUMIDITY]) - cg.add(var.set_humidity_sensor(humidity_sensor)) + await cg.add_variable(var.set_temperature_sensor, config[CONF_TEMPERATURE]) + await cg.add_variable(var.set_humidity_sensor, config[CONF_HUMIDITY]) cg.add(var.set_equation(config[CONF_EQUATION])) diff --git a/esphome/components/analog_threshold/binary_sensor.py b/esphome/components/analog_threshold/binary_sensor.py index b2de1d6184c..f21efb09055 100644 --- a/esphome/components/analog_threshold/binary_sensor.py +++ b/esphome/components/analog_threshold/binary_sensor.py @@ -37,8 +37,7 @@ async def to_code(config: ConfigType) -> None: var = await binary_sensor.new_binary_sensor(config) await cg.register_component(var, config) - sens = await cg.get_variable(config[CONF_SENSOR_ID]) - cg.add(var.set_sensor(sens)) + await cg.add_variable(var.set_sensor, config[CONF_SENSOR_ID]) if isinstance(config[CONF_THRESHOLD], dict): lower = await cg.templatable(config[CONF_THRESHOLD][CONF_LOWER], [], cg.float_) diff --git a/esphome/components/aqi/sensor.py b/esphome/components/aqi/sensor.py index a98d977227c..6e0a3e74963 100644 --- a/esphome/components/aqi/sensor.py +++ b/esphome/components/aqi/sensor.py @@ -53,11 +53,8 @@ async def to_code(config: ConfigType) -> None: var = await sensor.new_sensor(config) await cg.register_component(var, config) - pm_2_5_sensor = await cg.get_variable(config[CONF_PM_2_5]) - cg.add(var.set_pm_2_5_sensor(pm_2_5_sensor)) - - pm_10_0_sensor = await cg.get_variable(config[CONF_PM_10_0]) - cg.add(var.set_pm_10_0_sensor(pm_10_0_sensor)) + await cg.add_variable(var.set_pm_2_5_sensor, config[CONF_PM_2_5]) + await cg.add_variable(var.set_pm_10_0_sensor, config[CONF_PM_10_0]) cg.add(var.set_aqi_calculation_type(config[CONF_CALCULATION_TYPE])) cg.add(var.set_extended_range(config.get(CONF_EXTENDED_RANGE, False))) diff --git a/esphome/components/bang_bang/climate.py b/esphome/components/bang_bang/climate.py index 65c5eaed187..e09b187ae3d 100644 --- a/esphome/components/bang_bang/climate.py +++ b/esphome/components/bang_bang/climate.py @@ -46,12 +46,8 @@ async def to_code(config: ConfigType) -> None: var = await climate.new_climate(config) await cg.register_component(var, config) - sens = await cg.get_variable(config[CONF_SENSOR]) - cg.add(var.set_sensor(sens)) - - if CONF_HUMIDITY_SENSOR in config: - sens = await cg.get_variable(config[CONF_HUMIDITY_SENSOR]) - cg.add(var.set_humidity_sensor(sens)) + await cg.add_variable(var.set_sensor, config[CONF_SENSOR]) + await cg.add_variable(var.set_humidity_sensor, config.get(CONF_HUMIDITY_SENSOR)) normal_config = BangBangClimateTargetTempConfig( config[CONF_DEFAULT_TARGET_TEMPERATURE_LOW], diff --git a/esphome/components/bedjet/__init__.py b/esphome/components/bedjet/__init__.py index 61dc73c73d5..406955084ea 100644 --- a/esphome/components/bedjet/__init__.py +++ b/esphome/components/bedjet/__init__.py @@ -44,8 +44,6 @@ async def to_code(config: ConfigType) -> None: var = cg.new_Pvariable(config[CONF_ID]) await cg.register_component(var, config) await ble_client.register_ble_node(var, config) - if time_id := config.get(CONF_TIME_ID): - time_ = await cg.get_variable(time_id) - cg.add(var.set_time_id(time_)) + await cg.add_variable(var.set_time_id, config.get(CONF_TIME_ID)) if (receive_timeout := config.get(CONF_RECEIVE_TIMEOUT)) is not None: cg.add(var.set_status_timeout(receive_timeout)) diff --git a/esphome/components/binary/fan/__init__.py b/esphome/components/binary/fan/__init__.py index 03a03ec7cac..a97920b408a 100644 --- a/esphome/components/binary/fan/__init__.py +++ b/esphome/components/binary/fan/__init__.py @@ -25,13 +25,6 @@ async def to_code(config: ConfigType) -> None: var = await fan.new_fan(config) await cg.register_component(var, config) - output_ = await cg.get_variable(config[CONF_OUTPUT]) - cg.add(var.set_output(output_)) - - if oscillation_output_id := config.get(CONF_OSCILLATION_OUTPUT): - oscillation_output = await cg.get_variable(oscillation_output_id) - cg.add(var.set_oscillating(oscillation_output)) - - if direction_output_id := config.get(CONF_DIRECTION_OUTPUT): - direction_output = await cg.get_variable(direction_output_id) - cg.add(var.set_direction(direction_output)) + await cg.add_variable(var.set_output, config[CONF_OUTPUT]) + await cg.add_variable(var.set_oscillating, config.get(CONF_OSCILLATION_OUTPUT)) + await cg.add_variable(var.set_direction, config.get(CONF_DIRECTION_OUTPUT)) diff --git a/esphome/components/binary/light/__init__.py b/esphome/components/binary/light/__init__.py index b6eddac3410..3883394050c 100644 --- a/esphome/components/binary/light/__init__.py +++ b/esphome/components/binary/light/__init__.py @@ -20,5 +20,4 @@ async def to_code(config: ConfigType) -> None: var = cg.new_Pvariable(config[CONF_OUTPUT_ID]) await light.register_light(var, config) - out = await cg.get_variable(config[CONF_OUTPUT]) - cg.add(var.set_output(out)) + await cg.add_variable(var.set_output, config[CONF_OUTPUT]) diff --git a/esphome/components/bk72xx_ble_tracker/__init__.py b/esphome/components/bk72xx_ble_tracker/__init__.py index abef3c7752b..5a03fdd293c 100644 --- a/esphome/components/bk72xx_ble_tracker/__init__.py +++ b/esphome/components/bk72xx_ble_tracker/__init__.py @@ -144,8 +144,7 @@ async def to_code(config: ConfigType) -> None: var = cg.new_Pvariable(config[CONF_ID]) await cg.register_component(var, config) - parent = await cg.get_variable(config[CONF_BK72XX_BLE_ID]) - cg.add(var.set_parent(parent)) + await cg.register_parented(var, config[CONF_BK72XX_BLE_ID]) # The tracker registers itself as a controller scan listener in setup(); # request the codegen-sized StaticVector slot for it. bk72xx_ble.request_scan_listener_slot() diff --git a/esphome/components/bp1658cj/output.py b/esphome/components/bp1658cj/output.py index 93e3c75daf9..ca9c94f733b 100644 --- a/esphome/components/bp1658cj/output.py +++ b/esphome/components/bp1658cj/output.py @@ -24,6 +24,5 @@ async def to_code(config: ConfigType) -> None: var = cg.new_Pvariable(config[CONF_ID]) await output.register_output(var, config) - parent = await cg.get_variable(config[CONF_BP1658CJ_ID]) - cg.add(var.set_parent(parent)) + await cg.register_parented(var, config[CONF_BP1658CJ_ID]) cg.add(var.set_channel(config[CONF_CHANNEL])) diff --git a/esphome/components/bp5758d/output.py b/esphome/components/bp5758d/output.py index bbca7c18cc5..24fe8a04e50 100644 --- a/esphome/components/bp5758d/output.py +++ b/esphome/components/bp5758d/output.py @@ -25,7 +25,6 @@ async def to_code(config: ConfigType) -> None: var = cg.new_Pvariable(config[CONF_ID]) await output.register_output(var, config) - parent = await cg.get_variable(config[CONF_BP5758D_ID]) - cg.add(var.set_parent(parent)) + await cg.register_parented(var, config[CONF_BP5758D_ID]) cg.add(var.set_channel(config[CONF_CHANNEL])) cg.add(var.set_current(config[CONF_CURRENT])) diff --git a/esphome/components/ccs811/sensor.py b/esphome/components/ccs811/sensor.py index 80948a6b433..703ae619c5d 100644 --- a/esphome/components/ccs811/sensor.py +++ b/esphome/components/ccs811/sensor.py @@ -72,9 +72,5 @@ async def to_code(config: ConfigType) -> None: if (baseline := config.get(CONF_BASELINE)) is not None: cg.add(var.set_baseline(baseline)) - if temperature_id := config.get(CONF_TEMPERATURE): - sens = await cg.get_variable(temperature_id) - cg.add(var.set_temperature(sens)) - if humidity_id := config.get(CONF_HUMIDITY): - sens = await cg.get_variable(humidity_id) - cg.add(var.set_humidity(sens)) + await cg.add_variable(var.set_temperature, config.get(CONF_TEMPERATURE)) + await cg.add_variable(var.set_humidity, config.get(CONF_HUMIDITY)) diff --git a/esphome/components/cd74hc4067/sensor.py b/esphome/components/cd74hc4067/sensor.py index 670b0502715..aac921178e5 100644 --- a/esphome/components/cd74hc4067/sensor.py +++ b/esphome/components/cd74hc4067/sensor.py @@ -53,5 +53,4 @@ async def to_code(config: ConfigType) -> None: await cg.register_component(var, config) cg.add(var.set_pin(config[CONF_NUMBER])) - sens = await cg.get_variable(config[CONF_SENSOR]) - cg.add(var.set_source(sens)) + await cg.add_variable(var.set_source, config[CONF_SENSOR]) diff --git a/esphome/components/climate_ir/__init__.py b/esphome/components/climate_ir/__init__.py index f4b43e3a523..27c24464595 100644 --- a/esphome/components/climate_ir/__init__.py +++ b/esphome/components/climate_ir/__init__.py @@ -74,12 +74,8 @@ async def register_climate_ir(var: MockObj, config: ConfigType) -> None: cg.add(var.set_supports_heat_cool(False)) if remote_base.CONF_RECEIVER_ID in config: await remote_base.register_listener(var, config) - if sensor_id := config.get(CONF_SENSOR): - sens = await cg.get_variable(sensor_id) - cg.add(var.set_sensor(sens)) - if sensor_id := config.get(CONF_HUMIDITY_SENSOR): - sens = await cg.get_variable(sensor_id) - cg.add(var.set_humidity_sensor(sens)) + await cg.add_variable(var.set_sensor, config.get(CONF_SENSOR)) + await cg.add_variable(var.set_humidity_sensor, config.get(CONF_HUMIDITY_SENSOR)) async def new_climate_ir(config: ConfigType, *args: SafeExpType) -> MockObj: diff --git a/esphome/components/color_temperature/light.py b/esphome/components/color_temperature/light.py index 7686ede1558..f66b51eff4e 100644 --- a/esphome/components/color_temperature/light.py +++ b/esphome/components/color_temperature/light.py @@ -33,11 +33,8 @@ async def to_code(config: ConfigType) -> None: var = cg.new_Pvariable(config[CONF_OUTPUT_ID]) await light.register_light(var, config) - color_temperature = await cg.get_variable(config[CONF_COLOR_TEMPERATURE]) - cg.add(var.set_color_temperature(color_temperature)) - - brightness = await cg.get_variable(config[CONF_BRIGHTNESS]) - cg.add(var.set_brightness(brightness)) + await cg.add_variable(var.set_color_temperature, config[CONF_COLOR_TEMPERATURE]) + await cg.add_variable(var.set_brightness, config[CONF_BRIGHTNESS]) cg.add(var.set_cold_white_temperature(config[CONF_COLD_WHITE_COLOR_TEMPERATURE])) cg.add(var.set_warm_white_temperature(config[CONF_WARM_WHITE_COLOR_TEMPERATURE])) diff --git a/esphome/components/copy/binary_sensor/__init__.py b/esphome/components/copy/binary_sensor/__init__.py index cc8492f21e0..e21743ef296 100644 --- a/esphome/components/copy/binary_sensor/__init__.py +++ b/esphome/components/copy/binary_sensor/__init__.py @@ -38,5 +38,4 @@ async def to_code(config: ConfigType) -> None: var = await binary_sensor.new_binary_sensor(config) await cg.register_component(var, config) - source = await cg.get_variable(config[CONF_SOURCE_ID]) - cg.add(var.set_source(source)) + await cg.add_variable(var.set_source, config[CONF_SOURCE_ID]) diff --git a/esphome/components/copy/button/__init__.py b/esphome/components/copy/button/__init__.py index 768131bbe58..17155b2f744 100644 --- a/esphome/components/copy/button/__init__.py +++ b/esphome/components/copy/button/__init__.py @@ -38,5 +38,4 @@ async def to_code(config: ConfigType) -> None: await button.register_button(var, config) await cg.register_component(var, config) - source = await cg.get_variable(config[CONF_SOURCE_ID]) - cg.add(var.set_source(source)) + await cg.add_variable(var.set_source, config[CONF_SOURCE_ID]) diff --git a/esphome/components/copy/cover/__init__.py b/esphome/components/copy/cover/__init__.py index d23602fa741..7d01cd93ac2 100644 --- a/esphome/components/copy/cover/__init__.py +++ b/esphome/components/copy/cover/__init__.py @@ -36,5 +36,4 @@ async def to_code(config: ConfigType) -> None: var = await cover.new_cover(config) await cg.register_component(var, config) - source = await cg.get_variable(config[CONF_SOURCE_ID]) - cg.add(var.set_source(source)) + await cg.add_variable(var.set_source, config[CONF_SOURCE_ID]) diff --git a/esphome/components/copy/fan/__init__.py b/esphome/components/copy/fan/__init__.py index ffa414c5f21..44c0d654073 100644 --- a/esphome/components/copy/fan/__init__.py +++ b/esphome/components/copy/fan/__init__.py @@ -30,5 +30,4 @@ async def to_code(config: ConfigType) -> None: var = await fan.new_fan(config) await cg.register_component(var, config) - source = await cg.get_variable(config[CONF_SOURCE_ID]) - cg.add(var.set_source(source)) + await cg.add_variable(var.set_source, config[CONF_SOURCE_ID]) diff --git a/esphome/components/copy/lock/__init__.py b/esphome/components/copy/lock/__init__.py index 8d9c4b6eca7..5f2f8f2eb1e 100644 --- a/esphome/components/copy/lock/__init__.py +++ b/esphome/components/copy/lock/__init__.py @@ -30,5 +30,4 @@ async def to_code(config: ConfigType) -> None: var = await lock.new_lock(config) await cg.register_component(var, config) - source = await cg.get_variable(config[CONF_SOURCE_ID]) - cg.add(var.set_source(source)) + await cg.add_variable(var.set_source, config[CONF_SOURCE_ID]) diff --git a/esphome/components/copy/number/__init__.py b/esphome/components/copy/number/__init__.py index 9659a605f91..c0370afc18c 100644 --- a/esphome/components/copy/number/__init__.py +++ b/esphome/components/copy/number/__init__.py @@ -38,5 +38,4 @@ async def to_code(config: ConfigType) -> None: var = await number.new_number(config, min_value=0, max_value=0, step=0) await cg.register_component(var, config) - source = await cg.get_variable(config[CONF_SOURCE_ID]) - cg.add(var.set_source(source)) + await cg.add_variable(var.set_source, config[CONF_SOURCE_ID]) diff --git a/esphome/components/copy/select/__init__.py b/esphome/components/copy/select/__init__.py index 97776b1edd7..e6a4091be8f 100644 --- a/esphome/components/copy/select/__init__.py +++ b/esphome/components/copy/select/__init__.py @@ -31,5 +31,4 @@ async def to_code(config: ConfigType) -> None: await select.register_select(var, config, options=[]) await cg.register_component(var, config) - source = await cg.get_variable(config[CONF_SOURCE_ID]) - cg.add(var.set_source(source)) + await cg.add_variable(var.set_source, config[CONF_SOURCE_ID]) diff --git a/esphome/components/copy/sensor/__init__.py b/esphome/components/copy/sensor/__init__.py index 54687980475..746a48e19ce 100644 --- a/esphome/components/copy/sensor/__init__.py +++ b/esphome/components/copy/sensor/__init__.py @@ -42,5 +42,4 @@ async def to_code(config: ConfigType) -> None: var = await sensor.new_sensor(config) await cg.register_component(var, config) - source = await cg.get_variable(config[CONF_SOURCE_ID]) - cg.add(var.set_source(source)) + await cg.add_variable(var.set_source, config[CONF_SOURCE_ID]) diff --git a/esphome/components/copy/switch/__init__.py b/esphome/components/copy/switch/__init__.py index 0e714540f96..6bcd10ff200 100644 --- a/esphome/components/copy/switch/__init__.py +++ b/esphome/components/copy/switch/__init__.py @@ -36,5 +36,4 @@ async def to_code(config: ConfigType) -> None: var = await switch.new_switch(config) await cg.register_component(var, config) - source = await cg.get_variable(config[CONF_SOURCE_ID]) - cg.add(var.set_source(source)) + await cg.add_variable(var.set_source, config[CONF_SOURCE_ID]) diff --git a/esphome/components/copy/text/__init__.py b/esphome/components/copy/text/__init__.py index 59fdce6c96e..44d61a88506 100644 --- a/esphome/components/copy/text/__init__.py +++ b/esphome/components/copy/text/__init__.py @@ -31,5 +31,4 @@ async def to_code(config: ConfigType) -> None: var = await text.new_text(config) await cg.register_component(var, config) - source = await cg.get_variable(config[CONF_SOURCE_ID]) - cg.add(var.set_source(source)) + await cg.add_variable(var.set_source, config[CONF_SOURCE_ID]) diff --git a/esphome/components/copy/text_sensor/__init__.py b/esphome/components/copy/text_sensor/__init__.py index 146beae5eaa..9c5495938e0 100644 --- a/esphome/components/copy/text_sensor/__init__.py +++ b/esphome/components/copy/text_sensor/__init__.py @@ -30,5 +30,4 @@ async def to_code(config: ConfigType) -> None: var = await text_sensor.new_text_sensor(config) await cg.register_component(var, config) - source = await cg.get_variable(config[CONF_SOURCE_ID]) - cg.add(var.set_source(source)) + await cg.add_variable(var.set_source, config[CONF_SOURCE_ID]) diff --git a/esphome/components/counter/sensor.py b/esphome/components/counter/sensor.py index 0f36b1721bf..0c3766cbe7c 100644 --- a/esphome/components/counter/sensor.py +++ b/esphome/components/counter/sensor.py @@ -55,10 +55,8 @@ async def to_code(config): ) await cg.register_component(var, config) await sensor.register_sensor(var, config) - if (source := config.get(CONF_SENSOR)) is not None: - cg.add(var.count_updates_from(await cg.get_variable(source))) - if (source := config.get(CONF_BINARY_SENSOR)) is not None: - cg.add(var.count_true_from(await cg.get_variable(source))) + await cg.add_variable(var.count_updates_from, config.get(CONF_SENSOR)) + await cg.add_variable(var.count_true_from, config.get(CONF_BINARY_SENSOR)) automation.register_apply_action( diff --git a/esphome/components/ct_clamp/sensor.py b/esphome/components/ct_clamp/sensor.py index 8ef211cb247..b9959d65f72 100644 --- a/esphome/components/ct_clamp/sensor.py +++ b/esphome/components/ct_clamp/sensor.py @@ -41,6 +41,5 @@ async def to_code(config: ConfigType) -> None: var = await sensor.new_sensor(config) await cg.register_component(var, config) - sens = await cg.get_variable(config[CONF_SENSOR]) - cg.add(var.set_source(sens)) + await cg.add_variable(var.set_source, config[CONF_SENSOR]) cg.add(var.set_sample_duration(config[CONF_SAMPLE_DURATION])) diff --git a/esphome/components/current_based/cover.py b/esphome/components/current_based/cover.py index a552956082a..4edcb98a1d9 100644 --- a/esphome/components/current_based/cover.py +++ b/esphome/components/current_based/cover.py @@ -77,8 +77,7 @@ async def to_code(config: ConfigType) -> None: ) # OPEN - bin = await cg.get_variable(config[CONF_OPEN_SENSOR]) - cg.add(var.set_open_sensor(bin)) + await cg.add_variable(var.set_open_sensor, config[CONF_OPEN_SENSOR]) cg.add( var.set_open_moving_current_threshold( config[CONF_OPEN_MOVING_CURRENT_THRESHOLD] @@ -97,8 +96,7 @@ async def to_code(config: ConfigType) -> None: ) # CLOSE - bin = await cg.get_variable(config[CONF_CLOSE_SENSOR]) - cg.add(var.set_close_sensor(bin)) + await cg.add_variable(var.set_close_sensor, config[CONF_CLOSE_SENSOR]) cg.add( var.set_close_moving_current_threshold( config[CONF_CLOSE_MOVING_CURRENT_THRESHOLD] diff --git a/esphome/components/cwww/light.py b/esphome/components/cwww/light.py index 90fe6d0bad8..3ea6a85923a 100644 --- a/esphome/components/cwww/light.py +++ b/esphome/components/cwww/light.py @@ -36,13 +36,11 @@ async def to_code(config: ConfigType) -> None: var = cg.new_Pvariable(config[CONF_OUTPUT_ID]) await light.register_light(var, config) - cwhite = await cg.get_variable(config[CONF_COLD_WHITE]) - cg.add(var.set_cold_white(cwhite)) + await cg.add_variable(var.set_cold_white, config[CONF_COLD_WHITE]) if cold_white_color_temperature := config.get(CONF_COLD_WHITE_COLOR_TEMPERATURE): cg.add(var.set_cold_white_temperature(cold_white_color_temperature)) - wwhite = await cg.get_variable(config[CONF_WARM_WHITE]) - cg.add(var.set_warm_white(wwhite)) + await cg.add_variable(var.set_warm_white, config[CONF_WARM_WHITE]) if warm_white_color_temperature := config.get(CONF_WARM_WHITE_COLOR_TEMPERATURE): cg.add(var.set_warm_white_temperature(warm_white_color_temperature)) diff --git a/esphome/components/datetime/__init__.py b/esphome/components/datetime/__init__.py index 20fd258cb00..e9ea05dcdab 100644 --- a/esphome/components/datetime/__init__.py +++ b/esphome/components/datetime/__init__.py @@ -148,9 +148,7 @@ async def setup_datetime_core_(var: MockObj, config: ConfigType) -> None: forward=[automation.parent_ref(var).state_as_esptime()], ) - if CONF_TIME_ID in config: - rtc = await cg.get_variable(config[CONF_TIME_ID]) - cg.add(var.set_rtc(rtc)) + await cg.add_variable(var.set_rtc, config.get(CONF_TIME_ID)) for conf in config.get(CONF_ON_TIME, []): trigger = cg.new_Pvariable(conf[CONF_TRIGGER_ID]) diff --git a/esphome/components/deep_sleep/__init__.py b/esphome/components/deep_sleep/__init__.py index 7230b1e8e9c..69aa1120ba1 100644 --- a/esphome/components/deep_sleep/__init__.py +++ b/esphome/components/deep_sleep/__init__.py @@ -491,8 +491,7 @@ async def deep_sleep_enter_to_code( until = config[CONF_UNTIL] cg.add(var.set_until(until[CONF_HOUR], until[CONF_MINUTE], until[CONF_SECOND])) - time_ = await cg.get_variable(config[CONF_TIME_ID]) - cg.add(var.set_time(time_)) + await cg.add_variable(var.set_time, config[CONF_TIME_ID]) return var diff --git a/esphome/components/dew_point/sensor.py b/esphome/components/dew_point/sensor.py index 555fdef289e..e7361c8dbfe 100644 --- a/esphome/components/dew_point/sensor.py +++ b/esphome/components/dew_point/sensor.py @@ -40,8 +40,5 @@ async def to_code(config: ConfigType) -> None: var = await sensor.new_sensor(config) await cg.register_component(var, config) - temperature_sensor = await cg.get_variable(config[CONF_TEMPERATURE]) - cg.add(var.set_temperature_sensor(temperature_sensor)) - - humidity_sensor = await cg.get_variable(config[CONF_HUMIDITY]) - cg.add(var.set_humidity_sensor(humidity_sensor)) + await cg.add_variable(var.set_temperature_sensor, config[CONF_TEMPERATURE]) + await cg.add_variable(var.set_humidity_sensor, config[CONF_HUMIDITY]) diff --git a/esphome/components/display_menu_base/__init__.py b/esphome/components/display_menu_base/__init__.py index 791242cda12..ba51bdccaae 100644 --- a/esphome/components/display_menu_base/__init__.py +++ b/esphome/components/display_menu_base/__init__.py @@ -280,15 +280,12 @@ async def menu_item_to_code(menu, config, parent): if CONF_IMMEDIATE_EDIT in config: cg.add(item.set_immediate_edit(config[CONF_IMMEDIATE_EDIT])) if config[CONF_TYPE] == CONF_SELECT: - var = await cg.get_variable(config[CONF_SELECT]) - cg.add(item.set_select_variable(var)) + await cg.add_variable(item.set_select_variable, config[CONF_SELECT]) if config[CONF_TYPE] == CONF_NUMBER: - var = await cg.get_variable(config[CONF_NUMBER]) - cg.add(item.set_number_variable(var)) + await cg.add_variable(item.set_number_variable, config[CONF_NUMBER]) cg.add(item.set_format(config[CONF_FORMAT])) if config[CONF_TYPE] == CONF_SWITCH: - var = await cg.get_variable(config[CONF_SWITCH]) - cg.add(item.set_switch_variable(var)) + await cg.add_variable(item.set_switch_variable, config[CONF_SWITCH]) cg.add(item.set_on_text(config[CONF_ON_TEXT])) cg.add(item.set_off_text(config[CONF_OFF_TEXT])) await _build_item_automations(item, config) diff --git a/esphome/components/duty_time/sensor.py b/esphome/components/duty_time/sensor.py index 6b035d5c982..1f733fc6bb1 100644 --- a/esphome/components/duty_time/sensor.py +++ b/esphome/components/duty_time/sensor.py @@ -57,9 +57,7 @@ async def to_code(config: ConfigType) -> None: var = await sensor.new_sensor(config) await cg.register_component(var, config) cg.add(var.set_restore(config[CONF_RESTORE])) - if CONF_SENSOR in config: - sens = await cg.get_variable(config[CONF_SENSOR]) - cg.add(var.set_sensor(sens)) + await cg.add_variable(var.set_sensor, config.get(CONF_SENSOR)) if CONF_LAMBDA in config: lambda_ = await cg.process_lambda(config[CONF_LAMBDA], [], return_type=cg.bool_) cg.add(var.set_lambda(lambda_)) diff --git a/esphome/components/ecocomfort2/__init__.py b/esphome/components/ecocomfort2/__init__.py index 8a0e1654188..c2540db644e 100644 --- a/esphome/components/ecocomfort2/__init__.py +++ b/esphome/components/ecocomfort2/__init__.py @@ -53,8 +53,7 @@ async def to_code(config: ConfigType) -> None: var = cg.new_Pvariable(config[CONF_ID]) await cg.register_component(var, config) await ble_client.register_ble_node(var, config) - if (time_id := config.get(CONF_TIME_ID)) is not None: - cg.add(var.set_time(await cg.get_variable(time_id))) + await cg.add_variable(var.set_time, config.get(CONF_TIME_ID)) def _final_validate(config: ConfigType) -> ConfigType: diff --git a/esphome/components/endstop/cover.py b/esphome/components/endstop/cover.py index 0e27189500c..066326e9d46 100644 --- a/esphome/components/endstop/cover.py +++ b/esphome/components/endstop/cover.py @@ -43,15 +43,13 @@ async def to_code(config: ConfigType) -> None: var.get_stop_trigger(), [], config[CONF_STOP_ACTION] ) - bin = await cg.get_variable(config[CONF_OPEN_ENDSTOP]) - cg.add(var.set_open_endstop(bin)) + await cg.add_variable(var.set_open_endstop, config[CONF_OPEN_ENDSTOP]) cg.add(var.set_open_duration(config[CONF_OPEN_DURATION])) await automation.build_automation( var.get_open_trigger(), [], config[CONF_OPEN_ACTION] ) - bin = await cg.get_variable(config[CONF_CLOSE_ENDSTOP]) - cg.add(var.set_close_endstop(bin)) + await cg.add_variable(var.set_close_endstop, config[CONF_CLOSE_ENDSTOP]) cg.add(var.set_close_duration(config[CONF_CLOSE_DURATION])) await automation.build_automation( var.get_close_trigger(), [], config[CONF_CLOSE_ACTION] diff --git a/esphome/components/ens160_base/__init__.py b/esphome/components/ens160_base/__init__.py index 8ef5971f17a..61342cbe5c0 100644 --- a/esphome/components/ens160_base/__init__.py +++ b/esphome/components/ens160_base/__init__.py @@ -70,9 +70,9 @@ async def to_code_base(config: ConfigType) -> MockObj: await sensors(CONF_AQI, var.set_aqi) if compensation_config := config.get(CONF_COMPENSATION): - sens = await cg.get_variable(compensation_config[CONF_TEMPERATURE]) - cg.add(var.set_temperature(sens)) - sens = await cg.get_variable(compensation_config[CONF_HUMIDITY]) - cg.add(var.set_humidity(sens)) + await cg.add_variable( + var.set_temperature, compensation_config[CONF_TEMPERATURE] + ) + await cg.add_variable(var.set_humidity, compensation_config[CONF_HUMIDITY]) return var diff --git a/esphome/components/esp32_camera/__init__.py b/esphome/components/esp32_camera/__init__.py index 0014d38a5c4..a83a4817b1a 100644 --- a/esphome/components/esp32_camera/__init__.py +++ b/esphome/components/esp32_camera/__init__.py @@ -376,8 +376,7 @@ async def to_code(config: ConfigType) -> None: extclk = config[CONF_EXTERNAL_CLOCK] cg.add(var.set_external_clock(extclk[CONF_PIN], extclk[CONF_FREQUENCY])) if i2c_id := config.get(CONF_I2C_ID): - i2c_hub = await cg.get_variable(i2c_id) - cg.add(var.set_i2c_id(i2c_hub)) + await cg.add_variable(var.set_i2c_id, i2c_id) else: i2c_pins = config[CONF_I2C_PINS] cg.add(var.set_i2c_pins(i2c_pins[CONF_SDA], i2c_pins[CONF_SCL])) diff --git a/esphome/components/esp32_hosted/update/__init__.py b/esphome/components/esp32_hosted/update/__init__.py index 8e85cce75a5..4ccd6a12f8b 100644 --- a/esphome/components/esp32_hosted/update/__init__.py +++ b/esphome/components/esp32_hosted/update/__init__.py @@ -104,8 +104,7 @@ async def to_code(config: dict[str, Any]) -> None: cg.add(var.set_firmware_data(prog_arr)) cg.add(var.set_firmware_size(len(firmware_data))) else: - http_request_var = await cg.get_variable(config[CONF_HTTP_REQUEST_ID]) - cg.add(var.set_http_request_parent(http_request_var)) + await cg.add_variable(var.set_http_request_parent, config[CONF_HTTP_REQUEST_ID]) cg.add(var.set_source_url(config[CONF_SOURCE])) cg.add_define("USE_ESP32_HOSTED_HTTP_UPDATE") diff --git a/esphome/components/feedback/cover.py b/esphome/components/feedback/cover.py index 9fbda9a9737..f203e8d5186 100644 --- a/esphome/components/feedback/cover.py +++ b/esphome/components/feedback/cover.py @@ -129,30 +129,22 @@ async def to_code(config: ConfigType) -> None: var.get_open_trigger(), [], config[CONF_OPEN_ACTION] ) cg.add(var.set_open_duration(config[CONF_OPEN_DURATION])) - if CONF_OPEN_ENDSTOP in config: - bin = await cg.get_variable(config[CONF_OPEN_ENDSTOP]) - cg.add(var.set_open_endstop(bin)) - if CONF_OPEN_SENSOR in config: - bin = await cg.get_variable(config[CONF_OPEN_SENSOR]) - cg.add(var.set_open_sensor(bin)) - if CONF_OPEN_OBSTACLE_SENSOR in config: - bin = await cg.get_variable(config[CONF_OPEN_OBSTACLE_SENSOR]) - cg.add(var.set_open_obstacle_sensor(bin)) + await cg.add_variable(var.set_open_endstop, config.get(CONF_OPEN_ENDSTOP)) + await cg.add_variable(var.set_open_sensor, config.get(CONF_OPEN_SENSOR)) + await cg.add_variable( + var.set_open_obstacle_sensor, config.get(CONF_OPEN_OBSTACLE_SENSOR) + ) # CLOSE await automation.build_automation( var.get_close_trigger(), [], config[CONF_CLOSE_ACTION] ) cg.add(var.set_close_duration(config[CONF_CLOSE_DURATION])) - if CONF_CLOSE_ENDSTOP in config: - bin = await cg.get_variable(config[CONF_CLOSE_ENDSTOP]) - cg.add(var.set_close_endstop(bin)) - if CONF_CLOSE_SENSOR in config: - bin = await cg.get_variable(config[CONF_CLOSE_SENSOR]) - cg.add(var.set_close_sensor(bin)) - if CONF_CLOSE_OBSTACLE_SENSOR in config: - bin = await cg.get_variable(config[CONF_CLOSE_OBSTACLE_SENSOR]) - cg.add(var.set_close_obstacle_sensor(bin)) + await cg.add_variable(var.set_close_endstop, config.get(CONF_CLOSE_ENDSTOP)) + await cg.add_variable(var.set_close_sensor, config.get(CONF_CLOSE_SENSOR)) + await cg.add_variable( + var.set_close_obstacle_sensor, config.get(CONF_CLOSE_OBSTACLE_SENSOR) + ) # OTHER if CONF_MAX_DURATION in config: diff --git a/esphome/components/filter_lifetime/sensor.py b/esphome/components/filter_lifetime/sensor.py index 58af033f329..549f5a20a44 100644 --- a/esphome/components/filter_lifetime/sensor.py +++ b/esphome/components/filter_lifetime/sensor.py @@ -72,15 +72,15 @@ async def to_code(config: ConfigType) -> None: if (is_on := config.get(CONF_IS_ON)) is not None: cg.add(var.set_is_on_lambda(await cg.templatable(is_on, [], bool))) - elif (is_on_sensor := config.get(CONF_IS_ON_SENSOR)) is not None: - cg.add(var.set_is_on_sensor(await cg.get_variable(is_on_sensor))) + await cg.add_variable(var.set_is_on_sensor, config.get(CONF_IS_ON_SENSOR)) if (current_speed := config.get(CONF_CURRENT_SPEED)) is not None: cg.add( var.set_current_speed_lambda(await cg.templatable(current_speed, [], float)) ) - elif (speed_sensor := config.get(CONF_CURRENT_SPEED_SENSOR)) is not None: - cg.add(var.set_current_speed_sensor(await cg.get_variable(speed_sensor))) + await cg.add_variable( + var.set_current_speed_sensor, config.get(CONF_CURRENT_SPEED_SENSOR) + ) sensors = sensor.sub_sensors(config) await sensors(CONF_RUNTIME_HOURS, var.set_runtime_hours_sensor) diff --git a/esphome/components/gp2y1010au0f/sensor.py b/esphome/components/gp2y1010au0f/sensor.py index 3121aa1de50..9d541a3d88a 100644 --- a/esphome/components/gp2y1010au0f/sensor.py +++ b/esphome/components/gp2y1010au0f/sensor.py @@ -49,8 +49,7 @@ async def to_code(config: ConfigType) -> None: await cg.register_component(var, config) # the ADC sensor to read voltage from - adc_sensor = await cg.get_variable(config[CONF_SENSOR]) - cg.add(var.set_adc_source(adc_sensor)) + await cg.add_variable(var.set_adc_source, config[CONF_SENSOR]) cg.add( var.set_voltage_refs( config[CONF_ADC_VOLTAGE_OFFSET], config[CONF_ADC_VOLTAGE_MULTIPLIER] @@ -58,5 +57,4 @@ async def to_code(config: ConfigType) -> None: ) # the binary output to control the module's internal IR LED - led_output = await cg.get_variable(config[CONF_OUTPUT]) - cg.add(var.set_led_output(led_output)) + await cg.add_variable(var.set_led_output, config[CONF_OUTPUT]) diff --git a/esphome/components/graph/__init__.py b/esphome/components/graph/__init__.py index ce9035655c3..9dfa8df4cc8 100644 --- a/esphome/components/graph/__init__.py +++ b/esphome/components/graph/__init__.py @@ -169,8 +169,7 @@ async def to_code(config: ConfigType) -> None: # Trace options for trace in config[CONF_TRACES]: tr = cg.new_Pvariable(trace[CONF_ID], GraphTrace()) - sens = await cg.get_variable(trace[CONF_SENSOR]) - cg.add(tr.set_sensor(sens)) + await cg.add_variable(tr.set_sensor, trace[CONF_SENSOR]) if CONF_NAME in trace: cg.add(tr.set_name(trace[CONF_NAME])) else: @@ -179,9 +178,7 @@ async def to_code(config: ConfigType) -> None: cg.add(tr.set_line_thickness(trace[CONF_LINE_THICKNESS])) if CONF_LINE_TYPE in trace: cg.add(tr.set_line_type(trace[CONF_LINE_TYPE])) - if CONF_COLOR in trace: - c = await cg.get_variable(trace[CONF_COLOR]) - cg.add(tr.set_line_color(c)) + await cg.add_variable(tr.set_line_color, trace.get(CONF_COLOR)) if CONF_CONTINUOUS in trace: cg.add(tr.set_continuous(trace[CONF_CONTINUOUS])) cg.add(var.add_trace(tr)) @@ -189,12 +186,8 @@ async def to_code(config: ConfigType) -> None: if CONF_LEGEND in config: lgd = config[CONF_LEGEND] legend = cg.new_Pvariable(lgd[CONF_ID], GraphLegend()) - if CONF_NAME_FONT in lgd: - font = await cg.get_variable(lgd[CONF_NAME_FONT]) - cg.add(legend.set_name_font(font)) - if CONF_VALUE_FONT in lgd: - font = await cg.get_variable(lgd[CONF_VALUE_FONT]) - cg.add(legend.set_value_font(font)) + await cg.add_variable(legend.set_name_font, lgd.get(CONF_NAME_FONT)) + await cg.add_variable(legend.set_value_font, lgd.get(CONF_VALUE_FONT)) if CONF_WIDTH in lgd: cg.add(legend.set_width(lgd[CONF_WIDTH])) if CONF_HEIGHT in lgd: diff --git a/esphome/components/graphical_display_menu/__init__.py b/esphome/components/graphical_display_menu/__init__.py index a398aea6192..5534321dd7f 100644 --- a/esphome/components/graphical_display_menu/__init__.py +++ b/esphome/components/graphical_display_menu/__init__.py @@ -55,12 +55,8 @@ async def to_code(config: ConfigType) -> None: var = cg.new_Pvariable(config[CONF_ID]) await cg.register_component(var, config) - if display_config := config.get(CONF_DISPLAY): - drawing_display = await cg.get_variable(display_config) - cg.add(var.set_display(drawing_display)) - - menu_font = await cg.get_variable(config[CONF_FONT]) - cg.add(var.set_font(menu_font)) + await cg.add_variable(var.set_display, config.get(CONF_DISPLAY)) + await cg.add_variable(var.set_font, config[CONF_FONT]) if (menu_item_value_config := config.get(CONF_MENU_ITEM_VALUE, None)) is not None: if isinstance(menu_item_value_config, core.Lambda): @@ -73,13 +69,8 @@ async def to_code(config: ConfigType) -> None: else: cg.add(var.set_menu_item_value(menu_item_value_config)) - if foreground_color_config := config.get(CONF_FOREGROUND_COLOR): - foreground_color = await cg.get_variable(foreground_color_config) - cg.add(var.set_foreground_color(foreground_color)) - - if background_color_config := config.get(CONF_BACKGROUND_COLOR): - background_color = await cg.get_variable(background_color_config) - cg.add(var.set_background_color(background_color)) + await cg.add_variable(var.set_foreground_color, config.get(CONF_FOREGROUND_COLOR)) + await cg.add_variable(var.set_background_color, config.get(CONF_BACKGROUND_COLOR)) for conf in config.get(CONF_ON_REDRAW, []): await automation.build_callback_automation( diff --git a/esphome/components/hbridge/light/__init__.py b/esphome/components/hbridge/light/__init__.py index f7866cb9907..95cf9dc6dc8 100644 --- a/esphome/components/hbridge/light/__init__.py +++ b/esphome/components/hbridge/light/__init__.py @@ -28,7 +28,5 @@ async def to_code(config: ConfigType) -> None: await cg.register_component(var, config) await light.register_light(var, config) - hside = await cg.get_variable(config[CONF_PIN_A]) - cg.add(var.set_pina_pin(hside)) - lside = await cg.get_variable(config[CONF_PIN_B]) - cg.add(var.set_pinb_pin(lside)) + await cg.add_variable(var.set_pina_pin, config[CONF_PIN_A]) + await cg.add_variable(var.set_pinb_pin, config[CONF_PIN_B]) diff --git a/esphome/components/http_request/update/__init__.py b/esphome/components/http_request/update/__init__.py index 4bdc30e4cf3..e22270f1f2e 100644 --- a/esphome/components/http_request/update/__init__.py +++ b/esphome/components/http_request/update/__init__.py @@ -32,10 +32,8 @@ CONFIG_SCHEMA = ( async def to_code(config: ConfigType) -> None: var = await update.new_update(config) - ota_parent = await cg.get_variable(config[CONF_OTA_ID]) - cg.add(var.set_ota_parent(ota_parent)) - request_parent = await cg.get_variable(config[CONF_HTTP_REQUEST_ID]) - cg.add(var.set_request_parent(request_parent)) + await cg.add_variable(var.set_ota_parent, config[CONF_OTA_ID]) + await cg.add_variable(var.set_request_parent, config[CONF_HTTP_REQUEST_ID]) cg.add(var.set_source_url(config[CONF_SOURCE])) diff --git a/esphome/components/i2c/__init__.py b/esphome/components/i2c/__init__.py index 84f6d0c2e66..8598998f563 100644 --- a/esphome/components/i2c/__init__.py +++ b/esphome/components/i2c/__init__.py @@ -390,8 +390,7 @@ async def register_i2c_device(var: MockObj, config: ConfigType) -> None: This is a coroutine, you need to await it with an 'await' expression! """ - parent = await cg.get_variable(config[CONF_I2C_ID]) - cg.add(var.set_i2c_bus(parent)) + await cg.add_variable(var.set_i2c_bus, config[CONF_I2C_ID]) cg.add(var.set_i2c_address(config[CONF_ADDRESS])) diff --git a/esphome/components/improv_ble/__init__.py b/esphome/components/improv_ble/__init__.py index e7d4be8cc3d..dbc6542ec81 100644 --- a/esphome/components/improv_ble/__init__.py +++ b/esphome/components/improv_ble/__init__.py @@ -135,13 +135,8 @@ async def to_code(config: ConfigType) -> None: cg.add(var.set_wifi_timeout(config[CONF_WIFI_TIMEOUT])) - if CONF_AUTHORIZER in config and config[CONF_AUTHORIZER] is not None: - activator = await cg.get_variable(config[CONF_AUTHORIZER]) - cg.add(var.set_authorizer(activator)) - - if CONF_STATUS_INDICATOR in config: - status_indicator = await cg.get_variable(config[CONF_STATUS_INDICATOR]) - cg.add(var.set_status_indicator(status_indicator)) + await cg.add_variable(var.set_authorizer, config.get(CONF_AUTHORIZER)) + await cg.add_variable(var.set_status_indicator, config.get(CONF_STATUS_INDICATOR)) if any(config.get(entry.conf_key) for entry in _CALLBACK_AUTOMATIONS): cg.add_define("USE_IMPROV_BLE_STATE_CALLBACK") diff --git a/esphome/components/improv_serial/__init__.py b/esphome/components/improv_serial/__init__.py index 3e1aef21bb6..6bb5725b416 100644 --- a/esphome/components/improv_serial/__init__.py +++ b/esphome/components/improv_serial/__init__.py @@ -68,5 +68,5 @@ async def to_code(config: ConfigType) -> None: await improv_base.setup_improv_core(var, config) cg.add_define("USE_IMPROV_SERIAL") if (uart_id := config.get(CONF_UART_ID)) is not None: - cg.add(var.set_uart(await cg.get_variable(uart_id))) + await cg.add_variable(var.set_uart, uart_id) cg.add_define("USE_IMPROV_SERIAL_UART") diff --git a/esphome/components/integration/sensor.py b/esphome/components/integration/sensor.py index d8e2c82cf6f..6a7dc63dbd5 100644 --- a/esphome/components/integration/sensor.py +++ b/esphome/components/integration/sensor.py @@ -93,8 +93,7 @@ async def to_code(config: ConfigType) -> None: await cg.register_component(var, config) await sensor.register_sensor(var, config) - sens = await cg.get_variable(config[CONF_SENSOR]) - cg.add(var.set_sensor(sens)) + await cg.add_variable(var.set_sensor, config[CONF_SENSOR]) cg.add(var.set_time(config[CONF_TIME_UNIT])) cg.add(var.set_method(config[CONF_INTEGRATION_METHOD])) cg.add(var.set_restore(config[CONF_RESTORE])) diff --git a/esphome/components/key_collector/__init__.py b/esphome/components/key_collector/__init__.py index 8dafb5da070..dc50f8cdc0d 100644 --- a/esphome/components/key_collector/__init__.py +++ b/esphome/components/key_collector/__init__.py @@ -93,8 +93,7 @@ async def to_code(config: ConfigType) -> None: var = cg.new_Pvariable(config[CONF_ID]) await cg.register_component(var, config) for source_conf in config.get(CONF_SOURCE_ID, ()): - source = await cg.get_variable(source_conf) - cg.add(var.add_provider(source)) + await cg.add_variable(var.add_provider, source_conf) if CONF_MIN_LENGTH in config: cg.add(var.set_min_length(config[CONF_MIN_LENGTH])) if CONF_MAX_LENGTH in config: diff --git a/esphome/components/lcd_menu/__init__.py b/esphome/components/lcd_menu/__init__.py index 483a36491db..b314a0ae02d 100644 --- a/esphome/components/lcd_menu/__init__.py +++ b/esphome/components/lcd_menu/__init__.py @@ -61,8 +61,7 @@ FINAL_VALIDATE_SCHEMA = cv.All( async def to_code(config: ConfigType) -> None: var = cg.new_Pvariable(config[CONF_ID]) await cg.register_component(var, config) - disp = await cg.get_variable(config[CONF_DISPLAY_ID]) - cg.add(var.set_display(disp)) + await cg.add_variable(var.set_display, config[CONF_DISPLAY_ID]) cg.add(var.set_dimensions(config[CONF_DIMENSIONS][0], config[CONF_DIMENSIONS][1])) await display_menu_to_code(var, config) cg.add(var.set_mark_selected(config[CONF_MARK_SELECTED])) diff --git a/esphome/components/ln882h_ble_tracker/__init__.py b/esphome/components/ln882h_ble_tracker/__init__.py index 0d2b3a51804..607ea4448fd 100644 --- a/esphome/components/ln882h_ble_tracker/__init__.py +++ b/esphome/components/ln882h_ble_tracker/__init__.py @@ -126,8 +126,7 @@ async def to_code(config: ConfigType) -> None: var = cg.new_Pvariable(config[CONF_ID]) await cg.register_component(var, config) - parent = await cg.get_variable(config[CONF_LN882H_BLE_ID]) - cg.add(var.set_parent(parent)) + await cg.register_parented(var, config[CONF_LN882H_BLE_ID]) # The tracker registers itself as a controller scan listener in setup(); # request the codegen-sized StaticVector slot for it. ln882h_ble.request_scan_listener_slot()