mirror of
https://github.com/esphome/esphome.git
synced 2025-09-03 11:52:20 +01:00
Convert automation engine to use variadic templates (#452)
This commit is contained in:
@@ -420,12 +420,11 @@ def process_lambda(value, # type: Lambda
|
||||
|
||||
|
||||
def templatable(value, # type: Any
|
||||
input_type, # type: Expression
|
||||
args, # type: List[Tuple[Expression, str]]
|
||||
output_type # type: Optional[Expression]
|
||||
):
|
||||
if isinstance(value, Lambda):
|
||||
lambda_ = None
|
||||
for lambda_ in process_lambda(value, [(input_type, 'x')], return_type=output_type):
|
||||
for lambda_ in process_lambda(value, args, return_type=output_type):
|
||||
yield None
|
||||
yield lambda_
|
||||
else:
|
||||
@@ -475,9 +474,11 @@ class MockObj(Expression):
|
||||
continue
|
||||
require.require()
|
||||
|
||||
def template(self, args): # type: (Union[TemplateArguments, Expression]) -> MockObj
|
||||
if not isinstance(args, TemplateArguments):
|
||||
args = TemplateArguments(args)
|
||||
def template(self, *args): # type: (Tuple[Union[TemplateArguments, Expression]]) -> MockObj
|
||||
if len(args) != 1 or not isinstance(args[0], TemplateArguments):
|
||||
args = TemplateArguments(*args)
|
||||
else:
|
||||
args = args[0]
|
||||
obj = MockObj(u'{}{}'.format(self.base, args))
|
||||
obj.requires.append(self)
|
||||
obj.requires.append(args)
|
||||
@@ -553,9 +554,14 @@ class MockObjClass(MockObj):
|
||||
return True
|
||||
return False
|
||||
|
||||
def template(self, args): # type: (Union[TemplateArguments, Expression]) -> MockObjClass
|
||||
if not isinstance(args, TemplateArguments):
|
||||
args = TemplateArguments(args)
|
||||
def template(self,
|
||||
*args # type: Tuple[Union[TemplateArguments, Expression]]
|
||||
):
|
||||
# type: (...) -> MockObjClass
|
||||
if len(args) != 1 or not isinstance(args[0], TemplateArguments):
|
||||
args = TemplateArguments(*args)
|
||||
else:
|
||||
args = args[0]
|
||||
new_parents = self._parents[:]
|
||||
new_parents.append(self)
|
||||
obj = MockObjClass(u'{}{}'.format(self.base, args), parents=new_parents)
|
||||
|
Reference in New Issue
Block a user