mirror of
https://github.com/esphome/esphome.git
synced 2025-09-02 19:32:19 +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:
@@ -575,8 +575,7 @@ async def get_variable_with_full_id(id_: ID) -> Tuple[ID, "MockObj"]:
|
||||
return await CORE.get_variable_with_full_id(id_)
|
||||
|
||||
|
||||
@coroutine
|
||||
def process_lambda(
|
||||
async def process_lambda(
|
||||
value: Lambda,
|
||||
parameters: List[Tuple[SafeExpType, str]],
|
||||
capture: str = "=",
|
||||
@@ -596,11 +595,10 @@ def process_lambda(
|
||||
from esphome.components.globals import GlobalsComponent
|
||||
|
||||
if value is None:
|
||||
yield
|
||||
return
|
||||
parts = value.parts[:]
|
||||
for i, id in enumerate(value.requires_ids):
|
||||
full_id, var = yield get_variable_with_full_id(id)
|
||||
full_id, var = await get_variable_with_full_id(id)
|
||||
if (
|
||||
full_id is not None
|
||||
and isinstance(full_id.type, MockObjClass)
|
||||
@@ -620,7 +618,7 @@ def process_lambda(
|
||||
location.line += value.content_offset
|
||||
else:
|
||||
location = None
|
||||
yield LambdaExpression(parts, parameters, capture, return_type, location)
|
||||
return LambdaExpression(parts, parameters, capture, return_type, location)
|
||||
|
||||
|
||||
def is_template(value):
|
||||
@@ -628,8 +626,7 @@ def is_template(value):
|
||||
return isinstance(value, Lambda)
|
||||
|
||||
|
||||
@coroutine
|
||||
def templatable(
|
||||
async def templatable(
|
||||
value: Any,
|
||||
args: List[Tuple[SafeExpType, str]],
|
||||
output_type: Optional[SafeExpType],
|
||||
@@ -647,15 +644,12 @@ def templatable(
|
||||
:return: The potentially templated value.
|
||||
"""
|
||||
if is_template(value):
|
||||
lambda_ = yield process_lambda(value, args, return_type=output_type)
|
||||
yield lambda_
|
||||
else:
|
||||
if to_exp is None:
|
||||
yield value
|
||||
elif isinstance(to_exp, dict):
|
||||
yield to_exp[value]
|
||||
else:
|
||||
yield to_exp(value)
|
||||
return await process_lambda(value, args, return_type=output_type)
|
||||
if to_exp is None:
|
||||
return value
|
||||
if isinstance(to_exp, dict):
|
||||
return to_exp[value]
|
||||
return to_exp(value)
|
||||
|
||||
|
||||
class MockObj(Expression):
|
||||
|
Reference in New Issue
Block a user