Skip to content

Commit

Permalink
stateengine plugin: allow list in se_use eval/item declaration
Browse files Browse the repository at this point in the history
  • Loading branch information
onkelandy committed Oct 3, 2023
1 parent a1f14b5 commit 5fa6e35
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions stateengine/StateEngineState.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,7 @@ def write_to_log(self):
self.__is_copy_for.write_to_logger()
self.__releasedby.write_to_logger()
self.__can_release.write_to_logger()
if self.__use_done:
_log_se_use = self.__use_done[0] if len(self.__use_done) == 1 else self.__use_done
self._log_info("State configuration extended by se_use: {}", _log_se_use)
self.__use.write_to_logger()

self._log_info("Updating Web Interface...")
self._log_increase_indent()
Expand Down Expand Up @@ -379,6 +377,14 @@ def update_name(self, item_state, recursion_depth=0):
self.__name = self.text
return self.__name

def __fill_list(self, item_states, recursion_depth, se_use=None):
for i, element in enumerate(item_states):
if element == self.state_item:
self._log_info("Use element {} is same as current state - Ignoring.", element)
elif element is not None:
self.__fill(element, recursion_depth, se_use[i])
self.__use_done.append(element)

# Read configuration from item and populate data in class
# item_state: item to read from
# recursion_depth: current recursion_depth (recursion is canceled after five levels)
Expand All @@ -398,7 +404,6 @@ def update_action_status(action_status, actiontype):
if action_status is None:
return
action_status = StateEngineTools.flatten_list(action_status)
#self._log_debug("Action status: {}", action_status)
if isinstance(action_status, list):
for e in action_status:
update_action_status(e, actiontype)
Expand Down Expand Up @@ -464,7 +469,7 @@ def update_action_status(action_status, actiontype):
{item_state.property.path: {'issue': _issue, 'attribute': 'se_use'}})
self._log_warning("{} - ignoring.", _issue)
else:
_use = [_use] if not isinstance(_use, list) else StateEngineTools.flatten_list(_use)
_use = [_use] if not isinstance(_use, list) else _use
_returntype = [_returntype] if not isinstance(_returntype, list) else _returntype
cleaned_use_list = []
for i, element in enumerate(_use):
Expand Down Expand Up @@ -504,15 +509,20 @@ def update_action_status(action_status, actiontype):
_path = _configvalue[i]
self._log_info("se_use {} defined by item/eval. Even if current result is not valid, "
"entry will be re-evaluated on next state evaluation.", _path)
if _path not in cleaned_use_list:
if _path is not None and _path not in cleaned_use_list:
cleaned_use_list.append(_path)
self.__use_done.append(_path)
if _path is None:
pass
elif _fill and element not in self.__use_done:
elif element == self.state_item:
self._log_info("Use element {} is same as current state - Ignoring.", _name)
elif _fill and element is not None and element not in self.__use_done:
self._log_develop("Adding element {} to state fill function.", _name)
self.__use_done.append(element)
self.__fill(element, recursion_depth + 1, _name)

if isinstance(_name, list):
self.__fill_list(element, recursion_depth + 1, _name)
else:
self.__use_done.append(element)
self.__fill(element, recursion_depth + 1, _name)
self.__use.set(cleaned_use_list)

# Get action sets and condition sets
Expand Down

0 comments on commit 5fa6e35

Please sign in to comment.