diff --git a/esphome/components/mitsubishi_cn105/__init__.py b/esphome/components/mitsubishi_cn105/__init__.py index ba51bd3a806..4037dd14d1f 100644 --- a/esphome/components/mitsubishi_cn105/__init__.py +++ b/esphome/components/mitsubishi_cn105/__init__.py @@ -85,8 +85,7 @@ FINAL_VALIDATE_SCHEMA = cv.All( async def register_mitsubishi_cn105_device(var: MockObj, config: ConfigType) -> None: - parent = await cg.get_variable(config[CONF_MITSUBISHI_CN105_ID]) - cg.add(var.set_parent(parent)) + await cg.register_parented(var, config[CONF_MITSUBISHI_CN105_ID]) async def to_code(config: ConfigType) -> None: diff --git a/esphome/components/modbus/__init__.py b/esphome/components/modbus/__init__.py index 8c079afbac3..a1f15aab452 100644 --- a/esphome/components/modbus/__init__.py +++ b/esphome/components/modbus/__init__.py @@ -382,8 +382,7 @@ def final_validate_modbus_device( async def register_modbus_client_device(var: MockObj, config: ConfigType) -> None: - parent = await cg.get_variable(config[CONF_MODBUS_ID]) - cg.add(var.set_parent(parent)) + await cg.register_parented(var, config[CONF_MODBUS_ID]) cg.add(var.set_address(config[CONF_ADDRESS])) diff --git a/esphome/components/monochromatic/light.py b/esphome/components/monochromatic/light.py index 04336bcde1a..40e793a6058 100644 --- a/esphome/components/monochromatic/light.py +++ b/esphome/components/monochromatic/light.py @@ -21,5 +21,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/mqtt_subscribe/sensor/__init__.py b/esphome/components/mqtt_subscribe/sensor/__init__.py index e451d2db8ad..38eb47654ad 100644 --- a/esphome/components/mqtt_subscribe/sensor/__init__.py +++ b/esphome/components/mqtt_subscribe/sensor/__init__.py @@ -33,7 +33,6 @@ async def to_code(config: ConfigType) -> None: var = await sensor.new_sensor(config) await cg.register_component(var, config) - parent = await cg.get_variable(config[CONF_MQTT_PARENT_ID]) - cg.add(var.set_parent(parent)) + await cg.register_parented(var, config[CONF_MQTT_PARENT_ID]) cg.add(var.set_topic(config[CONF_TOPIC])) cg.add(var.set_qos(config[CONF_QOS])) diff --git a/esphome/components/mqtt_subscribe/text_sensor/__init__.py b/esphome/components/mqtt_subscribe/text_sensor/__init__.py index d432ef8a931..5b195778c55 100644 --- a/esphome/components/mqtt_subscribe/text_sensor/__init__.py +++ b/esphome/components/mqtt_subscribe/text_sensor/__init__.py @@ -31,7 +31,6 @@ async def to_code(config: ConfigType) -> None: var = await text_sensor.new_text_sensor(config) await cg.register_component(var, config) - parent = await cg.get_variable(config[CONF_MQTT_PARENT_ID]) - cg.add(var.set_parent(parent)) + await cg.register_parented(var, config[CONF_MQTT_PARENT_ID]) cg.add(var.set_topic(config[CONF_TOPIC])) cg.add(var.set_qos(config[CONF_QOS])) diff --git a/esphome/components/my9231/output.py b/esphome/components/my9231/output.py index c2ec15d411b..1516640e0e7 100644 --- a/esphome/components/my9231/output.py +++ b/esphome/components/my9231/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_MY9231_ID]) - cg.add(var.set_parent(parent)) + await cg.register_parented(var, config[CONF_MY9231_ID]) cg.add(var.set_channel(config[CONF_CHANNEL])) diff --git a/esphome/components/nextion/base_component.py b/esphome/components/nextion/base_component.py index 17c1b263ed8..442eb979158 100644 --- a/esphome/components/nextion/base_component.py +++ b/esphome/components/nextion/base_component.py @@ -116,21 +116,17 @@ async def setup_component_core_(var, config, arg): ) ) - if CONF_BACKGROUND_COLOR in config: - color_component = await cg.get_variable(config[CONF_BACKGROUND_COLOR]) - cg.add(var.set_background_color(color_component)) + await cg.add_variable(var.set_background_color, config.get(CONF_BACKGROUND_COLOR)) - if CONF_BACKGROUND_PRESSED_COLOR in config: - color_component = await cg.get_variable(config[CONF_BACKGROUND_PRESSED_COLOR]) - cg.add(var.set_background_pressed_color(color_component)) + await cg.add_variable( + var.set_background_pressed_color, config.get(CONF_BACKGROUND_PRESSED_COLOR) + ) - if CONF_FOREGROUND_COLOR in config: - color_component = await cg.get_variable(config[CONF_FOREGROUND_COLOR]) - cg.add(var.set_foreground_color(color_component)) + await cg.add_variable(var.set_foreground_color, config.get(CONF_FOREGROUND_COLOR)) - if CONF_FOREGROUND_PRESSED_COLOR in config: - color_component = await cg.get_variable(config[CONF_FOREGROUND_PRESSED_COLOR]) - cg.add(var.set_foreground_pressed_color(color_component)) + await cg.add_variable( + var.set_foreground_pressed_color, config.get(CONF_FOREGROUND_PRESSED_COLOR) + ) if CONF_FONT_ID in config: cg.add(var.set_font_id(config[CONF_FONT_ID])) diff --git a/esphome/components/ntc/sensor.py b/esphome/components/ntc/sensor.py index 6c2cb699901..9ac69b595f6 100644 --- a/esphome/components/ntc/sensor.py +++ b/esphome/components/ntc/sensor.py @@ -138,8 +138,7 @@ 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_sensor(sens)) + await cg.add_variable(var.set_sensor, config[CONF_SENSOR]) calib = config[CONF_CALIBRATION] cg.add(var.set_a(calib[CONF_A])) cg.add(var.set_b(calib[CONF_B])) diff --git a/esphome/components/one_wire/__init__.py b/esphome/components/one_wire/__init__.py index 69368a990ad..4a8edc656e2 100644 --- a/esphome/components/one_wire/__init__.py +++ b/esphome/components/one_wire/__init__.py @@ -37,8 +37,7 @@ async def register_one_wire_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_ONE_WIRE_ID]) - cg.add(var.set_one_wire_bus(parent)) + await cg.add_variable(var.set_one_wire_bus, config[CONF_ONE_WIRE_ID]) if (address := config.get(CONF_ADDRESS)) is not None: cg.add(var.set_address(address)) if (index := config.get(CONF_INDEX)) is not None: diff --git a/esphome/components/opentherm/__init__.py b/esphome/components/opentherm/__init__.py index 3772034ab63..309d35aac19 100644 --- a/esphome/components/opentherm/__init__.py +++ b/esphome/components/opentherm/__init__.py @@ -103,8 +103,9 @@ async def to_code(config: dict[str, Any]) -> None: if key in non_sensors: continue if key in schema.INPUTS: - input_sensor = await cg.get_variable(value) - cg.add(getattr(var, f"set_{key}_{const.INPUT_SENSOR}")(input_sensor)) + await cg.add_variable( + getattr(var, f"set_{key}_{const.INPUT_SENSOR}"), value + ) input_sensors.append(key) elif key in schema.SETTINGS: if value == schema.SETTINGS[key].default_value: diff --git a/esphome/components/output/__init__.py b/esphome/components/output/__init__.py index 1b794037848..ff7f55586da 100644 --- a/esphome/components/output/__init__.py +++ b/esphome/components/output/__init__.py @@ -59,9 +59,7 @@ FloatOutputPtr = FloatOutput.operator("ptr") async def setup_output_platform_(obj, config): if CONF_INVERTED in config: cg.add(obj.set_inverted(config[CONF_INVERTED])) - if CONF_POWER_SUPPLY in config: - power_supply_ = await cg.get_variable(config[CONF_POWER_SUPPLY]) - cg.add(obj.set_power_supply(power_supply_)) + await cg.add_variable(obj.set_power_supply, config.get(CONF_POWER_SUPPLY)) # The C++ initializers are max_power 1.0 and min_power 0.0; skip the setter when # the config matches them. The define stays whenever the key is present because # platforms such as ac_dimmer read the scaling fields directly. diff --git a/esphome/components/output/button/__init__.py b/esphome/components/output/button/__init__.py index 1d14fa5755f..95ad18a56b9 100644 --- a/esphome/components/output/button/__init__.py +++ b/esphome/components/output/button/__init__.py @@ -23,8 +23,7 @@ async def to_code(config): var = cg.new_Pvariable(config[CONF_ID]) cg.add(var.set_duration(config[CONF_DURATION])) - output_ = await cg.get_variable(config[CONF_OUTPUT]) - cg.add(var.set_output(output_)) + await cg.add_variable(var.set_output, config[CONF_OUTPUT]) await cg.register_component(var, config) await button.register_button(var, config) diff --git a/esphome/components/output/lock/__init__.py b/esphome/components/output/lock/__init__.py index 553114b689c..ffca1a5c47c 100644 --- a/esphome/components/output/lock/__init__.py +++ b/esphome/components/output/lock/__init__.py @@ -22,5 +22,4 @@ async def to_code(config): var = await lock.new_lock(config) await cg.register_component(var, config) - output_ = await cg.get_variable(config[CONF_OUTPUT]) - cg.add(var.set_output(output_)) + await cg.add_variable(var.set_output, config[CONF_OUTPUT]) diff --git a/esphome/components/output/switch/__init__.py b/esphome/components/output/switch/__init__.py index e896b183cad..6d46f8b2d5e 100644 --- a/esphome/components/output/switch/__init__.py +++ b/esphome/components/output/switch/__init__.py @@ -25,5 +25,4 @@ async def to_code(config): var = await switch.new_switch(config) await cg.register_component(var, config) - output_ = await cg.get_variable(config[CONF_OUTPUT]) - cg.add(var.set_output(output_)) + await cg.add_variable(var.set_output, config[CONF_OUTPUT]) diff --git a/esphome/components/pid/climate.py b/esphome/components/pid/climate.py index 1527fa6f354..a6b5641eb70 100644 --- a/esphome/components/pid/climate.py +++ b/esphome/components/pid/climate.py @@ -100,19 +100,10 @@ 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)) - - if CONF_COOL_OUTPUT in config: - out = await cg.get_variable(config[CONF_COOL_OUTPUT]) - cg.add(var.set_cool_output(out)) - if CONF_HEAT_OUTPUT in config: - out = await cg.get_variable(config[CONF_HEAT_OUTPUT]) - cg.add(var.set_heat_output(out)) + await cg.add_variable(var.set_sensor, config[CONF_SENSOR]) + await cg.add_variable(var.set_humidity_sensor, config.get(CONF_HUMIDITY_SENSOR)) + await cg.add_variable(var.set_cool_output, config.get(CONF_COOL_OUTPUT)) + await cg.add_variable(var.set_heat_output, config.get(CONF_HEAT_OUTPUT)) params = config[CONF_CONTROL_PARAMETERS] cg.add(var.set_kp(params[CONF_KP])) cg.add(var.set_ki(params[CONF_KI])) diff --git a/esphome/components/pvvx_mithermometer/display/__init__.py b/esphome/components/pvvx_mithermometer/display/__init__.py index 1b8c0b5be30..dcbb749d400 100644 --- a/esphome/components/pvvx_mithermometer/display/__init__.py +++ b/esphome/components/pvvx_mithermometer/display/__init__.py @@ -44,8 +44,6 @@ async def to_code(config: ConfigType) -> None: cg.add(var.set_auto_clear(config[CONF_AUTO_CLEAR_ENABLED])) cg.add(var.set_validity_period(config[CONF_VALIDITY_PERIOD].total_seconds)) - if CONF_TIME_ID in config: - time_ = await cg.get_variable(config[CONF_TIME_ID]) - cg.add(var.set_time(time_)) + await cg.add_variable(var.set_time, config.get(CONF_TIME_ID)) await display.add_writer(var, config, PVVXDisplayRef) diff --git a/esphome/components/remote_base/__init__.py b/esphome/components/remote_base/__init__.py index 990d2b87e4d..b01b0f3645e 100644 --- a/esphome/components/remote_base/__init__.py +++ b/esphome/components/remote_base/__init__.py @@ -154,8 +154,7 @@ async def attach_receiver( async def register_transmittable(var, config, key: str = CONF_TRANSMITTER_ID): - transmitter_ = await cg.get_variable(config[key]) - cg.add(var.set_transmitter(transmitter_)) + await cg.add_variable(var.set_transmitter, config[key]) # Registry names that share a protocol source file diff --git a/esphome/components/resampler/speaker/__init__.py b/esphome/components/resampler/speaker/__init__.py index 8fa8aeb61c4..5b82f149799 100644 --- a/esphome/components/resampler/speaker/__init__.py +++ b/esphome/components/resampler/speaker/__init__.py @@ -86,8 +86,7 @@ async def to_code(config: ConfigType) -> None: await cg.register_component(var, config) await speaker.register_speaker(var, config) - output_spkr = await cg.get_variable(config[CONF_OUTPUT_SPEAKER]) - cg.add(var.set_output_speaker(output_spkr)) + await cg.add_variable(var.set_output_speaker, config[CONF_OUTPUT_SPEAKER]) cg.add(var.set_buffer_duration(config[CONF_BUFFER_DURATION])) diff --git a/esphome/components/resistance/sensor.py b/esphome/components/resistance/sensor.py index cbf329713df..c76d910df53 100644 --- a/esphome/components/resistance/sensor.py +++ b/esphome/components/resistance/sensor.py @@ -43,8 +43,7 @@ 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_sensor(sens)) + await cg.add_variable(var.set_sensor, config[CONF_SENSOR]) cg.add(var.set_configuration(config[CONF_CONFIGURATION])) cg.add(var.set_resistor(config[CONF_RESISTOR])) cg.add(var.set_reference_voltage(config[CONF_REFERENCE_VOLTAGE])) diff --git a/esphome/components/rgb/light.py b/esphome/components/rgb/light.py index cd553292569..0a1ec2eddef 100644 --- a/esphome/components/rgb/light.py +++ b/esphome/components/rgb/light.py @@ -21,9 +21,6 @@ async def to_code(config: ConfigType) -> None: var = cg.new_Pvariable(config[CONF_OUTPUT_ID]) await light.register_light(var, config) - red = await cg.get_variable(config[CONF_RED]) - cg.add(var.set_red(red)) - green = await cg.get_variable(config[CONF_GREEN]) - cg.add(var.set_green(green)) - blue = await cg.get_variable(config[CONF_BLUE]) - cg.add(var.set_blue(blue)) + await cg.add_variable(var.set_red, config[CONF_RED]) + await cg.add_variable(var.set_green, config[CONF_GREEN]) + await cg.add_variable(var.set_blue, config[CONF_BLUE]) diff --git a/esphome/components/rgbct/light.py b/esphome/components/rgbct/light.py index 00626ec6ba2..43e31a011bf 100644 --- a/esphome/components/rgbct/light.py +++ b/esphome/components/rgbct/light.py @@ -42,17 +42,11 @@ async def to_code(config: ConfigType) -> None: var = cg.new_Pvariable(config[CONF_OUTPUT_ID]) await light.register_light(var, config) - red = await cg.get_variable(config[CONF_RED]) - cg.add(var.set_red(red)) - green = await cg.get_variable(config[CONF_GREEN]) - cg.add(var.set_green(green)) - blue = await cg.get_variable(config[CONF_BLUE]) - cg.add(var.set_blue(blue)) - - color_temp = await cg.get_variable(config[CONF_COLOR_TEMPERATURE]) - cg.add(var.set_color_temperature(color_temp)) - white_brightness = await cg.get_variable(config[CONF_WHITE_BRIGHTNESS]) - cg.add(var.set_white_brightness(white_brightness)) + await cg.add_variable(var.set_red, config[CONF_RED]) + await cg.add_variable(var.set_green, config[CONF_GREEN]) + await cg.add_variable(var.set_blue, config[CONF_BLUE]) + await cg.add_variable(var.set_color_temperature, config[CONF_COLOR_TEMPERATURE]) + await cg.add_variable(var.set_white_brightness, config[CONF_WHITE_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/rgbw/light.py b/esphome/components/rgbw/light.py index 7aedf4affc3..2875eba1978 100644 --- a/esphome/components/rgbw/light.py +++ b/esphome/components/rgbw/light.py @@ -30,12 +30,8 @@ async def to_code(config: ConfigType) -> None: var = cg.new_Pvariable(config[CONF_OUTPUT_ID]) await light.register_light(var, config) - red = await cg.get_variable(config[CONF_RED]) - cg.add(var.set_red(red)) - green = await cg.get_variable(config[CONF_GREEN]) - cg.add(var.set_green(green)) - blue = await cg.get_variable(config[CONF_BLUE]) - cg.add(var.set_blue(blue)) - white = await cg.get_variable(config[CONF_WHITE]) - cg.add(var.set_white(white)) + await cg.add_variable(var.set_red, config[CONF_RED]) + await cg.add_variable(var.set_green, config[CONF_GREEN]) + await cg.add_variable(var.set_blue, config[CONF_BLUE]) + await cg.add_variable(var.set_white, config[CONF_WHITE]) cg.add(var.set_color_interlock(config[CONF_COLOR_INTERLOCK])) diff --git a/esphome/components/rgbww/light.py b/esphome/components/rgbww/light.py index 3626a57b8c1..8881af6af45 100644 --- a/esphome/components/rgbww/light.py +++ b/esphome/components/rgbww/light.py @@ -45,22 +45,16 @@ async def to_code(config: ConfigType) -> None: var = cg.new_Pvariable(config[CONF_OUTPUT_ID]) await light.register_light(var, config) - red = await cg.get_variable(config[CONF_RED]) - cg.add(var.set_red(red)) - green = await cg.get_variable(config[CONF_GREEN]) - cg.add(var.set_green(green)) - blue = await cg.get_variable(config[CONF_BLUE]) - cg.add(var.set_blue(blue)) - - cwhite = await cg.get_variable(config[CONF_COLD_WHITE]) - cg.add(var.set_cold_white(cwhite)) + await cg.add_variable(var.set_red, config[CONF_RED]) + await cg.add_variable(var.set_green, config[CONF_GREEN]) + await cg.add_variable(var.set_blue, config[CONF_BLUE]) + await cg.add_variable(var.set_cold_white, config[CONF_COLD_WHITE]) if CONF_COLD_WHITE_COLOR_TEMPERATURE in config: cg.add( var.set_cold_white_temperature(config[CONF_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 CONF_WARM_WHITE_COLOR_TEMPERATURE in config: cg.add( var.set_warm_white_temperature(config[CONF_WARM_WHITE_COLOR_TEMPERATURE]) diff --git a/esphome/components/router/speaker/__init__.py b/esphome/components/router/speaker/__init__.py index f568aedcbdf..90e9febed5c 100644 --- a/esphome/components/router/speaker/__init__.py +++ b/esphome/components/router/speaker/__init__.py @@ -86,8 +86,7 @@ async def to_code(config: ConfigType) -> None: speakers = config[CONF_OUTPUT_SPEAKERS] cg.add(var.set_output_count(len(speakers))) for spk_id in speakers: - spk = await cg.get_variable(spk_id) - cg.add(var.add_output(spk)) + await cg.add_variable(var.add_output, spk_id) automation.register_apply_action( diff --git a/esphome/components/rp2_ble_tracker/__init__.py b/esphome/components/rp2_ble_tracker/__init__.py index 4a3d3f788bf..fdfc2a1f967 100644 --- a/esphome/components/rp2_ble_tracker/__init__.py +++ b/esphome/components/rp2_ble_tracker/__init__.py @@ -95,8 +95,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_RP2040_BLE_ID]) - cg.add(var.set_parent(parent)) + await cg.register_parented(var, config[CONF_RP2040_BLE_ID]) # The tracker registers itself as a controller scan listener in setup(); # request the codegen-sized StaticVector slot for it. rp2040_ble.request_scan_listener_slot() diff --git a/esphome/components/rtttl/__init__.py b/esphome/components/rtttl/__init__.py index 8bff8bb58dc..c987e0327c5 100644 --- a/esphome/components/rtttl/__init__.py +++ b/esphome/components/rtttl/__init__.py @@ -84,13 +84,10 @@ async def to_code(config: ConfigType) -> None: await cg.register_component(var, config) if CONF_OUTPUT in 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]) cg.add_define("USE_OUTPUT") - if CONF_SPEAKER in config: - out = await cg.get_variable(config[CONF_SPEAKER]) - cg.add(var.set_speaker(out)) + await cg.add_variable(var.set_speaker, config.get(CONF_SPEAKER)) cg.add(var.set_gain(config[CONF_GAIN])) diff --git a/esphome/components/safe_mode/button/__init__.py b/esphome/components/safe_mode/button/__init__.py index 89e24757996..d0ef080f10e 100644 --- a/esphome/components/safe_mode/button/__init__.py +++ b/esphome/components/safe_mode/button/__init__.py @@ -31,5 +31,4 @@ async def to_code(config: ConfigType) -> None: var = await button.new_button(config) await cg.register_component(var, config) - safe_mode_component = await cg.get_variable(config[CONF_SAFE_MODE]) - cg.add(var.set_safe_mode(safe_mode_component)) + await cg.add_variable(var.set_safe_mode, config[CONF_SAFE_MODE]) diff --git a/esphome/components/safe_mode/switch/__init__.py b/esphome/components/safe_mode/switch/__init__.py index 529b023d689..432d7a76154 100644 --- a/esphome/components/safe_mode/switch/__init__.py +++ b/esphome/components/safe_mode/switch/__init__.py @@ -26,5 +26,4 @@ async def to_code(config: ConfigType) -> None: var = await switch.new_switch(config) await cg.register_component(var, config) - safe_mode_component = await cg.get_variable(config[CONF_SAFE_MODE]) - cg.add(var.set_safe_mode(safe_mode_component)) + await cg.add_variable(var.set_safe_mode, config[CONF_SAFE_MODE]) diff --git a/esphome/components/scd4x/sensor.py b/esphome/components/scd4x/sensor.py index 12a07a3f63a..4b67319efb1 100644 --- a/esphome/components/scd4x/sensor.py +++ b/esphome/components/scd4x/sensor.py @@ -112,9 +112,10 @@ async def to_code(config: ConfigType) -> None: sens = await sensor.new_sensor(config[key]) cg.add(getattr(var, funcName)(sens)) - if CONF_AMBIENT_PRESSURE_COMPENSATION_SOURCE in config: - sens = await cg.get_variable(config[CONF_AMBIENT_PRESSURE_COMPENSATION_SOURCE]) - cg.add(var.set_ambient_pressure_source(sens)) + await cg.add_variable( + var.set_ambient_pressure_source, + config.get(CONF_AMBIENT_PRESSURE_COMPENSATION_SOURCE), + ) cg.add(var.set_measurement_mode(config[CONF_MEASUREMENT_MODE])) diff --git a/esphome/components/sen6x/sensor.py b/esphome/components/sen6x/sensor.py index b928f97774e..d961d05bc85 100644 --- a/esphome/components/sen6x/sensor.py +++ b/esphome/components/sen6x/sensor.py @@ -326,11 +326,10 @@ async def to_code(config: ConfigType) -> None: cg.add(var.set_altitude_compensation(altitude)) if (pressure := co2_cfg.get(CONF_AMBIENT_PRESSURE_COMPENSATION)) is not None: cg.add(var.set_ambient_pressure_compensation(pressure)) - if ( - source := co2_cfg.get(CONF_AMBIENT_PRESSURE_COMPENSATION_SOURCE) - ) is not None: - sens = await cg.get_variable(source) - cg.add(var.set_ambient_pressure_source(sens)) + await cg.add_variable( + var.set_ambient_pressure_source, + co2_cfg.get(CONF_AMBIENT_PRESSURE_COMPENSATION_SOURCE), + ) SEN6X_ACTION_SCHEMA = maybe_simple_id( diff --git a/esphome/components/sendspin/__init__.py b/esphome/components/sendspin/__init__.py index c557a7960d2..3caad51f919 100644 --- a/esphome/components/sendspin/__init__.py +++ b/esphome/components/sendspin/__init__.py @@ -428,8 +428,7 @@ async def to_code(config: ConfigType) -> None: # Service starts disabled and the hub enables it; always advertised where unsupported if mdns.request_service_enable_disable(): - mdns_var = await cg.get_variable(CORE.config[MDNS_DOMAIN][CONF_ID]) - cg.add(var.set_mdns(mdns_var)) + await cg.add_variable(var.set_mdns, CORE.config[MDNS_DOMAIN][CONF_ID]) data = _get_data() diff --git a/esphome/components/serial_proxy/__init__.py b/esphome/components/serial_proxy/__init__.py index 27d69c97346..d1b4e889066 100644 --- a/esphome/components/serial_proxy/__init__.py +++ b/esphome/components/serial_proxy/__init__.py @@ -101,12 +101,10 @@ async def to_code(config: ConfigType) -> None: # port_type names the electrical interface (a USB RS485 adapter is RS485), so every # usb_uart channel reports USB identity whatever port type it declares if is_usb_uart_channel(config[CONF_UART_ID], CORE.config): - channel = await cg.get_variable(config[CONF_UART_ID]) - cg.add(var.set_usb_channel(channel)) + await cg.add_variable(var.set_usb_channel, config[CONF_UART_ID]) cg.add_define("USE_SERIAL_PROXY_USB_IDENTITY") if uart.is_host_uart(config[CONF_UART_ID], CORE.config): - host_uart = await cg.get_variable(config[CONF_UART_ID]) - cg.add(var.set_host_uart(host_uart)) + await cg.add_variable(var.set_host_uart, config[CONF_UART_ID]) cg.add_define("USE_SERIAL_PROXY_HOST_UART") cg.add_define("USE_SERIAL_PROXY") diff --git a/esphome/components/servo/__init__.py b/esphome/components/servo/__init__.py index 44ec294765b..fdfb892d3e1 100644 --- a/esphome/components/servo/__init__.py +++ b/esphome/components/servo/__init__.py @@ -43,8 +43,7 @@ async def to_code(config: ConfigType) -> None: var = cg.new_Pvariable(config[CONF_ID]) await cg.register_component(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]) cg.add(var.set_min_level(config[CONF_MIN_LEVEL])) cg.add(var.set_idle_level(config[CONF_IDLE_LEVEL])) cg.add(var.set_max_level(config[CONF_MAX_LEVEL])) diff --git a/esphome/components/sgp30/sensor.py b/esphome/components/sgp30/sensor.py index 5d4c43fccae..87b0d3aa2c0 100644 --- a/esphome/components/sgp30/sensor.py +++ b/esphome/components/sgp30/sensor.py @@ -98,7 +98,9 @@ async def to_code(config: ConfigType) -> None: cg.add(var.set_tvoc_baseline(baseline_config[CONF_TVOC_BASELINE])) if compensation_config := config.get(CONF_COMPENSATION): - sens = await cg.get_variable(compensation_config[CONF_HUMIDITY_SOURCE]) - cg.add(var.set_humidity_sensor(sens)) - sens = await cg.get_variable(compensation_config[CONF_TEMPERATURE_SOURCE]) - cg.add(var.set_temperature_sensor(sens)) + await cg.add_variable( + var.set_humidity_sensor, compensation_config[CONF_HUMIDITY_SOURCE] + ) + await cg.add_variable( + var.set_temperature_sensor, compensation_config[CONF_TEMPERATURE_SOURCE] + ) diff --git a/esphome/components/sgp4x/sensor.py b/esphome/components/sgp4x/sensor.py index 866445f2464..78792c80102 100644 --- a/esphome/components/sgp4x/sensor.py +++ b/esphome/components/sgp4x/sensor.py @@ -103,10 +103,12 @@ async def to_code(config: ConfigType) -> None: if CONF_COMPENSATION in config: compensation_config = config[CONF_COMPENSATION] - sens = await cg.get_variable(compensation_config[CONF_HUMIDITY_SOURCE]) - cg.add(var.set_humidity_sensor(sens)) - sens = await cg.get_variable(compensation_config[CONF_TEMPERATURE_SOURCE]) - cg.add(var.set_temperature_sensor(sens)) + await cg.add_variable( + var.set_humidity_sensor, compensation_config[CONF_HUMIDITY_SOURCE] + ) + await cg.add_variable( + var.set_temperature_sensor, compensation_config[CONF_TEMPERATURE_SOURCE] + ) cg.add(var.set_store_baseline(config[CONF_STORE_BASELINE])) diff --git a/esphome/components/sm16716/output.py b/esphome/components/sm16716/output.py index 08cec24fd64..c4f6981c04e 100644 --- a/esphome/components/sm16716/output.py +++ b/esphome/components/sm16716/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_SM16716_ID]) - cg.add(var.set_parent(parent)) + await cg.register_parented(var, config[CONF_SM16716_ID]) cg.add(var.set_channel(config[CONF_CHANNEL])) diff --git a/esphome/components/sm2135/output.py b/esphome/components/sm2135/output.py index 80b4cb1a4f2..b7a49374045 100644 --- a/esphome/components/sm2135/output.py +++ b/esphome/components/sm2135/output.py @@ -25,6 +25,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_SM2135_ID]) - cg.add(var.set_parent(parent)) + await cg.register_parented(var, config[CONF_SM2135_ID]) cg.add(var.set_channel(config[CONF_CHANNEL])) diff --git a/esphome/components/sm2235/output.py b/esphome/components/sm2235/output.py index 29940a651e8..be590a3bd95 100644 --- a/esphome/components/sm2235/output.py +++ b/esphome/components/sm2235/output.py @@ -25,6 +25,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_SM2235_ID]) - cg.add(var.set_parent(parent)) + await cg.register_parented(var, config[CONF_SM2235_ID]) cg.add(var.set_channel(config[CONF_CHANNEL])) diff --git a/esphome/components/sm2335/output.py b/esphome/components/sm2335/output.py index 30f653b087a..ce047cbb96e 100644 --- a/esphome/components/sm2335/output.py +++ b/esphome/components/sm2335/output.py @@ -25,6 +25,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_SM2335_ID]) - cg.add(var.set_parent(parent)) + await cg.register_parented(var, config[CONF_SM2335_ID]) cg.add(var.set_channel(config[CONF_CHANNEL])) diff --git a/esphome/components/speaker/__init__.py b/esphome/components/speaker/__init__.py index d34cfc32c0f..e1df66f6841 100644 --- a/esphome/components/speaker/__init__.py +++ b/esphome/components/speaker/__init__.py @@ -22,9 +22,7 @@ PlayAction = speaker_ns.class_( async def setup_speaker_core_(var, config): - if audio_dac_config := config.get(CONF_AUDIO_DAC): - aud_dac = await cg.get_variable(audio_dac_config) - cg.add(var.set_audio_dac(aud_dac)) + await cg.add_variable(var.set_audio_dac, config.get(CONF_AUDIO_DAC)) async def register_speaker(var, config): diff --git a/esphome/components/speaker/media_player/__init__.py b/esphome/components/speaker/media_player/__init__.py index b37a288d874..83f406e9e65 100644 --- a/esphome/components/speaker/media_player/__init__.py +++ b/esphome/components/speaker/media_player/__init__.py @@ -184,8 +184,9 @@ async def to_code(config): cg.add(var.set_volume_min(config[CONF_VOLUME_MIN])) announcement_pipeline_config = config[CONF_ANNOUNCEMENT_PIPELINE] - spkr = await cg.get_variable(announcement_pipeline_config[CONF_SPEAKER]) - cg.add(var.set_announcement_speaker(spkr)) + await cg.add_variable( + var.set_announcement_speaker, announcement_pipeline_config[CONF_SPEAKER] + ) if announcement_pipeline_config[CONF_FORMAT] != "NONE": cg.add( var.set_announcement_format( @@ -196,8 +197,9 @@ async def to_code(config): ) if media_pipeline_config := config.get(CONF_MEDIA_PIPELINE): - spkr = await cg.get_variable(media_pipeline_config[CONF_SPEAKER]) - cg.add(var.set_media_speaker(spkr)) + await cg.add_variable( + var.set_media_speaker, media_pipeline_config[CONF_SPEAKER] + ) if media_pipeline_config[CONF_FORMAT] != "NONE": cg.add( var.set_media_format( diff --git a/esphome/components/spi/__init__.py b/esphome/components/spi/__init__.py index 151f228651e..8ff1842a7c1 100644 --- a/esphome/components/spi/__init__.py +++ b/esphome/components/spi/__init__.py @@ -484,8 +484,7 @@ def spi_device_schema( async def register_spi_device( var: cg.MockObj, config: ConfigType, write_only: bool = False ) -> None: - parent = await cg.get_variable(config[CONF_SPI_ID]) - cg.add(var.set_spi_parent(parent)) + await cg.add_variable(var.set_spi_parent, config[CONF_SPI_ID]) if write_only: cg.add(var.set_write_only(True)) await cg.add_pin(var.set_cs_pin, config.get(CONF_CS_PIN)) diff --git a/esphome/components/sprinkler/__init__.py b/esphome/components/sprinkler/__init__.py index fe096514d07..557b24505bd 100644 --- a/esphome/components/sprinkler/__init__.py +++ b/esphome/components/sprinkler/__init__.py @@ -733,8 +733,4 @@ async def to_code(config): var = await cg.get_variable(sprinkler_controller[CONF_ID]) for controller_to_add in config: if sprinkler_controller[CONF_ID] != controller_to_add[CONF_ID]: - cg.add( - var.add_controller( - await cg.get_variable(controller_to_add[CONF_ID]) - ) - ) + await cg.add_variable(var.add_controller, controller_to_add[CONF_ID]) diff --git a/esphome/components/stcc4/sensor.py b/esphome/components/stcc4/sensor.py index b103aa39534..4ea1bc6ed81 100644 --- a/esphome/components/stcc4/sensor.py +++ b/esphome/components/stcc4/sensor.py @@ -107,13 +107,11 @@ async def to_code(config: ConfigType) -> None: await sensors(CONF_TEMPERATURE, var.set_temperature_sensor) await sensors(CONF_HUMIDITY, var.set_humidity_sensor) - if (temperature_source := config.get(CONF_TEMPERATURE_SOURCE)) is not None: - sens = await cg.get_variable(temperature_source) - cg.add(var.set_temperature_source(sens)) + await cg.add_variable( + var.set_temperature_source, config.get(CONF_TEMPERATURE_SOURCE) + ) - if (humidity_source := config.get(CONF_HUMIDITY_SOURCE)) is not None: - sens = await cg.get_variable(humidity_source) - cg.add(var.set_humidity_source(sens)) + await cg.add_variable(var.set_humidity_source, config.get(CONF_HUMIDITY_SOURCE)) if ( ambient_pressure_compensation := config.get(CONF_AMBIENT_PRESSURE_COMPENSATION) @@ -124,12 +122,9 @@ async def to_code(config: ConfigType) -> None: ) ) - if ( - ambient_pressure_compensation_source := config.get( - CONF_AMBIENT_PRESSURE_COMPENSATION_SOURCE - ) - ) is not None: - sens = await cg.get_variable(ambient_pressure_compensation_source) - cg.add(var.set_ambient_pressure_source(sens)) + await cg.add_variable( + var.set_ambient_pressure_source, + config.get(CONF_AMBIENT_PRESSURE_COMPENSATION_SOURCE), + ) cg.add(var.set_measurement_mode(config[CONF_MEASUREMENT_MODE])) diff --git a/esphome/components/sun/__init__.py b/esphome/components/sun/__init__.py index 71441e97823..c104316d475 100644 --- a/esphome/components/sun/__init__.py +++ b/esphome/components/sun/__init__.py @@ -118,8 +118,7 @@ CONFIG_SCHEMA = cv.Schema( async def to_code(config: ConfigType) -> None: var = cg.new_Pvariable(config[CONF_ID]) - 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]) cg.add(var.set_latitude(config[CONF_LATITUDE])) cg.add(var.set_longitude(config[CONF_LONGITUDE])) diff --git a/esphome/components/sun/sensor/__init__.py b/esphome/components/sun/sensor/__init__.py index ef4e51d5e5e..b6981422a05 100644 --- a/esphome/components/sun/sensor/__init__.py +++ b/esphome/components/sun/sensor/__init__.py @@ -40,5 +40,4 @@ async def to_code(config: ConfigType) -> None: await cg.register_component(var, config) cg.add(var.set_type(config[CONF_TYPE])) - paren = await cg.get_variable(config[CONF_SUN_ID]) - cg.add(var.set_parent(paren)) + await cg.register_parented(var, config[CONF_SUN_ID]) diff --git a/esphome/components/sun/text_sensor/__init__.py b/esphome/components/sun/text_sensor/__init__.py index 523471bd41e..b7db7cd39d9 100644 --- a/esphome/components/sun/text_sensor/__init__.py +++ b/esphome/components/sun/text_sensor/__init__.py @@ -53,8 +53,7 @@ async def to_code(config: ConfigType) -> None: var = await text_sensor.new_text_sensor(config) await cg.register_component(var, config) - paren = await cg.get_variable(config[CONF_SUN_ID]) - cg.add(var.set_parent(paren)) + await cg.register_parented(var, config[CONF_SUN_ID]) cg.add(var.set_sunrise(SUN_TYPES[config[CONF_TYPE]])) cg.add(var.set_elevation(config[CONF_ELEVATION])) cg.add(var.set_format(config[CONF_FORMAT])) diff --git a/esphome/components/switch/binary_sensor/__init__.py b/esphome/components/switch/binary_sensor/__init__.py index 61ca1a14a24..ece53c0deb3 100644 --- a/esphome/components/switch/binary_sensor/__init__.py +++ b/esphome/components/switch/binary_sensor/__init__.py @@ -27,5 +27,4 @@ async def to_code(config): 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/sx126x/packet_transport/__init__.py b/esphome/components/sx126x/packet_transport/__init__.py index fc3bbf6df25..0c3ec56fcc0 100644 --- a/esphome/components/sx126x/packet_transport/__init__.py +++ b/esphome/components/sx126x/packet_transport/__init__.py @@ -23,5 +23,4 @@ CONFIG_SCHEMA = transport_schema(SX126xTransport).extend( async def to_code(config: ConfigType) -> None: var, _ = await new_packet_transport(config) - sx126x = await cg.get_variable(config[CONF_SX126X_ID]) - cg.add(var.set_parent(sx126x)) + await cg.register_parented(var, config[CONF_SX126X_ID]) diff --git a/esphome/components/sx127x/packet_transport/__init__.py b/esphome/components/sx127x/packet_transport/__init__.py index 33204a7d83d..0ec1a0f6950 100644 --- a/esphome/components/sx127x/packet_transport/__init__.py +++ b/esphome/components/sx127x/packet_transport/__init__.py @@ -23,5 +23,4 @@ CONFIG_SCHEMA = transport_schema(SX127xTransport).extend( async def to_code(config: ConfigType) -> None: var, _ = await new_packet_transport(config) - sx127x = await cg.get_variable(config[CONF_SX127X_ID]) - cg.add(var.set_parent(sx127x)) + await cg.register_parented(var, config[CONF_SX127X_ID]) diff --git a/esphome/components/thermostat/climate.py b/esphome/components/thermostat/climate.py index bebdd7d0660..3e6d63adbb7 100644 --- a/esphome/components/thermostat/climate.py +++ b/esphome/components/thermostat/climate.py @@ -716,9 +716,7 @@ async def to_code(config: ConfigType) -> None: ) 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_humidity_sensor, config.get(CONF_HUMIDITY_SENSOR)) cg.add(var.set_cool_deadband(config[CONF_COOL_DEADBAND])) cg.add(var.set_cool_overrun(config[CONF_COOL_OVERRUN])) diff --git a/esphome/components/tm1638/output/__init__.py b/esphome/components/tm1638/output/__init__.py index 961abfee476..4b85e73c88b 100644 --- a/esphome/components/tm1638/output/__init__.py +++ b/esphome/components/tm1638/output/__init__.py @@ -23,5 +23,4 @@ async def to_code(config: ConfigType) -> None: await output.register_output(var, config) await cg.register_component(var, config) cg.add(var.set_lednum(config[CONF_LED])) - hub = await cg.get_variable(config[CONF_TM1638_ID]) - cg.add(var.set_tm1638(hub)) + await cg.add_variable(var.set_tm1638, config[CONF_TM1638_ID]) diff --git a/esphome/components/tm1638/switch/__init__.py b/esphome/components/tm1638/switch/__init__.py index f42b835e039..eee55dc118e 100644 --- a/esphome/components/tm1638/switch/__init__.py +++ b/esphome/components/tm1638/switch/__init__.py @@ -25,5 +25,4 @@ async def to_code(config: ConfigType) -> None: var = await switch.new_switch(config) await cg.register_component(var, config) cg.add(var.set_lednum(config[CONF_LED])) - hub = await cg.get_variable(config[CONF_TM1638_ID]) - cg.add(var.set_tm1638(hub)) + await cg.add_variable(var.set_tm1638, config[CONF_TM1638_ID]) diff --git a/esphome/components/total_daily_energy/sensor.py b/esphome/components/total_daily_energy/sensor.py index af2f5ff561c..304688de07a 100644 --- a/esphome/components/total_daily_energy/sensor.py +++ b/esphome/components/total_daily_energy/sensor.py @@ -83,9 +83,7 @@ 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_POWER_ID]) - cg.add(var.set_parent(sens)) - time_ = await cg.get_variable(config[CONF_TIME_ID]) - cg.add(var.set_time(time_)) + await cg.register_parented(var, config[CONF_POWER_ID]) + await cg.add_variable(var.set_time, config[CONF_TIME_ID]) cg.add(var.set_restore(config[CONF_RESTORE])) cg.add(var.set_method(config[CONF_METHOD])) diff --git a/esphome/components/touchscreen/__init__.py b/esphome/components/touchscreen/__init__.py index 7a23d140690..36679e828b7 100644 --- a/esphome/components/touchscreen/__init__.py +++ b/esphome/components/touchscreen/__init__.py @@ -155,8 +155,7 @@ TOUCHSCREEN_SCHEMA = touchscreen_schema(cv.UNDEFINED) async def register_touchscreen(var: MockObj, config: ConfigType) -> None: await cg.register_component(var, config) - disp = await cg.get_variable(config[CONF_DISPLAY]) - cg.add(var.set_display(disp)) + await cg.add_variable(var.set_display, config[CONF_DISPLAY]) if CONF_TOUCH_TIMEOUT in config: cg.add(var.set_touch_timeout(config[CONF_TOUCH_TIMEOUT])) diff --git a/esphome/components/touchscreen/binary_sensor/__init__.py b/esphome/components/touchscreen/binary_sensor/__init__.py index 6a66d00ea6c..fccaf26c39a 100644 --- a/esphome/components/touchscreen/binary_sensor/__init__.py +++ b/esphome/components/touchscreen/binary_sensor/__init__.py @@ -83,5 +83,4 @@ async def to_code(config: ConfigType) -> None: ) for page_id in config.get(CONF_PAGES, []): - page = await cg.get_variable(page_id) - cg.add(var.add_page(page)) + await cg.add_variable(var.add_page, page_id) diff --git a/esphome/components/tuya/__init__.py b/esphome/components/tuya/__init__.py index 4a334e3e518..0ec7452e379 100644 --- a/esphome/components/tuya/__init__.py +++ b/esphome/components/tuya/__init__.py @@ -85,8 +85,7 @@ CONFIG_SCHEMA = cv.All( async def to_code(config): var = await uart.new_uart_component(config) if (time_id := config.get(CONF_TIME_ID)) is not None: - time_ = await cg.get_variable(time_id) - cg.add(var.set_time_id(time_)) + await cg.add_variable(var.set_time_id, time_id) if config[CONF_FORCE_TIME_SYNC]: cg.add(var.set_force_time_sync(True)) await cg.add_pin(var.set_status_pin, config.get(CONF_STATUS_PIN)) diff --git a/esphome/components/tuya/binary_sensor/__init__.py b/esphome/components/tuya/binary_sensor/__init__.py index 767d1c636e5..049386461af 100644 --- a/esphome/components/tuya/binary_sensor/__init__.py +++ b/esphome/components/tuya/binary_sensor/__init__.py @@ -28,7 +28,6 @@ async def to_code(config): var = await binary_sensor.new_binary_sensor(config) await cg.register_component(var, config) - paren = await cg.get_variable(config[CONF_TUYA_ID]) - cg.add(var.set_tuya_parent(paren)) + await cg.add_variable(var.set_tuya_parent, config[CONF_TUYA_ID]) cg.add(var.set_sensor_id(config[CONF_SENSOR_DATAPOINT])) diff --git a/esphome/components/tuya/climate/__init__.py b/esphome/components/tuya/climate/__init__.py index 91ef9a6a68a..65045e2cd27 100644 --- a/esphome/components/tuya/climate/__init__.py +++ b/esphome/components/tuya/climate/__init__.py @@ -196,8 +196,7 @@ async def to_code(config): var = await climate.new_climate(config) await cg.register_component(var, config) - paren = await cg.get_variable(config[CONF_TUYA_ID]) - cg.add(var.set_tuya_parent(paren)) + await cg.add_variable(var.set_tuya_parent, config[CONF_TUYA_ID]) cg.add(var.set_supports_heat(config[CONF_SUPPORTS_HEAT])) cg.add(var.set_supports_cool(config[CONF_SUPPORTS_COOL])) diff --git a/esphome/components/tuya/cover/__init__.py b/esphome/components/tuya/cover/__init__.py index 6e1daef884a..c93fdf55445 100644 --- a/esphome/components/tuya/cover/__init__.py +++ b/esphome/components/tuya/cover/__init__.py @@ -69,5 +69,4 @@ async def to_code(config): cg.add(var.set_invert_position(config[CONF_INVERT_POSITION])) cg.add(var.set_invert_position_report(config[CONF_INVERT_POSITION_REPORT])) cg.add(var.set_restore_mode(config[CONF_RESTORE_MODE])) - paren = await cg.get_variable(config[CONF_TUYA_ID]) - cg.add(var.set_tuya_parent(paren)) + await cg.add_variable(var.set_tuya_parent, config[CONF_TUYA_ID]) diff --git a/esphome/components/tuya/light/__init__.py b/esphome/components/tuya/light/__init__.py index 5ba55b6ccbb..9811995ad0c 100644 --- a/esphome/components/tuya/light/__init__.py +++ b/esphome/components/tuya/light/__init__.py @@ -112,5 +112,4 @@ async def to_code(config): ) cg.add(var.set_color_interlock(config[CONF_COLOR_INTERLOCK])) - paren = await cg.get_variable(config[CONF_TUYA_ID]) - cg.add(var.set_tuya_parent(paren)) + await cg.add_variable(var.set_tuya_parent, config[CONF_TUYA_ID]) diff --git a/esphome/components/tuya/number/__init__.py b/esphome/components/tuya/number/__init__.py index 7a61e69c5cf..dcc2c15347b 100644 --- a/esphome/components/tuya/number/__init__.py +++ b/esphome/components/tuya/number/__init__.py @@ -85,8 +85,7 @@ async def to_code(config): ) cg.add(var.set_write_multiply(config[CONF_MULTIPLY])) - parent = await cg.get_variable(config[CONF_TUYA_ID]) - cg.add(var.set_tuya_parent(parent)) + await cg.add_variable(var.set_tuya_parent, config[CONF_TUYA_ID]) cg.add(var.set_number_id(config[CONF_NUMBER_DATAPOINT])) if hidden_config := config.get(CONF_DATAPOINT_HIDDEN): diff --git a/esphome/components/tuya/select/__init__.py b/esphome/components/tuya/select/__init__.py index 9f2b6f1e12a..84819f8f497 100644 --- a/esphome/components/tuya/select/__init__.py +++ b/esphome/components/tuya/select/__init__.py @@ -52,8 +52,7 @@ async def to_code(config): var = await select.new_select(config, options=list(options_map.values())) await cg.register_component(var, config) cg.add(var.set_select_mappings(list(options_map.keys()))) - parent = await cg.get_variable(config[CONF_TUYA_ID]) - cg.add(var.set_tuya_parent(parent)) + await cg.add_variable(var.set_tuya_parent, config[CONF_TUYA_ID]) if (enum_datapoint := config.get(CONF_ENUM_DATAPOINT, None)) is not None: cg.add(var.set_select_id(enum_datapoint, False)) if (int_datapoint := config.get(CONF_INT_DATAPOINT, None)) is not None: diff --git a/esphome/components/tuya/sensor/__init__.py b/esphome/components/tuya/sensor/__init__.py index 861bbc656aa..191f1095e6d 100644 --- a/esphome/components/tuya/sensor/__init__.py +++ b/esphome/components/tuya/sensor/__init__.py @@ -27,7 +27,6 @@ async def to_code(config): await cg.register_component(var, config) await sensor.register_sensor(var, config) - paren = await cg.get_variable(config[CONF_TUYA_ID]) - cg.add(var.set_tuya_parent(paren)) + await cg.add_variable(var.set_tuya_parent, config[CONF_TUYA_ID]) cg.add(var.set_sensor_id(config[CONF_SENSOR_DATAPOINT])) diff --git a/esphome/components/tuya/switch/__init__.py b/esphome/components/tuya/switch/__init__.py index e9987050cb0..fc43b39b9c0 100644 --- a/esphome/components/tuya/switch/__init__.py +++ b/esphome/components/tuya/switch/__init__.py @@ -26,7 +26,6 @@ async def to_code(config): var = await switch.new_switch(config) await cg.register_component(var, config) - paren = await cg.get_variable(config[CONF_TUYA_ID]) - cg.add(var.set_tuya_parent(paren)) + await cg.add_variable(var.set_tuya_parent, config[CONF_TUYA_ID]) cg.add(var.set_switch_id(config[CONF_SWITCH_DATAPOINT])) diff --git a/esphome/components/tuya/text_sensor/__init__.py b/esphome/components/tuya/text_sensor/__init__.py index 3bae109b93a..af84d32f124 100644 --- a/esphome/components/tuya/text_sensor/__init__.py +++ b/esphome/components/tuya/text_sensor/__init__.py @@ -27,7 +27,6 @@ async def to_code(config): var = await text_sensor.new_text_sensor(config) await cg.register_component(var, config) - paren = await cg.get_variable(config[CONF_TUYA_ID]) - cg.add(var.set_tuya_parent(paren)) + await cg.add_variable(var.set_tuya_parent, config[CONF_TUYA_ID]) cg.add(var.set_sensor_id(config[CONF_SENSOR_DATAPOINT])) diff --git a/esphome/components/tuya/water_heater/__init__.py b/esphome/components/tuya/water_heater/__init__.py index 7d1af791b4f..96b7136c725 100644 --- a/esphome/components/tuya/water_heater/__init__.py +++ b/esphome/components/tuya/water_heater/__init__.py @@ -89,8 +89,7 @@ async def to_code(config: ConfigType) -> None: var = await water_heater.new_water_heater(config) await cg.register_component(var, config) - paren = await cg.get_variable(config[CONF_TUYA_ID]) - cg.add(var.set_tuya_parent(paren)) + await cg.add_variable(var.set_tuya_parent, config[CONF_TUYA_ID]) cg.add(var.set_switch_id(config[CONF_SWITCH_DATAPOINT])) diff --git a/esphome/components/ufire_ec/sensor.py b/esphome/components/ufire_ec/sensor.py index 6a632e05cd5..de68f56046b 100644 --- a/esphome/components/ufire_ec/sensor.py +++ b/esphome/components/ufire_ec/sensor.py @@ -68,9 +68,9 @@ async def to_code(config: ConfigType) -> None: 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]) - cg.add(var.set_temperature_sensor_external(sens)) + await cg.add_variable( + var.set_temperature_sensor_external, config.get(CONF_TEMPERATURE_SENSOR) + ) await i2c.register_i2c_device(var, config) diff --git a/esphome/components/ufire_ise/sensor.py b/esphome/components/ufire_ise/sensor.py index 6f205af784d..f9aae747689 100644 --- a/esphome/components/ufire_ise/sensor.py +++ b/esphome/components/ufire_ise/sensor.py @@ -60,9 +60,9 @@ async def to_code(config: ConfigType) -> None: 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]) - cg.add(var.set_temperature_sensor_external(sens)) + await cg.add_variable( + var.set_temperature_sensor_external, config.get(CONF_TEMPERATURE_SENSOR) + ) await i2c.register_i2c_device(var, config) diff --git a/esphome/components/uponor_smatrix/__init__.py b/esphome/components/uponor_smatrix/__init__.py index e23f4157a7e..d4d03d3e0f5 100644 --- a/esphome/components/uponor_smatrix/__init__.py +++ b/esphome/components/uponor_smatrix/__init__.py @@ -69,8 +69,7 @@ async def to_code(config: ConfigType) -> None: var = await uart.new_uart_component(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, time_id) if time_device_address := config.get(CONF_TIME_DEVICE_ADDRESS): cg.add(var.set_time_device_address(time_device_address)) diff --git a/esphome/components/uptime/sensor/__init__.py b/esphome/components/uptime/sensor/__init__.py index 04140ba431d..619d9ca8864 100644 --- a/esphome/components/uptime/sensor/__init__.py +++ b/esphome/components/uptime/sensor/__init__.py @@ -61,8 +61,7 @@ async def to_code(config: ConfigType) -> None: var = await sensor.new_sensor(config) await cg.register_component(var, config) if time_id_config := config.get(CONF_TIME_ID): - time_id = await cg.get_variable(time_id_config) - cg.add(var.set_time(time_id)) + await cg.add_variable(var.set_time, time_id_config) cg.add_define("USE_UPTIME_TIMESTAMP") diff --git a/esphome/components/voice_assistant/__init__.py b/esphome/components/voice_assistant/__init__.py index 488e16a3839..1b7ad38c1c5 100644 --- a/esphome/components/voice_assistant/__init__.py +++ b/esphome/components/voice_assistant/__init__.py @@ -207,17 +207,9 @@ async def to_code(config: ConfigType) -> None: mic_source2 = await microphone.microphone_source_to_code(mic_sources[1]) cg.add(var.set_microphone_source2(mic_source2)) - if CONF_MICRO_WAKE_WORD in config: - mww = await cg.get_variable(config[CONF_MICRO_WAKE_WORD]) - cg.add(var.set_micro_wake_word(mww)) - - if CONF_MEDIA_PLAYER in config: - mp = await cg.get_variable(config[CONF_MEDIA_PLAYER]) - cg.add(var.set_media_player(mp)) - - if CONF_SPEAKER in config: - spkr = await cg.get_variable(config[CONF_SPEAKER]) - cg.add(var.set_speaker(spkr)) + await cg.add_variable(var.set_micro_wake_word, config.get(CONF_MICRO_WAKE_WORD)) + await cg.add_variable(var.set_media_player, config.get(CONF_MEDIA_PLAYER)) + await cg.add_variable(var.set_speaker, config.get(CONF_SPEAKER)) cg.add(var.set_use_wake_word(config[CONF_USE_WAKE_WORD])) diff --git a/esphome/components/wireguard/__init__.py b/esphome/components/wireguard/__init__.py index e9641a5957c..07cb154c91c 100644 --- a/esphome/components/wireguard/__init__.py +++ b/esphome/components/wireguard/__init__.py @@ -137,7 +137,7 @@ async def to_code(config): ) ) - cg.add(var.set_srctime(await cg.get_variable(config[CONF_TIME_ID]))) + await cg.add_variable(var.set_srctime, config[CONF_TIME_ID]) if config[CONF_REQUIRE_CONNECTION_TO_PROCEED]: cg.add(var.disable_auto_proceed()) diff --git a/esphome/components/yashima/climate.py b/esphome/components/yashima/climate.py index cfc4744d82c..25e06b37586 100644 --- a/esphome/components/yashima/climate.py +++ b/esphome/components/yashima/climate.py @@ -32,9 +32,5 @@ async def to_code(config: ConfigType) -> None: cg.add(var.set_supports_cool(config[CONF_SUPPORTS_COOL])) cg.add(var.set_supports_heat(config[CONF_SUPPORTS_HEAT])) - if CONF_SENSOR in config: - sens = await cg.get_variable(config[CONF_SENSOR]) - cg.add(var.set_sensor(sens)) - - transmitter = await cg.get_variable(config[CONF_TRANSMITTER_ID]) - cg.add(var.set_transmitter(transmitter)) + await cg.add_variable(var.set_sensor, config.get(CONF_SENSOR)) + await cg.add_variable(var.set_transmitter, config[CONF_TRANSMITTER_ID]) diff --git a/esphome/components/zigbee/time/__init__.py b/esphome/components/zigbee/time/__init__.py index 0572e591cfc..dbbb6734920 100644 --- a/esphome/components/zigbee/time/__init__.py +++ b/esphome/components/zigbee/time/__init__.py @@ -113,5 +113,4 @@ async def _add_time_zephyr(config: ConfigType) -> None: cg.add(var.set_endpoint(slot_index + 1)) cg.add(var.set_cluster_attributes(time_attrs)) - hub = await cg.get_variable(config[CONF_ZIGBEE_ID]) - cg.add(var.set_parent(hub)) + await cg.register_parented(var, config[CONF_ZIGBEE_ID])