1
0
mirror of https://github.com/esphome/esphome.git synced 2025-10-30 14:43:51 +00: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

@@ -3,7 +3,7 @@ import esphome.config_validation as cv
from esphome import core, automation
from esphome.automation import maybe_simple_id
from esphome.const import CONF_ID, CONF_LAMBDA, CONF_PAGES, CONF_PAGE_ID, CONF_ROTATION
from esphome.core import coroutine, coroutine_with_priority
from esphome.core import coroutine_with_priority
IS_PLATFORM_COMPONENT = True
@@ -60,14 +60,13 @@ FULL_DISPLAY_SCHEMA = BASIC_DISPLAY_SCHEMA.extend(
)
@coroutine
def setup_display_core_(var, config):
async def setup_display_core_(var, config):
if CONF_ROTATION in config:
cg.add(var.set_rotation(DISPLAY_ROTATIONS[config[CONF_ROTATION]]))
if CONF_PAGES in config:
pages = []
for conf in config[CONF_PAGES]:
lambda_ = yield cg.process_lambda(
lambda_ = await cg.process_lambda(
conf[CONF_LAMBDA], [(DisplayBufferRef, "it")], return_type=cg.void
)
page = cg.new_Pvariable(conf[CONF_ID], lambda_)
@@ -75,9 +74,8 @@ def setup_display_core_(var, config):
cg.add(var.set_pages(pages))
@coroutine
def register_display(var, config):
yield setup_display_core_(var, config)
async def register_display(var, config):
await setup_display_core_(var, config)
@automation.register_action(
@@ -89,15 +87,15 @@ def register_display(var, config):
}
),
)
def display_page_show_to_code(config, action_id, template_arg, args):
async def display_page_show_to_code(config, action_id, template_arg, args):
var = cg.new_Pvariable(action_id, template_arg)
if isinstance(config[CONF_ID], core.Lambda):
template_ = yield cg.templatable(config[CONF_ID], args, DisplayPagePtr)
template_ = await cg.templatable(config[CONF_ID], args, DisplayPagePtr)
cg.add(var.set_page(template_))
else:
paren = yield cg.get_variable(config[CONF_ID])
paren = await cg.get_variable(config[CONF_ID])
cg.add(var.set_page(paren))
yield var
return var
@automation.register_action(
@@ -109,9 +107,9 @@ def display_page_show_to_code(config, action_id, template_arg, args):
}
),
)
def display_page_show_next_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 display_page_show_next_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)
@automation.register_action(
@@ -123,9 +121,9 @@ def display_page_show_next_to_code(config, action_id, template_arg, args):
}
),
)
def display_page_show_previous_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 display_page_show_previous_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)
@automation.register_condition(
@@ -149,5 +147,5 @@ def display_is_displaying_page_to_code(config, condition_id, template_arg, args)
@coroutine_with_priority(100.0)
def to_code(config):
async def to_code(config):
cg.add_global(display_ns.using)