feat: add support for local expressions in ADExpressionContext and update smart condition handling
This commit is contained in:
@@ -31,6 +31,7 @@ class Evaluator():
|
||||
__LOG_INIT = "log_init"
|
||||
__EXTRA_ENTITIES_TO_LISTEN = "extra_entities_to_listen"
|
||||
__CONSTANTS = "constants"
|
||||
__LOCAL_EXPRESSIONS_STRING = "local_expressions"
|
||||
__UNAVAIBILITY_RESULT = "unavaibility_result"
|
||||
|
||||
def __init__(self, appdaemon_api, conditions_block,**kwargs):
|
||||
@@ -313,6 +314,12 @@ class Evaluator():
|
||||
if disable_conditions_args:
|
||||
add_conditions_to_conditions_block(conditions_block,self.__DISABLE_CONDITIONS_STRING,disable_conditions_args)
|
||||
|
||||
local_expressions_args = param_parser.parse_args(self.__LOCAL_EXPRESSIONS_STRING, None)
|
||||
if local_expressions_args:
|
||||
if self.__LOCAL_EXPRESSIONS_STRING not in conditions_block:
|
||||
conditions_block[self.__LOCAL_EXPRESSIONS_STRING] = {}
|
||||
conditions_block[self.__LOCAL_EXPRESSIONS_STRING].update(local_expressions_args)
|
||||
|
||||
if param_parser.parse_args(self.__TEMPLATE_CONDITIONS_STRING, None):
|
||||
self.__log(f"Template '{template}' contain recursive template",level = "ERROR")
|
||||
|
||||
@@ -377,7 +384,19 @@ class Evaluator():
|
||||
if self.__log_init:
|
||||
self.__log(f"{constant_name} = {value}")
|
||||
self.expression_context.declare_constant(constant_name,value)
|
||||
|
||||
|
||||
local_expressions = param_parser.parse_args(self.__LOCAL_EXPRESSIONS_STRING, None)
|
||||
if local_expressions:
|
||||
if self.__log_init:
|
||||
self.__log(f"declaring local expressions:")
|
||||
for expr_name, expr_string in local_expressions.items():
|
||||
if self.__log_init:
|
||||
self.__log(f"{expr_name} = {expr_string}")
|
||||
self.expression_context.declare_local_expression(expr_name, str(expr_string))
|
||||
# Ensure sensors referenced only in local_expressions are registered as
|
||||
# listeners even if no condition string references them directly.
|
||||
self.__add_to_entities_to_listen(self.expression_context.get_entities_to_listen())
|
||||
|
||||
|
||||
trigger_conditions_args = param_parser.parse_args(self.__TRIGGER_CONDITIONS_STRING,None)
|
||||
if trigger_conditions_args:
|
||||
|
||||
Reference in New Issue
Block a user