Skip to content

Commit

Permalink
Merge pull request #790 from onkelandy/stateengine
Browse files Browse the repository at this point in the history
Stateengine Plugin 2.0.0
  • Loading branch information
onkelandy authored Aug 31, 2023
2 parents 58a91e8 + b5d55b3 commit 1fbe62d
Show file tree
Hide file tree
Showing 32 changed files with 2,814 additions and 1,208 deletions.
628 changes: 412 additions & 216 deletions stateengine/StateEngineAction.py

Large diffs are not rendered by default.

43 changes: 30 additions & 13 deletions stateengine/StateEngineActions.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,14 @@
#########################################################################
from . import StateEngineAction
from . import StateEngineTools

import ast
import threading
import queue


# Class representing a list of actions
class SeActions(StateEngineTools.SeItemChild):
@property
def dict_actions(self):
result = {}
for name in self.__actions:
self._abitem._initactionname = name
result.update({name: self.__actions[name].get()})
self._abitem._initactionname = None
return result

# Initialize the set of actions
# abitem: parent SeItem instance
Expand All @@ -56,6 +49,21 @@ def __init__(self, abitem):
def __repr__(self):
return "SeActions, count {}".format(self.count())

def dict_actions(self, type, state):
result = {}
for name in self.__actions:
self._abitem._initactionname = name
result.update({name: self.__actions[name].get()})
try:
result[name].update({'actionstatus': self._abitem.webif_infos[state][type][name].get('actionstatus')})
except Exception:
pass
self._abitem._initactionname = None
return result

def reset(self):
self.__actions = {}

# Return number of actions in list
def count(self):
return len(self.__actions)
Expand All @@ -67,6 +75,7 @@ def update(self, attribute, value):
# Split attribute in function and action name
func, name = StateEngineTools.partition_strip(attribute, "_")
_count = 0
_issue = None
try:
if func == "se_delay":
# set delay
Expand Down Expand Up @@ -133,17 +142,18 @@ def update(self, attribute, value):
self.__actions[name].update_order(value)
return
elif func == "se_action": # and name not in self.__actions:
self.__handle_combined_action_attribute(name, value)
_issue = self.__handle_combined_action_attribute(name, value)
_count += 1
elif self.__ensure_action_exists(func, name):
# update action
self.__actions[name].update(value)
_issue = self.__actions[name].update(value)
_count += 1
except ValueError as ex:
if name in self.__actions:
del self.__actions[name]
_issue = {name: {'issue': ex, 'issueorigin': [{'state': 'unknown', 'action': 'unknown'}]}}
self._log_warning("Ignoring action {0} because: {1}", attribute, ex)
return _count
return _count, _issue

# ensure that action exists and create if missing
# func: action function
Expand Down Expand Up @@ -279,6 +289,7 @@ def __handle_combined_action_attribute(self, name, value_list):

# create action based on function
exists = False
_issue = None
try:
if parameter['function'] == "set":
if self.__ensure_action_exists("se_set", name):
Expand Down Expand Up @@ -342,6 +353,7 @@ def __handle_combined_action_attribute(self, name, value_list):
exists = False
if name in self.__actions:
del self.__actions[name]
_issue = {name: {'issue': ex, 'issueorigin': [{'state': 'unknown', 'action': 'unknown'}]}}
self._log_warning("Ignoring action {0} because: {1}", name, ex)

# add additional parameters
Expand All @@ -363,6 +375,8 @@ def __handle_combined_action_attribute(self, name, value_list):
if parameter['mode'] is not None:
self.__actions[name].update_modes(parameter['mode'])

return _issue

# noinspection PyMethodMayBeStatic
def __raise_missing_parameter_error(self, parameter, param_name):
if param_name not in parameter or parameter[param_name] is None:
Expand All @@ -372,11 +386,14 @@ def __raise_missing_parameter_error(self, parameter, param_name):
# Check the actions optimize and complete them
# item_state: item to read from
def complete(self, item_state, evals_items=None):
_status = {}
for name in self.__actions:
try:
self.__actions[name].complete(item_state, evals_items)
_status.update(self.__actions[name].complete(item_state, evals_items))
except ValueError as ex:
_status.update({name: {'issue': ex, 'issueorigin': {'state': item_state.property.path, 'action': 'unknown'}}})
raise ValueError("State '{0}', Action '{1}': {2}".format(item_state.property.path, name, ex))
return _status

def set(self, value):
for name in self.__actions:
Expand All @@ -390,7 +407,7 @@ def set(self, value):
# item_allow_repeat: Is repeating actions generally allowed for the item?
# state: state item triggering the action
# additional_actions: SeActions-Instance containing actions which should be executed, too
def execute(self, is_repeat: bool, allow_item_repeat: bool, state: str, additional_actions=None):
def execute(self, is_repeat: bool, allow_item_repeat: bool, state, additional_actions=None):
actions = []
for name in self.__actions:
actions.append((self.__actions[name].get_order(), self.__actions[name]))
Expand Down
Loading

0 comments on commit 1fbe62d

Please sign in to comment.