[components] Use the codegen helpers in the remaining components (#21078)

This commit is contained in:
J. Nick Koston
2026-10-18 14:05:37 -10:00
committed by GitHub
parent d9242520e3
commit 84ce39e493
42 changed files with 66 additions and 184 deletions
+10 -9
View File
@@ -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(
{
+1 -4
View File
@@ -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)
+2 -4
View File
@@ -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))
@@ -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)
+1 -2
View File
@@ -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.
+1 -2
View File
@@ -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.
+3 -12
View File
@@ -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:
+1 -5
View File
@@ -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)
+1 -2
View File
@@ -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]))
+1 -5
View File
@@ -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):
+1 -2
View File
@@ -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]))
+3 -8
View File
@@ -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]))
+1 -5
View File
@@ -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)
+1 -3
View File
@@ -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))
+1 -3
View File
@@ -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")
+1 -2
View File
@@ -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:
+1 -2
View File
@@ -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
+1 -5
View File
@@ -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]))
+1 -2
View File
@@ -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]))
+2 -11
View File
@@ -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)
@@ -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,
+2 -5
View File
@@ -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))
+1 -2
View File
@@ -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)
+1 -3
View File
@@ -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))
+1 -4
View File
@@ -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)
+1 -6
View File
@@ -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")
+1 -2
View File
@@ -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:
+1 -2
View File
@@ -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:
+1 -2
View File
@@ -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:
+1 -5
View File
@@ -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)
+1 -5
View File
@@ -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)
+1 -2
View File
@@ -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:
+1 -3
View File
@@ -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))
+1 -2
View File
@@ -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:
+1 -5
View File
@@ -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)
@@ -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)
+3 -10
View File
@@ -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]))
+1 -2
View File
@@ -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:
@@ -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),
+4 -11
View File
@@ -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(
+1 -3
View File
@@ -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({}),
+1 -2
View File
@@ -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: