Skip to content

Commit

Permalink
Merge pull request #810 from onkelandy/stateengine
Browse files Browse the repository at this point in the history
Stateengine Updates for recent scheduler/caller changes in core
  • Loading branch information
onkelandy authored Sep 10, 2023
2 parents 085dca6 + e8ac378 commit e21f1e3
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 18 deletions.
6 changes: 3 additions & 3 deletions stateengine/StateEngineAction.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
16 changes: 11 additions & 5 deletions stateengine/StateEngineFunctions.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,11 @@ 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")
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()
Expand Down Expand Up @@ -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()
Expand All @@ -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()
Expand All @@ -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()
Expand Down
2 changes: 2 additions & 0 deletions stateengine/StateEngineItem.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
11 changes: 7 additions & 4 deletions stateengine/StateEngineLogger.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions stateengine/StateEngineTools.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -333,10 +333,10 @@ def get_original_caller(elog, caller, source, item=None, eval_keyword=['Eval'],
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.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
Expand Down
7 changes: 4 additions & 3 deletions stateengine/webif/templates/visu.html
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,6 @@
{% endblock pluginstyles %}
{% block pluginscripts %}
<script src="static/panzoom.min.js">
if ("{{firstrun}}" != 'None'){
window.update_active = true;
refresh.set_interval(5000, false);
</script>
<script>
function refreshGraph() {
Expand Down Expand Up @@ -149,6 +146,10 @@
<script>
window.addEventListener('load', function() {
initPanzoom();
if ("{{firstrun}}" != 'None'){
window.update_active = true;
refresh.set_interval(5000, false);
}
});
</script>
{% endblock pluginscripts %}
Expand Down

0 comments on commit e21f1e3

Please sign in to comment.