mirror of
https://github.com/esphome/esphome.git
synced 2025-09-23 05:32:22 +01:00
[core] Replace magic coroutine priority numbers with self-documenting CoroPriority enum (#10518)
This commit is contained in:
@@ -39,7 +39,7 @@ from esphome.const import (
|
||||
PlatformFramework,
|
||||
__version__ as ESPHOME_VERSION,
|
||||
)
|
||||
from esphome.core import CORE, coroutine_with_priority
|
||||
from esphome.core import CORE, CoroPriority, coroutine_with_priority
|
||||
from esphome.helpers import (
|
||||
copy_file_if_changed,
|
||||
fnv1a_32bit_hash,
|
||||
@@ -359,7 +359,7 @@ ARDUINO_GLUE_CODE = """\
|
||||
"""
|
||||
|
||||
|
||||
@coroutine_with_priority(-999.0)
|
||||
@coroutine_with_priority(CoroPriority.WORKAROUNDS)
|
||||
async def add_arduino_global_workaround():
|
||||
# The Arduino framework defined these itself in the global
|
||||
# namespace. For the esphome codebase that is not a problem,
|
||||
@@ -376,7 +376,7 @@ async def add_arduino_global_workaround():
|
||||
cg.add_global(cg.RawStatement(line))
|
||||
|
||||
|
||||
@coroutine_with_priority(-1000.0)
|
||||
@coroutine_with_priority(CoroPriority.FINAL)
|
||||
async def add_includes(includes):
|
||||
# Add includes at the very end, so that the included files can access global variables
|
||||
for include in includes:
|
||||
@@ -392,7 +392,7 @@ async def add_includes(includes):
|
||||
include_file(path, basename)
|
||||
|
||||
|
||||
@coroutine_with_priority(-1000.0)
|
||||
@coroutine_with_priority(CoroPriority.FINAL)
|
||||
async def _add_platformio_options(pio_options):
|
||||
# Add includes at the very end, so that they override everything
|
||||
for key, val in pio_options.items():
|
||||
@@ -401,7 +401,7 @@ async def _add_platformio_options(pio_options):
|
||||
cg.add_platformio_option(key, val)
|
||||
|
||||
|
||||
@coroutine_with_priority(30.0)
|
||||
@coroutine_with_priority(CoroPriority.AUTOMATION)
|
||||
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))
|
||||
@@ -423,7 +423,7 @@ async def _add_automations(config):
|
||||
DATETIME_SUBTYPES = {"date", "time", "datetime"}
|
||||
|
||||
|
||||
@coroutine_with_priority(-1000.0)
|
||||
@coroutine_with_priority(CoroPriority.FINAL)
|
||||
async def _add_platform_defines() -> None:
|
||||
# Generate compile-time defines for platforms that have actual entities
|
||||
# Only add USE_* and count defines when there are entities
|
||||
@@ -442,7 +442,7 @@ async def _add_platform_defines() -> None:
|
||||
cg.add_define(f"USE_{platform_name.upper()}")
|
||||
|
||||
|
||||
@coroutine_with_priority(100.0)
|
||||
@coroutine_with_priority(CoroPriority.CORE)
|
||||
async def to_code(config: ConfigType) -> None:
|
||||
cg.add_global(cg.global_ns.namespace("esphome").using)
|
||||
# These can be used by user lambdas, put them to default scope
|
||||
|
Reference in New Issue
Block a user