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

Introduce new async-def coroutine syntax (#1657)

This commit is contained in:
Otto Winter
2021-05-17 07:14:15 +02:00
committed by GitHub
parent 95ed3e9d46
commit d4686c0fb1
10 changed files with 391 additions and 238 deletions

View File

@@ -233,7 +233,7 @@ def include_file(path, basename):
@coroutine_with_priority(-1000.0)
def add_includes(includes):
async def add_includes(includes):
# Add includes at the very end, so that the included files can access global variables
for include in includes:
path = CORE.relative_config_path(include)
@@ -249,7 +249,7 @@ def add_includes(includes):
@coroutine_with_priority(-1000.0)
def _esp8266_add_lwip_type():
async def _esp8266_add_lwip_type():
# If any component has already set this, do not change it
if any(
flag.startswith("-DPIO_FRAMEWORK_ARDUINO_LWIP2_") for flag in CORE.build_flags
@@ -271,25 +271,25 @@ def _esp8266_add_lwip_type():
@coroutine_with_priority(30.0)
def _add_automations(config):
async def _add_automations(config):
for conf in config.get(CONF_ON_BOOT, []):
trigger = cg.new_Pvariable(conf[CONF_TRIGGER_ID], conf.get(CONF_PRIORITY))
yield cg.register_component(trigger, conf)
yield automation.build_automation(trigger, [], conf)
await cg.register_component(trigger, conf)
await automation.build_automation(trigger, [], conf)
for conf in config.get(CONF_ON_SHUTDOWN, []):
trigger = cg.new_Pvariable(conf[CONF_TRIGGER_ID])
yield cg.register_component(trigger, conf)
yield automation.build_automation(trigger, [], conf)
await cg.register_component(trigger, conf)
await automation.build_automation(trigger, [], conf)
for conf in config.get(CONF_ON_LOOP, []):
trigger = cg.new_Pvariable(conf[CONF_TRIGGER_ID])
yield cg.register_component(trigger, conf)
yield automation.build_automation(trigger, [], conf)
await cg.register_component(trigger, conf)
await automation.build_automation(trigger, [], conf)
@coroutine_with_priority(100.0)
def to_code(config):
async def to_code(config):
cg.add_global(cg.global_ns.namespace("esphome").using)
cg.add(
cg.App.pre_setup(