diff --git a/esphome/components/airton/climate.py b/esphome/components/airton/climate.py index fdfef45aaa4..bde8eca0c04 100644 --- a/esphome/components/airton/climate.py +++ b/esphome/components/airton/climate.py @@ -16,15 +16,16 @@ CONF_VERTICAL_DIRECTION = "vertical_direction" VerticalDirection = airton_ns.enum("VerticalDirection", is_class=True) # In the order of the enum, so the option index is the direction value -VERTICAL_DIRECTIONS = { - "off": VerticalDirection.VERTICAL_DIRECTION_OFF, - "swing": VerticalDirection.VERTICAL_DIRECTION_SWING, - "up": VerticalDirection.VERTICAL_DIRECTION_UP, - "middle-up": VerticalDirection.VERTICAL_DIRECTION_MIDDLE_UP, - "middle": VerticalDirection.VERTICAL_DIRECTION_MIDDLE, - "middle-down": VerticalDirection.VERTICAL_DIRECTION_MIDDLE_DOWN, - "down": VerticalDirection.VERTICAL_DIRECTION_DOWN, -} +VERTICAL_DIRECTIONS = VerticalDirection.options( + "off", + "swing", + "up", + "middle-up", + "middle", + "middle-down", + "down", + prefix="VERTICAL_DIRECTION_", +) CONFIG_SCHEMA = climate_ir.climate_ir_with_receiver_schema(AirtonClimate).extend( { diff --git a/esphome/components/am43/sensor/__init__.py b/esphome/components/am43/sensor/__init__.py index ef746f3e52f..d988c6dbec6 100644 --- a/esphome/components/am43/sensor/__init__.py +++ b/esphome/components/am43/sensor/__init__.py @@ -3,7 +3,6 @@ from esphome.components import ble_client, sensor import esphome.config_validation as cv from esphome.const import ( CONF_BATTERY_LEVEL, - CONF_ID, CONF_ILLUMINANCE, DEVICE_CLASS_BATTERY, ENTITY_CATEGORY_DIAGNOSTIC, @@ -44,9 +43,7 @@ CONFIG_SCHEMA = ( 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) + var = await ble_client.new_ble_node_component(config) sensors = sensor.sub_sensors(config) await sensors(CONF_BATTERY_LEVEL, var.set_battery) diff --git a/esphome/components/bedjet/__init__.py b/esphome/components/bedjet/__init__.py index 406955084ea..2bcbf557649 100644 --- a/esphome/components/bedjet/__init__.py +++ b/esphome/components/bedjet/__init__.py @@ -1,7 +1,7 @@ import esphome.codegen as cg from esphome.components import ble_client, time import esphome.config_validation as cv -from esphome.const import CONF_ID, CONF_RECEIVE_TIMEOUT, CONF_TIME_ID +from esphome.const import CONF_RECEIVE_TIMEOUT, CONF_TIME_ID from esphome.cpp_generator import MockObj from esphome.types import ConfigType @@ -41,9 +41,7 @@ async def register_bedjet_child(var: MockObj, config: ConfigType) -> None: 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) + var = await ble_client.new_ble_node_component(config) 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/bluetooth_proxy/__init__.py b/esphome/components/bluetooth_proxy/__init__.py index 6332ea6dc12..5c7dff0cd17 100644 --- a/esphome/components/bluetooth_proxy/__init__.py +++ b/esphome/components/bluetooth_proxy/__init__.py @@ -372,8 +372,7 @@ async def _to_code_esp32(config: ConfigType) -> None: await cg.register_component(var, config) cg.add(var.set_active(config[CONF_ACTIVE])) - tracker = await cg.get_variable(config[esp32_ble_tracker.CONF_ESP32_BLE_ID]) - cg.add(var.set_ble_hub(tracker)) + await cg.add_variable(var.set_ble_hub, config[esp32_ble_tracker.CONF_ESP32_BLE_ID]) # Compiles the scanner-state push slot into the tracker and the matching # registration into the proxy; the other hubs are polled instead. @@ -390,8 +389,7 @@ async def _to_code_ble_hub(config: ConfigType) -> None: await cg.register_component(var, config) cg.add(var.set_active(config[CONF_ACTIVE])) - hub = await cg.get_variable(config[ble_device_base.CONF_BLE_HUB_ID]) - cg.add(var.set_ble_hub(hub)) + await cg.add_variable(var.set_ble_hub, config[ble_device_base.CONF_BLE_HUB_ID]) await _connections_to_code(var, config) diff --git a/esphome/components/ch422g/__init__.py b/esphome/components/ch422g/__init__.py index 5110503bf84..60801e0c8dd 100644 --- a/esphome/components/ch422g/__init__.py +++ b/esphome/components/ch422g/__init__.py @@ -42,8 +42,7 @@ async def to_code(config: ConfigType) -> None: var = cg.new_Pvariable(config[CONF_ID]) await cg.register_component(var, config) # Can't use register_i2c_device because there is no CONF_ADDRESS - 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]) # This is used as a final validation step so that modes have been fully transformed. diff --git a/esphome/components/ch423/__init__.py b/esphome/components/ch423/__init__.py index 3997f9581f0..42dc8bb2841 100644 --- a/esphome/components/ch423/__init__.py +++ b/esphome/components/ch423/__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) # Can't use register_i2c_device because there is no CONF_ADDRESS - 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]) # This is used as a final validation step so that modes have been fully transformed. diff --git a/esphome/components/dlms_meter/__init__.py b/esphome/components/dlms_meter/__init__.py index eed702b6f1a..46ccc2e44e6 100644 --- a/esphome/components/dlms_meter/__init__.py +++ b/esphome/components/dlms_meter/__init__.py @@ -4,13 +4,7 @@ from typing import Any import esphome.codegen as cg from esphome.components import esp32, uart import esphome.config_validation as cv -from esphome.const import ( - CONF_ID, - CONF_NAME, - CONF_PATTERN, - CONF_PRIORITY, - CONF_RECEIVE_TIMEOUT, -) +from esphome.const import CONF_NAME, CONF_PATTERN, CONF_PRIORITY, CONF_RECEIVE_TIMEOUT from esphome.core import CORE from esphome.cpp_generator import MockObj from esphome.types import ConfigType @@ -146,8 +140,8 @@ async def to_code(config: ConfigType) -> None: for pattern in config.get(CONF_CUSTOM_PATTERNS, []) ] - var = cg.new_Pvariable( - config[CONF_ID], + await uart.new_uart_component( + config, config[CONF_RECEIVE_TIMEOUT], config[CONF_SKIP_CRC], config.get(CONF_DECRYPTION_KEY, cg.nullptr), @@ -155,9 +149,6 @@ async def to_code(config: ConfigType) -> None: cg.ArrayInitializer(*custom_patterns, multiline=True), ) - await cg.register_component(var, config) - await uart.register_uart_device(var, config) - if CORE.is_esp32: esp32.add_idf_component(name="esphome/dlms_parser", ref=DLMS_PARSER_VERSION) else: diff --git a/esphome/components/ds1307/time.py b/esphome/components/ds1307/time.py index 7a15283f3b7..962bd3605fb 100644 --- a/esphome/components/ds1307/time.py +++ b/esphome/components/ds1307/time.py @@ -2,7 +2,6 @@ from esphome import automation import esphome.codegen as cg from esphome.components import i2c, time import esphome.config_validation as cv -from esphome.const import CONF_ID from esphome.types import ConfigType CODEOWNERS = ["@badbadc0ffee"] @@ -40,8 +39,5 @@ automation.register_apply_action( async def to_code(config: ConfigType) -> None: - var = cg.new_Pvariable(config[CONF_ID]) - - await cg.register_component(var, config) - await i2c.register_i2c_device(var, config) + var = await i2c.new_i2c_component(config) await time.register_time(var, config) diff --git a/esphome/components/ds248x/one_wire.py b/esphome/components/ds248x/one_wire.py index b0289581329..1b142b41690 100644 --- a/esphome/components/ds248x/one_wire.py +++ b/esphome/components/ds248x/one_wire.py @@ -52,6 +52,5 @@ 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_DS248X_ID]) - cg.add(var.set_parent(parent)) + await cg.register_parented(var, config[CONF_DS248X_ID]) cg.add(var.set_channel(config[CONF_CHANNEL])) diff --git a/esphome/components/epaper_spi/display.py b/esphome/components/epaper_spi/display.py index 75a3426f162..35bb99ed872 100644 --- a/esphome/components/epaper_spi/display.py +++ b/esphome/components/epaper_spi/display.py @@ -245,11 +245,7 @@ async def to_code(config): await cg.add_pin(var.set_dc_pin, config[CONF_DC_PIN]) - if CONF_LAMBDA in config: - lambda_ = await cg.process_lambda( - config[CONF_LAMBDA], [(display.DisplayRef, "it")], return_type=cg.void - ) - cg.add(var.set_writer(lambda_)) + await display.add_writer(var, config) await cg.add_pin(var.set_reset_pin, config.get(CONF_RESET_PIN)) await cg.add_pin(var.set_busy_pin, config.get(CONF_BUSY_PIN)) if enable_pin := config.get(CONF_ENABLE_PIN): diff --git a/esphome/components/ethernet/__init__.py b/esphome/components/ethernet/__init__.py index 3fa71632f02..1a50dbebfc3 100644 --- a/esphome/components/ethernet/__init__.py +++ b/esphome/components/ethernet/__init__.py @@ -715,8 +715,7 @@ async def _to_code_esp32(var: cg.MockObj, config: ConfigType) -> None: if config[CONF_TYPE] in SPI_ETHERNET_TYPES: if (spi_id := config.get(CONF_SPI_ID)) is not None: # Pins and host come from the shared spi bus. - spi_parent = await cg.get_variable(spi_id) - cg.add(var.set_spi_parent(spi_parent)) + await cg.add_variable(var.set_spi_parent, spi_id) else: cg.add(var.set_clk_pin(config[CONF_CLK_PIN])) cg.add(var.set_miso_pin(config[CONF_MISO_PIN])) diff --git a/esphome/components/hbridge/fan/__init__.py b/esphome/components/hbridge/fan/__init__.py index f6d935c300d..01713ba34f4 100644 --- a/esphome/components/hbridge/fan/__init__.py +++ b/esphome/components/hbridge/fan/__init__.py @@ -56,14 +56,9 @@ async def to_code(config: ConfigType) -> None: config[CONF_DECAY_MODE], ) await cg.register_component(var, config) - pin_a_ = await cg.get_variable(config[CONF_PIN_A]) - cg.add(var.set_pin_a(pin_a_)) - pin_b_ = await cg.get_variable(config[CONF_PIN_B]) - cg.add(var.set_pin_b(pin_b_)) - - if CONF_ENABLE_PIN in config: - enable_pin = await cg.get_variable(config[CONF_ENABLE_PIN]) - cg.add(var.set_enable_pin(enable_pin)) + await cg.add_variable(var.set_pin_a, config[CONF_PIN_A]) + await cg.add_variable(var.set_pin_b, config[CONF_PIN_B]) + await cg.add_variable(var.set_enable_pin, config.get(CONF_ENABLE_PIN)) if CONF_PRESET_MODES in config: cg.add(var.set_preset_modes(config[CONF_PRESET_MODES])) diff --git a/esphome/components/ina260/sensor.py b/esphome/components/ina260/sensor.py index 20cf1fee45f..985defc06a8 100644 --- a/esphome/components/ina260/sensor.py +++ b/esphome/components/ina260/sensor.py @@ -4,7 +4,6 @@ import esphome.config_validation as cv from esphome.const import ( CONF_BUS_VOLTAGE, CONF_CURRENT, - CONF_ID, CONF_POWER, DEVICE_CLASS_CURRENT, DEVICE_CLASS_POWER, @@ -54,10 +53,7 @@ CONFIG_SCHEMA = cv.All( async def to_code(config: ConfigType) -> None: - var = cg.new_Pvariable(config[CONF_ID]) - - await cg.register_component(var, config) - await i2c.register_i2c_device(var, config) + var = await i2c.new_i2c_component(config) sensors = sensor.sub_sensors(config) await sensors(CONF_BUS_VOLTAGE, var.set_bus_voltage_sensor) diff --git a/esphome/components/ld6002b/__init__.py b/esphome/components/ld6002b/__init__.py index 48017a8f00e..5dccf0d725f 100644 --- a/esphome/components/ld6002b/__init__.py +++ b/esphome/components/ld6002b/__init__.py @@ -64,9 +64,7 @@ FINAL_VALIDATE_SCHEMA = uart.final_validate_device_schema( async def to_code(config: ConfigType) -> None: var = await uart.new_uart_component(config) - if wakeup_pin_config := config.get(CONF_WAKEUP_PIN): - pin = await cg.gpio_pin_expression(wakeup_pin_config) - cg.add(var.set_wakeup_pin(pin)) + await cg.add_pin(var.set_wakeup_pin, config.get(CONF_WAKEUP_PIN)) cg.add(var.set_wakeup_pulse_ms(config[CONF_WAKEUP_PULSE].total_milliseconds)) diff --git a/esphome/components/light/__init__.py b/esphome/components/light/__init__.py index 056ec7c44f9..dcd88a80ea4 100644 --- a/esphome/components/light/__init__.py +++ b/esphome/components/light/__init__.py @@ -633,9 +633,7 @@ async def setup_light_core_(light_var, config, output_var): if (color_correct := config.get(CONF_COLOR_CORRECT)) is not None: cg.add(output_var.set_correction(*color_correct)) - if (power_supply_id := config.get(CONF_POWER_SUPPLY)) is not None: - var_ = await cg.get_variable(power_supply_id) - cg.add(output_var.set_power_supply(var_)) + await cg.add_variable(output_var.set_power_supply, config.get(CONF_POWER_SUPPLY)) if (power_estimation := config.get(CONF_POWER_ESTIMATION)) is not None: cg.add_define("USE_LIGHT_POWER_ESTIMATION") diff --git a/esphome/components/mcp23016/__init__.py b/esphome/components/mcp23016/__init__.py index ab77bc5a5b3..67b302d1c51 100644 --- a/esphome/components/mcp23016/__init__.py +++ b/esphome/components/mcp23016/__init__.py @@ -38,8 +38,7 @@ CONFIG_SCHEMA = ( async def to_code(config: ConfigType) -> None: var = await i2c.new_i2c_component(config) - if interrupt_pin := config.get(CONF_INTERRUPT_PIN): - cg.add(var.set_interrupt_pin(await cg.gpio_pin_expression(interrupt_pin))) + await cg.add_pin(var.set_interrupt_pin, config.get(CONF_INTERRUPT_PIN)) def validate_mode(value: ConfigType) -> ConfigType: diff --git a/esphome/components/mcp23xxx_base/__init__.py b/esphome/components/mcp23xxx_base/__init__.py index 942a975813a..c7aae9d10ff 100644 --- a/esphome/components/mcp23xxx_base/__init__.py +++ b/esphome/components/mcp23xxx_base/__init__.py @@ -47,8 +47,7 @@ async def register_mcp23xxx(config: ConfigType, num_pins: int) -> MockObj: await cg.register_component(var, config) CORE.data.setdefault(CONF_MCP23XXX, {})[id.id] = num_pins cg.add(var.set_open_drain_ints(config[CONF_OPEN_DRAIN_INTERRUPT])) - if interrupt_pin := config.get(CONF_INTERRUPT_PIN): - cg.add(var.set_interrupt_pin(await cg.gpio_pin_expression(interrupt_pin))) + await cg.add_pin(var.set_interrupt_pin, config.get(CONF_INTERRUPT_PIN)) return var diff --git a/esphome/components/mcp9600/sensor.py b/esphome/components/mcp9600/sensor.py index 9a5afe64c28..9953f450145 100644 --- a/esphome/components/mcp9600/sensor.py +++ b/esphome/components/mcp9600/sensor.py @@ -2,7 +2,6 @@ import esphome.codegen as cg from esphome.components import i2c, sensor import esphome.config_validation as cv from esphome.const import ( - CONF_ID, CONF_THERMOCOUPLE_TYPE, DEVICE_CLASS_TEMPERATURE, STATE_CLASS_MEASUREMENT, @@ -57,10 +56,7 @@ FINAL_VALIDATE_SCHEMA = i2c.final_validate_device_schema( async def to_code(config: ConfigType) -> None: - var = cg.new_Pvariable(config[CONF_ID]) - - await cg.register_component(var, config) - await i2c.register_i2c_device(var, config) + var = await i2c.new_i2c_component(config) cg.add(var.set_thermocouple_type(config[CONF_THERMOCOUPLE_TYPE])) diff --git a/esphome/components/midea/climate.py b/esphome/components/midea/climate.py index cecbf9836ef..f5c1ed71b84 100644 --- a/esphome/components/midea/climate.py +++ b/esphome/components/midea/climate.py @@ -221,8 +221,7 @@ async def to_code(config): if CONF_TRANSMITTER_ID in config: remote_base.request_protocol("midea") # ir_transmitter.h uses it from C++ cg.add_define("USE_REMOTE_TRANSMITTER") - transmitter_ = await cg.get_variable(config[CONF_TRANSMITTER_ID]) - cg.add(var.set_transmitter(transmitter_)) + await cg.add_variable(var.set_transmitter, config[CONF_TRANSMITTER_ID]) cg.add(var.set_beeper_feedback(config[CONF_BEEPER])) cg.add(var.set_autoconf(config[CONF_AUTOCONF])) cg.add(var.set_display_control(config[CONF_DISPLAY_CONTROL])) diff --git a/esphome/components/mipi_spi/display.py b/esphome/components/mipi_spi/display.py index 380c3a4dfd6..fffd1aacf44 100644 --- a/esphome/components/mipi_spi/display.py +++ b/esphome/components/mipi_spi/display.py @@ -45,7 +45,6 @@ from esphome.const import ( CONF_ID, CONF_INIT_SEQUENCE, CONF_INVERT_COLORS, - CONF_LAMBDA, CONF_MODEL, CONF_RESET_PIN, CONF_ROTATION, @@ -227,11 +226,7 @@ def model_schema(config: ConfigType) -> cv.All | cv.Schema: ) if model.get_default(CONF_BRIGHTNESS, None) is not None or model.name == "CUSTOM": schema = schema.extend( - { - model.option(CONF_BRIGHTNESS, cv.UNDEFINED): cv.int_range( - 0, 0xFF, min_included=True, max_included=True - ), - } + {model.option(CONF_BRIGHTNESS, cv.UNDEFINED): cv.uint8_t} ) if bus_mode != TYPE_SINGLE: return cv.All(schema, cv.only_on_esp32) @@ -413,10 +408,6 @@ async def to_code(config: ConfigType) -> None: if config.get(CONF_INVERT_COLORS): cg.add(var.set_invert_colors(True)) - if lamb := config.get(CONF_LAMBDA): - lambda_ = await cg.process_lambda( - lamb, [(display.DisplayRef, "it")], return_type=cg.void - ) - cg.add(var.set_writer(lambda_)) + await display.add_writer(var, config) await display.register_display(var, config) await spi.register_spi_device(var, config, write_only=True) diff --git a/esphome/components/mipi_spi/light/__init__.py b/esphome/components/mipi_spi/light/__init__.py index aec5d9b4fdf..2fe4c872dfe 100644 --- a/esphome/components/mipi_spi/light/__init__.py +++ b/esphome/components/mipi_spi/light/__init__.py @@ -32,8 +32,8 @@ CONFIG_SCHEMA = cv.All( cv.GenerateID(CONF_OUTPUT_ID): cv.declare_id(MipiSpiLight), cv.GenerateID(CONF_DISPLAY_ID): cv.use_id(MipiSpi), cv.Optional(CONF_GAMMA_CORRECT, default=1.0): cv.positive_float, - cv.Optional(CONF_MIN_BRIGHTNESS, default=0): cv.int_range(0, 255), - cv.Optional(CONF_MAX_BRIGHTNESS, default=255): cv.int_range(0, 255), + cv.Optional(CONF_MIN_BRIGHTNESS, default=0): cv.uint8_t, + cv.Optional(CONF_MAX_BRIGHTNESS, default=255): cv.uint8_t, } ), _validate_brightness_range, diff --git a/esphome/components/modbus/__init__.py b/esphome/components/modbus/__init__.py index a1f15aab452..258ecd51bac 100644 --- a/esphome/components/modbus/__init__.py +++ b/esphome/components/modbus/__init__.py @@ -9,7 +9,7 @@ import esphome.codegen as cg from esphome.components import uart from esphome.components.const import CONF_ROLE import esphome.config_validation as cv -from esphome.const import CONF_ADDRESS, CONF_CONTINUOUS, CONF_FLOW_CONTROL_PIN, CONF_ID +from esphome.const import CONF_ADDRESS, CONF_CONTINUOUS, CONF_FLOW_CONTROL_PIN from esphome.cpp_generator import MockObj import esphome.final_validate as fv from esphome.types import ConfigType, TemplateArgsType @@ -301,10 +301,7 @@ CONFIG_SCHEMA = cv.typed_schema( async def to_code(config: ConfigType) -> None: cg.add_global(modbus_ns.using) - var = cg.new_Pvariable(config[CONF_ID]) - await cg.register_component(var, config) - - await uart.register_uart_device(var, config) + var = await uart.new_uart_component(config) await cg.add_pin(var.set_flow_control_pin, config.get(CONF_FLOW_CONTROL_PIN)) diff --git a/esphome/components/modbus_client/__init__.py b/esphome/components/modbus_client/__init__.py index 67c3cd75bdc..25f4b230dbb 100644 --- a/esphome/components/modbus_client/__init__.py +++ b/esphome/components/modbus_client/__init__.py @@ -186,8 +186,7 @@ async def register_client_action( response_args are the on_response handler's arguments, which differ per action. """ - parent = await cg.get_variable(config[modbus.CONF_MODBUS_ID]) - cg.add(var.set_parent(parent)) + await cg.register_parented(var, config[modbus.CONF_MODBUS_ID]) cg.add( var.set_target_address( await cg.templatable(config[CONF_ADDRESS], args, cg.uint8) diff --git a/esphome/components/mt6701_i2c/__init__.py b/esphome/components/mt6701_i2c/__init__.py index 17734e00459..79c73eebe46 100644 --- a/esphome/components/mt6701_i2c/__init__.py +++ b/esphome/components/mt6701_i2c/__init__.py @@ -155,9 +155,7 @@ CONFIG_SCHEMA = ( async def to_code(config: ConfigType) -> None: - var = cg.new_Pvariable(config[CONF_ID]) - await cg.register_component(var, config) - await i2c.register_i2c_device(var, config) + var = await i2c.new_i2c_component(config) if (direction := config.get(CONF_DIRECTION)) is not None: cg.add(var.set_direction(direction)) diff --git a/esphome/components/mt6701_spi/__init__.py b/esphome/components/mt6701_spi/__init__.py index 6f45e347b7d..3498dde0e8a 100644 --- a/esphome/components/mt6701_spi/__init__.py +++ b/esphome/components/mt6701_spi/__init__.py @@ -1,7 +1,6 @@ import esphome.codegen as cg from esphome.components import spi import esphome.config_validation as cv -from esphome.const import CONF_ID from esphome.types import ConfigType from ..mt6701 import MT6701Component @@ -42,6 +41,4 @@ FINAL_VALIDATE_SCHEMA = spi.final_validate_device_schema( async def to_code(config: ConfigType) -> None: - var = cg.new_Pvariable(config[CONF_ID]) - await cg.register_component(var, config) - await spi.register_spi_device(var, config) + await spi.new_spi_component(config) diff --git a/esphome/components/nextion/display.py b/esphome/components/nextion/display.py index 969a6c8e8c9..92255a6eda2 100644 --- a/esphome/components/nextion/display.py +++ b/esphome/components/nextion/display.py @@ -5,7 +5,6 @@ import esphome.config_validation as cv from esphome.const import ( CONF_BRIGHTNESS, CONF_ID, - CONF_LAMBDA, CONF_ON_TOUCH, PLATFORM_ESP32, PLATFORM_ESP8266, @@ -232,11 +231,7 @@ async def to_code(config): if CONF_BRIGHTNESS in config: cg.add(var.set_brightness(config[CONF_BRIGHTNESS])) - if CONF_LAMBDA in config: - lambda_ = await cg.process_lambda( - config[CONF_LAMBDA], [(nextion_ref, "it")], return_type=cg.void - ) - cg.add(var.set_writer(lambda_)) + await display.add_writer(var, config, nextion_ref) if CONF_TFT_URL in config: cg.add_define("USE_NEXTION_TFT_UPLOAD") diff --git a/esphome/components/pca6416a/__init__.py b/esphome/components/pca6416a/__init__.py index 33f8af9d528..144088d48f1 100644 --- a/esphome/components/pca6416a/__init__.py +++ b/esphome/components/pca6416a/__init__.py @@ -42,8 +42,7 @@ CONFIG_SCHEMA = ( async def to_code(config: ConfigType) -> None: var = await i2c.new_i2c_component(config) - if interrupt_pin := config.get(CONF_INTERRUPT_PIN): - cg.add(var.set_interrupt_pin(await cg.gpio_pin_expression(interrupt_pin))) + await cg.add_pin(var.set_interrupt_pin, config.get(CONF_INTERRUPT_PIN)) def validate_mode(value: ConfigType) -> ConfigType: diff --git a/esphome/components/pca9505/__init__.py b/esphome/components/pca9505/__init__.py index 4e3acb94e6e..91521820b30 100644 --- a/esphome/components/pca9505/__init__.py +++ b/esphome/components/pca9505/__init__.py @@ -42,8 +42,7 @@ CONFIG_SCHEMA = ( async def to_code(config: ConfigType) -> None: var = await i2c.new_i2c_component(config) - if interrupt_pin := config.get(CONF_INTERRUPT_PIN): - cg.add(var.set_interrupt_pin(await cg.gpio_pin_expression(interrupt_pin))) + await cg.add_pin(var.set_interrupt_pin, config.get(CONF_INTERRUPT_PIN)) def validate_mode(value: ConfigType) -> ConfigType: diff --git a/esphome/components/pca9554/__init__.py b/esphome/components/pca9554/__init__.py index cba5656e88d..6e9478b1fd4 100644 --- a/esphome/components/pca9554/__init__.py +++ b/esphome/components/pca9554/__init__.py @@ -48,8 +48,7 @@ async def to_code(config: ConfigType) -> None: cg.add(var.set_pin_count(config[CONF_PIN_COUNT])) await cg.register_component(var, config) await i2c.register_i2c_device(var, config) - if interrupt_pin := config.get(CONF_INTERRUPT_PIN): - cg.add(var.set_interrupt_pin(await cg.gpio_pin_expression(interrupt_pin))) + await cg.add_pin(var.set_interrupt_pin, config.get(CONF_INTERRUPT_PIN)) def validate_mode(value: ConfigType) -> ConfigType: diff --git a/esphome/components/pcf85063/time.py b/esphome/components/pcf85063/time.py index 3f993c17e19..e3e7daeb49a 100644 --- a/esphome/components/pcf85063/time.py +++ b/esphome/components/pcf85063/time.py @@ -2,7 +2,6 @@ from esphome import automation import esphome.codegen as cg from esphome.components import i2c, time import esphome.config_validation as cv -from esphome.const import CONF_ID from esphome.types import ConfigType CODEOWNERS = ["@brogon"] @@ -42,8 +41,5 @@ automation.register_apply_action( async def to_code(config: ConfigType) -> None: - var = cg.new_Pvariable(config[CONF_ID]) - - await cg.register_component(var, config) - await i2c.register_i2c_device(var, config) + var = await i2c.new_i2c_component(config) await time.register_time(var, config) diff --git a/esphome/components/pcf8563/time.py b/esphome/components/pcf8563/time.py index 3f677280c5b..7f78549ba8e 100644 --- a/esphome/components/pcf8563/time.py +++ b/esphome/components/pcf8563/time.py @@ -2,7 +2,6 @@ from esphome import automation import esphome.codegen as cg from esphome.components import i2c, time import esphome.config_validation as cv -from esphome.const import CONF_ID from esphome.types import ConfigType CODEOWNERS = ["@KoenBreeman"] @@ -38,8 +37,5 @@ automation.register_apply_action( async def to_code(config: ConfigType) -> None: - var = cg.new_Pvariable(config[CONF_ID]) - - await cg.register_component(var, config) - await i2c.register_i2c_device(var, config) + var = await i2c.new_i2c_component(config) await time.register_time(var, config) diff --git a/esphome/components/pcf8574/__init__.py b/esphome/components/pcf8574/__init__.py index f1db7c29748..b491dae5047 100644 --- a/esphome/components/pcf8574/__init__.py +++ b/esphome/components/pcf8574/__init__.py @@ -48,8 +48,7 @@ async def to_code(config: ConfigType) -> None: cg.add(var.set_pcf8575(config[CONF_PCF8575])) if (reset := config[CONF_RESET]) != DEFAULT_RESET: cg.add(var.set_reset(reset)) - if interrupt_pin := config.get(CONF_INTERRUPT_PIN): - cg.add(var.set_interrupt_pin(await cg.gpio_pin_expression(interrupt_pin))) + await cg.add_pin(var.set_interrupt_pin, config.get(CONF_INTERRUPT_PIN)) def validate_mode(value: ConfigType) -> ConfigType: diff --git a/esphome/components/pcm5122/audio_dac.py b/esphome/components/pcm5122/audio_dac.py index cb50b101c13..fbfc998bb9f 100644 --- a/esphome/components/pcm5122/audio_dac.py +++ b/esphome/components/pcm5122/audio_dac.py @@ -140,6 +140,4 @@ async def to_code(config: ConfigType) -> None: cg.add(var.set_channel_mix(config[CONF_CHANNEL_MIX])) cg.add(var.set_volume_min_db(config[CONF_VOLUME_MIN_DB])) cg.add(var.set_volume_max_db(config[CONF_VOLUME_MAX_DB])) - if enable_pin_config := config.get(CONF_ENABLE_PIN): - enable_pin = await cg.gpio_pin_expression(enable_pin_config) - cg.add(var.set_enable_pin(enable_pin)) + await cg.add_pin(var.set_enable_pin, config.get(CONF_ENABLE_PIN)) diff --git a/esphome/components/pi4ioe5v6408/__init__.py b/esphome/components/pi4ioe5v6408/__init__.py index 4128114b3cc..458ea1f2728 100644 --- a/esphome/components/pi4ioe5v6408/__init__.py +++ b/esphome/components/pi4ioe5v6408/__init__.py @@ -49,8 +49,7 @@ async def to_code(config: ConfigType) -> None: var = await i2c.new_i2c_component(config) cg.add(var.set_reset(config[CONF_RESET])) - if interrupt_pin := config.get(CONF_INTERRUPT_PIN): - cg.add(var.set_interrupt_pin(await cg.gpio_pin_expression(interrupt_pin))) + await cg.add_pin(var.set_interrupt_pin, config.get(CONF_INTERRUPT_PIN)) def validate_mode(value: ConfigType) -> ConfigType: diff --git a/esphome/components/rx8025t/time.py b/esphome/components/rx8025t/time.py index e8ffe772ab7..fcc6c0b72fa 100644 --- a/esphome/components/rx8025t/time.py +++ b/esphome/components/rx8025t/time.py @@ -2,7 +2,6 @@ from esphome import automation import esphome.codegen as cg from esphome.components import i2c, time import esphome.config_validation as cv -from esphome.const import CONF_ID from esphome.types import ConfigType CODEOWNERS = ["@remcom"] @@ -35,8 +34,5 @@ for _name, _call in ( async def to_code(config: ConfigType) -> None: - var = cg.new_Pvariable(config[CONF_ID]) - - await cg.register_component(var, config) - await i2c.register_i2c_device(var, config) + var = await i2c.new_i2c_component(config) await time.register_time(var, config) diff --git a/esphome/components/seeed_mr24hpc1/__init__.py b/esphome/components/seeed_mr24hpc1/__init__.py index 4ec01e46c67..63b5373cffc 100644 --- a/esphome/components/seeed_mr24hpc1/__init__.py +++ b/esphome/components/seeed_mr24hpc1/__init__.py @@ -1,7 +1,6 @@ import esphome.codegen as cg from esphome.components import uart import esphome.config_validation as cv -from esphome.const import CONF_ID from esphome.types import ConfigType DEPENDENCIES = ["uart"] @@ -43,12 +42,5 @@ FINAL_VALIDATE_SCHEMA = uart.final_validate_device_schema( ) -# The async def keyword is used to define a concurrent function. -# Concurrent functions are special functions designed to work with Python's asyncio library to support asynchronous I/O operations. async def to_code(config: ConfigType) -> None: - # This line of code creates a new Pvariable (a Python object representing a C++ variable) with the variable's ID taken from the configuration. - var = cg.new_Pvariable(config[CONF_ID]) - # This line of code registers the newly created Pvariable as a component so that ESPHome can manage it at runtime. - await cg.register_component(var, config) - # This line of code registers the newly created Pvariable as a device. - await uart.register_uart_device(var, config) + await uart.new_uart_component(config) diff --git a/esphome/components/speed/fan/__init__.py b/esphome/components/speed/fan/__init__.py index 9a9290e78ee..cd94796f081 100644 --- a/esphome/components/speed/fan/__init__.py +++ b/esphome/components/speed/fan/__init__.py @@ -38,16 +38,9 @@ async def to_code(config: ConfigType) -> None: var = await fan.new_fan(config, config[CONF_SPEED_COUNT]) await cg.register_component(var, config) - output_ = await cg.get_variable(config[CONF_OUTPUT]) - cg.add(var.set_output(output_)) - - if CONF_OSCILLATION_OUTPUT in config: - oscillation_output = await cg.get_variable(config[CONF_OSCILLATION_OUTPUT]) - cg.add(var.set_oscillating(oscillation_output)) - - if CONF_DIRECTION_OUTPUT in config: - direction_output = await cg.get_variable(config[CONF_DIRECTION_OUTPUT]) - 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)) if CONF_PRESET_MODES in config: cg.add(var.set_preset_modes(config[CONF_PRESET_MODES])) diff --git a/esphome/components/tca9555/__init__.py b/esphome/components/tca9555/__init__.py index 0554f9a569d..a3992b7c88e 100644 --- a/esphome/components/tca9555/__init__.py +++ b/esphome/components/tca9555/__init__.py @@ -41,8 +41,7 @@ CONFIG_SCHEMA = ( async def to_code(config: ConfigType) -> None: var = await i2c.new_i2c_component(config) - if interrupt_pin := config.get(CONF_INTERRUPT_PIN): - cg.add(var.set_interrupt_pin(await cg.gpio_pin_expression(interrupt_pin))) + await cg.add_pin(var.set_interrupt_pin, config.get(CONF_INTERRUPT_PIN)) def validate_mode(value: ConfigType) -> ConfigType: diff --git a/esphome/components/template/climate/__init__.py b/esphome/components/template/climate/__init__.py index 30155de28aa..54cd6df45e6 100644 --- a/esphome/components/template/climate/__init__.py +++ b/esphome/components/template/climate/__init__.py @@ -295,11 +295,8 @@ async def to_code(config: ConfigType) -> None: await cg.register_component(var, config) await climate.register_climate(var, config) - if (sens := config.get(CONF_SENSOR)) is not None: - cg.add(var.set_sensor(await cg.get_variable(sens))) - - if (sens := config.get(CONF_HUMIDITY_SENSOR)) is not None: - cg.add(var.set_humidity_sensor(await cg.get_variable(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)) for key, flag in ( (CONF_SUPPORTS_ACTION, climate_ns.CLIMATE_SUPPORTS_ACTION), diff --git a/esphome/components/uart/__init__.py b/esphome/components/uart/__init__.py index dd6ae47bbfa..c70f0b6c693 100644 --- a/esphome/components/uart/__init__.py +++ b/esphome/components/uart/__init__.py @@ -370,15 +370,9 @@ async def to_code(config): cg.add(var.set_baud_rate(config[CONF_BAUD_RATE])) - if CONF_TX_PIN in config: - tx_pin = await cg.gpio_pin_expression(config[CONF_TX_PIN]) - cg.add(var.set_tx_pin(tx_pin)) - if CONF_RX_PIN in config: - rx_pin = await cg.gpio_pin_expression(config[CONF_RX_PIN]) - cg.add(var.set_rx_pin(rx_pin)) - if CONF_FLOW_CONTROL_PIN in config: - flow_control_pin = await cg.gpio_pin_expression(config[CONF_FLOW_CONTROL_PIN]) - cg.add(var.set_flow_control_pin(flow_control_pin)) + await cg.add_pin(var.set_tx_pin, config.get(CONF_TX_PIN)) + await cg.add_pin(var.set_rx_pin, config.get(CONF_RX_PIN)) + await cg.add_pin(var.set_flow_control_pin, config.get(CONF_FLOW_CONTROL_PIN)) if CONF_PORT in config: cg.add(var.set_name(config[CONF_PORT])) cg.add(var.set_rx_buffer_size(config[CONF_RX_BUFFER_SIZE])) @@ -589,8 +583,7 @@ async def register_uart_device(var, config): This is a coroutine, you need to await it with an 'await' expression! """ - parent = await cg.get_variable(config[CONF_UART_ID]) - cg.add(var.set_uart_parent(parent)) + await cg.add_variable(var.set_uart_parent, config[CONF_UART_ID]) def new_uart_component( diff --git a/esphome/components/zigbee/__init__.py b/esphome/components/zigbee/__init__.py index 44f83696f25..c0b0ce453b8 100644 --- a/esphome/components/zigbee/__init__.py +++ b/esphome/components/zigbee/__init__.py @@ -176,9 +176,7 @@ CONFIG_SCHEMA = cv.All( cv.Length(max=31), _validate_ascii, ), - cv.Optional(CONF_VERSION, default=0): cv.All( - cv.int_range(min=0x00, max=0xFF), - ), + cv.Optional(CONF_VERSION, default=0): cv.uint8_t, cv.Optional(CONF_ROUTER, default=False): cv.boolean, cv.Optional(CONF_ON_JOIN): automation.validate_automation({}), cv.Optional(CONF_ON_START): automation.validate_automation({}), diff --git a/esphome/components/zigbee/zigbee_zephyr.py b/esphome/components/zigbee/zigbee_zephyr.py index f7da147b88f..ad2bb4f869e 100644 --- a/esphome/components/zigbee/zigbee_zephyr.py +++ b/esphome/components/zigbee/zigbee_zephyr.py @@ -392,8 +392,7 @@ async def _add_zigbee_ep( cg.add(var.set_endpoint(slot_index + 1)) cg.add(var.set_cluster_attributes(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]) async def add_binary_sensor(entity: cg.MockObj, config: ConfigType) -> None: