1
0
mirror of https://github.com/esphome/esphome.git synced 2025-09-02 11:22:24 +01:00

[quality] Convert remaining `to_code to async` (#10271)

This commit is contained in:
Jesse Hills
2025-08-20 14:34:45 +12:00
committed by GitHub
parent 9b1ebdb6da
commit a45137434b
9 changed files with 34 additions and 36 deletions

View File

@@ -18,6 +18,6 @@ CONFIG_SCHEMA = cv.Schema(
).extend(esp32_ble_tracker.ESP_BLE_DEVICE_SCHEMA)
def to_code(config):
async def to_code(config):
var = cg.new_Pvariable(config[CONF_ID])
yield esp32_ble_tracker.register_ble_device(var, config)
await esp32_ble_tracker.register_ble_device(var, config)

View File

@@ -27,7 +27,7 @@ CONFIG_SCHEMA = cv.All(
)
def to_code(config):
async def to_code(config):
var = cg.new_Pvariable(config[CONF_ID])
if len(config[CONF_SERVICE_UUID]) == len(esp32_ble_tracker.bt_uuid16_format):
cg.add(
@@ -63,6 +63,6 @@ def to_code(config):
)
cg.add(var.set_char_uuid128(uuid128))
cg.add(var.set_require_response(config[CONF_REQUIRE_RESPONSE]))
yield output.register_output(var, config)
yield ble_client.register_ble_node(var, config)
yield cg.register_component(var, config)
await output.register_output(var, config)
await ble_client.register_ble_node(var, config)
await cg.register_component(var, config)

View File

@@ -228,9 +228,9 @@ async def cover_stop_to_code(config, action_id, template_arg, args):
@automation.register_action("cover.toggle", ToggleAction, COVER_ACTION_SCHEMA)
def cover_toggle_to_code(config, action_id, template_arg, args):
paren = yield cg.get_variable(config[CONF_ID])
yield cg.new_Pvariable(action_id, template_arg, paren)
async def cover_toggle_to_code(config, action_id, template_arg, args):
paren = await cg.get_variable(config[CONF_ID])
return cg.new_Pvariable(action_id, template_arg, paren)
COVER_CONTROL_ACTION_SCHEMA = cv.Schema(

View File

@@ -26,7 +26,7 @@ CONFIG_SCHEMA = cv.All(
)
def to_code(config):
async def to_code(config):
var = cg.new_Pvariable(config[CONF_ID])
yield cg.register_component(var, config)
yield uart.register_uart_device(var, config)
await cg.register_component(var, config)
await uart.register_uart_device(var, config)

View File

@@ -99,9 +99,9 @@ async def to_code(config):
}
),
)
def output_pipsolar_set_level_to_code(config, action_id, template_arg, args):
paren = yield cg.get_variable(config[CONF_ID])
async def output_pipsolar_set_level_to_code(config, action_id, template_arg, args):
paren = await cg.get_variable(config[CONF_ID])
var = cg.new_Pvariable(action_id, template_arg, paren)
template_ = yield cg.templatable(config[CONF_VALUE], args, float)
template_ = await cg.templatable(config[CONF_VALUE], args, float)
cg.add(var.set_level(template_))
yield var
return var

View File

@@ -18,6 +18,6 @@ CONFIG_SCHEMA = cv.Schema(
).extend(esp32_ble_tracker.ESP_BLE_DEVICE_SCHEMA)
def to_code(config):
async def to_code(config):
var = cg.new_Pvariable(config[CONF_ID])
yield esp32_ble_tracker.register_ble_device(var, config)
await esp32_ble_tracker.register_ble_device(var, config)

View File

@@ -1782,14 +1782,12 @@ def nexa_dumper(var, config):
@register_action("nexa", NexaAction, NEXA_SCHEMA)
def nexa_action(var, config, args):
cg.add(var.set_device((yield cg.templatable(config[CONF_DEVICE], args, cg.uint32))))
cg.add(var.set_group((yield cg.templatable(config[CONF_GROUP], args, cg.uint8))))
cg.add(var.set_state((yield cg.templatable(config[CONF_STATE], args, cg.uint8))))
cg.add(
var.set_channel((yield cg.templatable(config[CONF_CHANNEL], args, cg.uint8)))
)
cg.add(var.set_level((yield cg.templatable(config[CONF_LEVEL], args, cg.uint8))))
async def nexa_action(var, config, args):
cg.add(var.set_device(await cg.templatable(config[CONF_DEVICE], args, cg.uint32)))
cg.add(var.set_group(await cg.templatable(config[CONF_GROUP], args, cg.uint8)))
cg.add(var.set_state(await cg.templatable(config[CONF_STATE], args, cg.uint8)))
cg.add(var.set_channel(await cg.templatable(config[CONF_CHANNEL], args, cg.uint8)))
cg.add(var.set_level(await cg.templatable(config[CONF_LEVEL], args, cg.uint8)))
# Midea

View File

@@ -183,7 +183,7 @@ CONFIG_SCHEMA = (
)
def to_code(config):
async def to_code(config):
fw_hex = get_firmware(config[CONF_FIRMWARE])
fw_major, fw_minor = parse_firmware_version(config[CONF_FIRMWARE][CONF_VERSION])
@@ -193,17 +193,17 @@ def to_code(config):
cg.add_define("USE_SHD_FIRMWARE_MINOR_VERSION", fw_minor)
var = cg.new_Pvariable(config[CONF_OUTPUT_ID])
yield cg.register_component(var, config)
await cg.register_component(var, config)
config.pop(
CONF_UPDATE_INTERVAL
) # drop UPDATE_INTERVAL as it does not apply to the light component
yield light.register_light(var, config)
yield uart.register_uart_device(var, config)
await light.register_light(var, config)
await uart.register_uart_device(var, config)
nrst_pin = yield cg.gpio_pin_expression(config[CONF_NRST_PIN])
nrst_pin = await cg.gpio_pin_expression(config[CONF_NRST_PIN])
cg.add(var.set_nrst_pin(nrst_pin))
boot0_pin = yield cg.gpio_pin_expression(config[CONF_BOOT0_PIN])
boot0_pin = await cg.gpio_pin_expression(config[CONF_BOOT0_PIN])
cg.add(var.set_boot0_pin(boot0_pin))
cg.add(var.set_leading_edge(config[CONF_LEADING_EDGE]))
@@ -217,5 +217,5 @@ def to_code(config):
continue
conf = config[key]
sens = yield sensor.new_sensor(conf)
sens = await sensor.new_sensor(conf)
cg.add(getattr(var, f"set_{key}_sensor")(sens))

View File

@@ -202,9 +202,9 @@ async def valve_stop_to_code(config, action_id, template_arg, args):
@automation.register_action("valve.toggle", ToggleAction, VALVE_ACTION_SCHEMA)
def valve_toggle_to_code(config, action_id, template_arg, args):
paren = yield cg.get_variable(config[CONF_ID])
yield cg.new_Pvariable(action_id, template_arg, paren)
async def valve_toggle_to_code(config, action_id, template_arg, args):
paren = await cg.get_variable(config[CONF_ID])
return cg.new_Pvariable(action_id, template_arg, paren)
VALVE_CONTROL_ACTION_SCHEMA = cv.Schema(