1
0
mirror of https://github.com/esphome/esphome.git synced 2025-10-01 09:32:21 +01:00

Convert core components to async-def coroutine syntax (#1658)

Co-authored-by: Guillermo Ruffino <glm.net@gmail.com>
Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>
This commit is contained in:
Otto Winter
2021-05-23 22:10:30 +02:00
committed by GitHub
parent 514d11d46f
commit aebad04c0b
29 changed files with 313 additions and 359 deletions

View File

@@ -11,7 +11,7 @@ from esphome.const import (
CONF_RX_BUFFER_SIZE,
CONF_INVERT,
)
from esphome.core import CORE, coroutine
from esphome.core import CORE
CODEOWNERS = ["@esphome/core"]
uart_ns = cg.esphome_ns.namespace("uart")
@@ -73,10 +73,10 @@ CONFIG_SCHEMA = cv.All(
)
def to_code(config):
async def to_code(config):
cg.add_global(uart_ns.using)
var = cg.new_Pvariable(config[CONF_ID])
yield cg.register_component(var, config)
await cg.register_component(var, config)
cg.add(var.set_baud_rate(config[CONF_BAUD_RATE]))
@@ -100,13 +100,12 @@ UART_DEVICE_SCHEMA = cv.Schema(
)
@coroutine
def register_uart_device(var, config):
async def register_uart_device(var, config):
"""Register a UART device, setting up all the internal values.
This is a coroutine, you need to await it with a 'yield' expression!
"""
parent = yield cg.get_variable(config[CONF_UART_ID])
parent = await cg.get_variable(config[CONF_UART_ID])
cg.add(var.set_uart_parent(parent))
@@ -121,16 +120,16 @@ def register_uart_device(var, config):
key=CONF_DATA,
),
)
def uart_write_to_code(config, action_id, template_arg, args):
async def uart_write_to_code(config, action_id, template_arg, args):
var = cg.new_Pvariable(action_id, template_arg)
yield cg.register_parented(var, config[CONF_ID])
await cg.register_parented(var, config[CONF_ID])
data = config[CONF_DATA]
if isinstance(data, bytes):
data = list(data)
if cg.is_template(data):
templ = yield cg.templatable(data, args, cg.std_vector.template(cg.uint8))
templ = await cg.templatable(data, args, cg.std_vector.template(cg.uint8))
cg.add(var.set_data_template(templ))
else:
cg.add(var.set_data_static(data))
yield var
return var