From 8fe60b69c627eb1799d5a8039b10617e7658f22f Mon Sep 17 00:00:00 2001 From: Onkel Andy Date: Sat, 9 Sep 2023 00:25:33 +0200 Subject: [PATCH 1/8] stateengine plugin: fix delayed execution for new scheduler caller --- stateengine/StateEngineAction.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/stateengine/StateEngineAction.py b/stateengine/StateEngineAction.py index 6848f21a5..e2b7f41dc 100755 --- a/stateengine/StateEngineAction.py +++ b/stateengine/StateEngineAction.py @@ -569,12 +569,12 @@ def _waitforexecute(self, state, actionname: str, namevar: str = "", repeat_text 'previousstate_condition': previousstate_condition, 'state': state}, next=next_run) - def _delayed_execute(self, actionname: str, namevar: str = "", repeat_text: str = "", value=None, current_condition=None, previous_condition=None, previousstate_condition=None, state=None): + def _delayed_execute(self, actionname: str, namevar: str = "", repeat_text: str = "", value=None, current_condition=None, previous_condition=None, previousstate_condition=None, state=None, caller=None): if state: - self._log_debug("Putting delayed action '{}' from state '{}' into queue.", namevar, state) + self._log_debug("Putting delayed action '{}' from state '{}' into queue. Caller: {}", namevar, state, caller) self.__queue.put(["delayedaction", self, actionname, namevar, repeat_text, value, current_condition, previous_condition, previousstate_condition, state]) else: - self._log_debug("Putting delayed action '{}' into queue.", namevar) + self._log_debug("Putting delayed action '{}' into queue. Caller: {}", namevar, caller) self.__queue.put(["delayedaction", self, actionname, namevar, repeat_text, value, current_condition, previous_condition, previousstate_condition]) if not self._abitem.update_lock.locked(): self._log_debug("Running queue") From 5486efd72096aa427705b3026ae3245c35d96dd9 Mon Sep 17 00:00:00 2001 From: Onkel Andy Date: Sat, 9 Sep 2023 00:25:51 +0200 Subject: [PATCH 2/8] stateengine plugin: fix manual logger --- stateengine/StateEngineFunctions.py | 2 +- stateengine/StateEngineLogger.py | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/stateengine/StateEngineFunctions.py b/stateengine/StateEngineFunctions.py index 6b90c0822..0a5eed057 100755 --- a/stateengine/StateEngineFunctions.py +++ b/stateengine/StateEngineFunctions.py @@ -83,7 +83,7 @@ def manual_item_update_eval(self, item_id, caller=None, source=None): self.logger.error("manual_item_update_item: se_manual_logitem {0} not found!".format(elog_item_id)) elog = StateEngineLogger.SeLoggerDummy() else: - elog = StateEngineLogger.SeLogger.create(elog_item) + elog = StateEngineLogger.SeLogger.create(elog_item, manual=True) else: elog = StateEngineLogger.SeLoggerDummy() elog.header("manual_item_update_eval") diff --git a/stateengine/StateEngineLogger.py b/stateengine/StateEngineLogger.py index acf5460f5..07eabac00 100755 --- a/stateengine/StateEngineLogger.py +++ b/stateengine/StateEngineLogger.py @@ -122,17 +122,20 @@ def remove_old_logfiles(): # Return SeLogger instance for given item # item: item for which the detailed log is @staticmethod - def create(item): - return SeLogger(item) + def create(item, manual=False): + return SeLogger(item, manual) # Constructor # item: item for which the detailed log is (used as part of file name) - def __init__(self, item): + def __init__(self, item, manual=False): self.logger = logging.getLogger('stateengine.{}'.format(item.property.path)) self.__name = 'stateengine.{}'.format(item.property.path) self.__section = item.property.path.replace(".", "_").replace("/", "") self.__indentlevel = 0 - self.__log_level_as_num = 0 + if manual: + self.__log_level_as_num = 2 + else: + self.__log_level_as_num = 0 self.__logmaxage = None self.__date = None self.__logerror = False From 82b64a118505f2dd1f3994b7bc05568c45ff19c7 Mon Sep 17 00:00:00 2001 From: Onkel Andy Date: Sat, 9 Sep 2023 02:21:40 +0200 Subject: [PATCH 3/8] stateengine plugin: fix exception when original caller function doesn't return an item --- stateengine/StateEngineItem.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/stateengine/StateEngineItem.py b/stateengine/StateEngineItem.py index 1ef03cfc5..669898e55 100755 --- a/stateengine/StateEngineItem.py +++ b/stateengine/StateEngineItem.py @@ -524,6 +524,8 @@ def run_queue(self): # Find out what initially caused the update to trigger if the caller is "Eval" orig_caller, orig_source, orig_item = StateEngineTools.get_original_caller(self.__logger, caller, source, item) + if orig_item is None: + orig_item = item if orig_caller != caller: text = "{0} initially triggered by {1} (item={2} source={3} value={4})." self.__logger.debug(text, caller, orig_caller, orig_item.property.path, From 91f4f83b699a961db6208cce516807030813565e Mon Sep 17 00:00:00 2001 From: Onkel Andy Date: Sat, 9 Sep 2023 09:23:38 +0200 Subject: [PATCH 4/8] stateengine plugin: fix searching for original caller to work with recent scheduler/caller changes from core --- stateengine/StateEngineTools.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/stateengine/StateEngineTools.py b/stateengine/StateEngineTools.py index da3f9c4af..b4589b53d 100755 --- a/stateengine/StateEngineTools.py +++ b/stateengine/StateEngineTools.py @@ -327,6 +327,7 @@ def get_eval_name(eval_func): # item: item being updated # eval_type: update or change def get_original_caller(elog, caller, source, item=None, eval_keyword=['Eval'], eval_type='update'): + eval_keyword = [caller] original_caller = caller original_item = item if isinstance(source, str): @@ -336,7 +337,7 @@ def get_original_caller(elog, caller, source, item=None, eval_keyword=['Eval'], while original_caller in eval_keyword: original_item = itemsApi.return_item(original_source) if original_item is None: - elog.warning("get_caller({0}, {1}): original item not found", caller, source) + elog.info("get_caller({0}, {1}): original item not found", caller, source) break original_manipulated_by = original_item.property.last_update_by if eval_type == "update" else \ original_item.property.last_change_by From e9bdaa51aee5e517450ca3369600b0469392e23e Mon Sep 17 00:00:00 2001 From: Onkel Andy Date: Mon, 11 Sep 2023 00:12:16 +0200 Subject: [PATCH 5/8] stateengine plugin: auto update webif on start to automatically find out when visu can be redrawn. --- stateengine/webif/templates/visu.html | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/stateengine/webif/templates/visu.html b/stateengine/webif/templates/visu.html index d5a076db3..11ea42a7b 100755 --- a/stateengine/webif/templates/visu.html +++ b/stateengine/webif/templates/visu.html @@ -51,9 +51,6 @@ {% endblock pluginstyles %} {% block pluginscripts %} {% endblock pluginscripts %} From 916ccc652d136fb6dfa3005fa7eba3a5764b51e4 Mon Sep 17 00:00:00 2001 From: Onkel Andy Date: Mon, 11 Sep 2023 00:12:43 +0200 Subject: [PATCH 6/8] stateengine plugin: make original caller finding work with latest changes of core --- stateengine/StateEngineTools.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/stateengine/StateEngineTools.py b/stateengine/StateEngineTools.py index b4589b53d..a924acf64 100755 --- a/stateengine/StateEngineTools.py +++ b/stateengine/StateEngineTools.py @@ -327,14 +327,13 @@ def get_eval_name(eval_func): # item: item being updated # eval_type: update or change def get_original_caller(elog, caller, source, item=None, eval_keyword=['Eval'], eval_type='update'): - eval_keyword = [caller] original_caller = caller original_item = item if isinstance(source, str): original_source = source else: original_source = "None" - while original_caller in eval_keyword: + while partition_strip(original_caller, ":")[0] in eval_keyword: original_item = itemsApi.return_item(original_source) if original_item is None: elog.info("get_caller({0}, {1}): original item not found", caller, source) From 3e92e4f134d05efdb28c4b93cdda20784974e02f Mon Sep 17 00:00:00 2001 From: Onkel Andy Date: Mon, 11 Sep 2023 00:14:06 +0200 Subject: [PATCH 7/8] stateengine plugin: minor code refactor for stateengine tools --- stateengine/StateEngineTools.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stateengine/StateEngineTools.py b/stateengine/StateEngineTools.py index a924acf64..23703918b 100755 --- a/stateengine/StateEngineTools.py +++ b/stateengine/StateEngineTools.py @@ -124,7 +124,7 @@ def parse_relative(evalstr, begintag, endtags): rel = rest[:rest.find(endtag)] rest = rest[rest.find(endtag)+len(endtag):] if 'property' in endtag: - rest1 = re.split('( |\+|-|\*|/)', rest, 1) + rest1 = re.split('([ +\-*/])', rest, 1) rest = ''.join(rest1[1:]) pref += "se_eval.get_relative_itemproperty('{}', '{}')".format(rel, rest1[0]) elif '()' in endtag: From e8ac3784f6187efd837e1ed516623ae4f1e8b558 Mon Sep 17 00:00:00 2001 From: Onkel Andy Date: Mon, 11 Sep 2023 00:15:47 +0200 Subject: [PATCH 8/8] stateengine plugin: improve log entries for elog (update of manuell item) --- stateengine/StateEngineFunctions.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/stateengine/StateEngineFunctions.py b/stateengine/StateEngineFunctions.py index 0a5eed057..dc66feee0 100755 --- a/stateengine/StateEngineFunctions.py +++ b/stateengine/StateEngineFunctions.py @@ -87,7 +87,7 @@ def manual_item_update_eval(self, item_id, caller=None, source=None): else: elog = StateEngineLogger.SeLoggerDummy() elog.header("manual_item_update_eval") - elog.info("running for item '{0}' source '{1}' caller '{2}'", item_id, caller, source) + elog.info("running for item '{0}' source '{1}' caller '{2}'", item_id, source, caller) retval_no_trigger = item() retval_trigger = not item() @@ -121,7 +121,9 @@ def manual_item_update_eval(self, item_id, caller=None, source=None): result = entry.match(original) elog.info("Checking regex result {}", result) if result is not None: - elog.info("{0}: matching. Writing value {1}", entry, retval_no_trigger) + elog.info("{0}: matching.", entry) + elog.decrease_indent() + elog.info("Writing value {0}", retval_no_trigger) return retval_no_trigger elog.info("{0}: not matching", entry) elog.decrease_indent() @@ -144,7 +146,9 @@ def manual_item_update_eval(self, item_id, caller=None, source=None): result = entry.match(original) elog.info("Checking regex result {}", result) if result is not None: - elog.info("{0}: matching. Writing value {1}", entry, retval_no_trigger) + elog.info("{0}: matching.", entry) + elog.decrease_indent() + elog.info("Writing value {0}", retval_no_trigger) return retval_no_trigger elog.info("{0}: not matching", entry) elog.decrease_indent() @@ -166,7 +170,9 @@ def manual_item_update_eval(self, item_id, caller=None, source=None): result = entry.match(original) elog.info("Checking regex result {}", result) if result is not None: - elog.info("{0}: matching. Writing value {1}", entry, retval_trigger) + elog.info("{0}: matching.", entry) + elog.decrease_indent() + elog.info("Writing value {0}", retval_no_trigger) return retval_trigger elog.info("{0}: not matching", entry) elog.decrease_indent()