Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stateengine Plugin: Additional updates for version 2.0.0 #808

Merged
merged 16 commits into from
Sep 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
659 changes: 404 additions & 255 deletions stateengine/StateEngineAction.py

Large diffs are not rendered by default.

300 changes: 211 additions & 89 deletions stateengine/StateEngineActions.py

Large diffs are not rendered by default.

261 changes: 170 additions & 91 deletions stateengine/StateEngineCondition.py

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions stateengine/StateEngineConditionSet.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def update(self, item, grandparent_item):
self.__conditions[name] = StateEngineCondition.SeCondition(self._abitem, name)
issue = self.__conditions[name].set(func, item.conf[attribute])
self.__conditions.move_to_end(name, last=True)
if issue:
if issue not in [[], None, [None]]:
self.__unused_attributes.update({name: {'attribute': attribute, 'issue': issue}})
elif name not in self.__used_attributes.keys():
self.__used_attributes.update({name: {'attribute': attribute}})
Expand All @@ -113,7 +113,7 @@ def update(self, item, grandparent_item):
if name == "":
continue
cond1 = name not in self.__used_attributes.keys()
cond2 = func == "se_item" or func == "se_eval" or func == "se_status"
cond2 = func == "se_item" or func == "se_eval" or func == "se_status_eval" or func == "se_status"
cond3 = name not in self.__unused_attributes.keys()
if cond1:
if cond2 and cond3:
Expand All @@ -125,7 +125,7 @@ def update(self, item, grandparent_item):
self.__conditions[name] = StateEngineCondition.SeCondition(self._abitem, name)
try:
issue = self.__conditions[name].set(func, grandparent_item.conf[attribute])
if issue:
if issue not in [[], None, [None]]:
self.__unused_attributes.update({name: {'attribute': attribute, 'issue': issue}})
except ValueError as ex:
self.__unused_attributes.update({name: {'attribute': attribute, 'issue': ex}})
Expand Down
283 changes: 179 additions & 104 deletions stateengine/StateEngineItem.py

Large diffs are not rendered by default.

41 changes: 7 additions & 34 deletions stateengine/StateEngineLogger.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,32 +57,17 @@ def log_maxage(self, value):
logger.error("The maximum age of the log files has to be an int number.")

@property
def using_default_log_level(self):
return self.__using_default_log_level
def log_level_as_num(self):
return self.__log_level_as_num

@using_default_log_level.setter
def using_default_log_level(self, value):
self.__using_default_log_level = value
@log_level_as_num.setter
def log_level_as_num(self, value):
self.__log_level_as_num = value

@property
def name(self):
return self.__name

# Set global log level
# loglevel: current loglevel
@property
def log_level(self):
return self.__log_level.get()

@log_level.setter
def log_level(self, value):
try:
self.__log_level = int(value)
except ValueError:
self.__log_level = 0
logger = StateEngineDefaults.logger
logger.error("Loglevel has to be an int number!")

@property
def log_directory(self):
return SeLogger.__log_directory
Expand Down Expand Up @@ -147,19 +132,13 @@ def __init__(self, item):
self.__name = 'stateengine.{}'.format(item.property.path)
self.__section = item.property.path.replace(".", "_").replace("/", "")
self.__indentlevel = 0
self.__default_log_level = None
self.__startup_log_level = None
self.__log_level = None
self.__using_default_log_level = False
self.__log_level_as_num = 0
self.__logmaxage = None
self.__date = None
self.__logerror = False
self.__filename = ""
self.update_logfile()

# get current log level of abitem
def get_loglevel(self):
return self.log_level.get()

# Update name logfile if required
def update_logfile(self):
Expand All @@ -186,13 +165,7 @@ def decrease_indent(self, by=1):
# text: text to log
def log(self, level, text, *args):
# Section given: Check level
_log_level = self.get_loglevel()
if _log_level <= -1:
self.using_default_log_level = True
_log_level = SeLogger.default_log_level.get()
else:
self.using_default_log_level = False
if level <= _log_level:
if level <= self.__log_level_as_num:
indent = "\t" * self.__indentlevel
if args:
text = text.format(*args)
Expand Down
24 changes: 21 additions & 3 deletions stateengine/StateEngineState.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,14 +362,22 @@ def update_unused(used_attributes, type, name):
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)
return
for itm, dct in action_status.items():
if itm not in self.__action_status:
self.__action_status.update({itm: dct})

for (itm, dct) in action_status.items():
issues = dct.get('issue')
if issues:
if isinstance(issues, list):
self.__action_status[itm]['issue'].extend(
[issue for issue in issues if issue not in self.__action_status[itm]['issue']])
origin_list = self.__action_status[itm].get('issueorigin', [])
new_list = origin_list.copy()
for i, listitem in enumerate(origin_list):
Expand All @@ -392,7 +400,8 @@ def update_action_status(action_status, actiontype):
filtered_dict[key].update(nested_dict)
#self._log_develop("Add {} to used {}", key, filtered_dict)
self.__used_attributes = copy(filtered_dict)
filtered_dict = {key: value for key, value in self.__action_status.items() if value.get('issue') not in [[], None]}
filtered_dict = {key: value for key, value in self.__action_status.items()
if value.get('issue') not in [[], [None], None]}
self.__action_status = filtered_dict
#self._log_develop("Updated action status: {}, updated used {}", self.__action_status, self.__used_attributes)

Expand Down Expand Up @@ -506,7 +515,7 @@ def update_action_status(action_status, actiontype):
for attribute in parent_item.conf:
func, name = StateEngineTools.partition_strip(attribute, "_")
cond1 = name and name not in self.__used_attributes
cond2 = func == "se_item" or func == "se_eval" or func == "se_status"
cond2 = func == "se_item" or func == "se_eval" or func == "se_status_eval" or func == "se_status"
cond3 = name not in self.__unused_attributes.keys()

if cond1 and cond2 and cond3:
Expand All @@ -523,6 +532,7 @@ def update_action_status(action_status, actiontype):
_, _action_status = self.__actions_enter.update(attribute, child_item.conf[attribute])
if _action_status:
update_action_status(_action_status, 'enter')
self._abitem.update_action_status(self.__action_status)
update_unused(_used_attributes, 'action', child_name)
elif child_name == "on_stay":
_actioncount += 1
Expand All @@ -531,6 +541,7 @@ def update_action_status(action_status, actiontype):
_, _action_status = self.__actions_stay.update(attribute, child_item.conf[attribute])
if _action_status:
update_action_status(_action_status, 'stay')
self._abitem.update_action_status(self.__action_status)
update_unused(_used_attributes, 'action', child_name)
elif child_name == "on_enter_or_stay":
_actioncount += 1
Expand All @@ -539,6 +550,7 @@ def update_action_status(action_status, actiontype):
_, _action_status = self.__actions_enter_or_stay.update(attribute, child_item.conf[attribute])
if _action_status:
update_action_status(_action_status, 'enter_or_stay')
self._abitem.update_action_status(self.__action_status)
update_unused(_used_attributes, 'action', child_name)
elif child_name == "on_leave":
_actioncount += 1
Expand All @@ -547,6 +559,7 @@ def update_action_status(action_status, actiontype):
_, _action_status = self.__actions_leave.update(attribute, child_item.conf[attribute])
if _action_status:
update_action_status(_action_status, 'leave')
self._abitem.update_action_status(self.__action_status)
update_unused(_used_attributes, 'action', child_name)
except ValueError as ex:
raise ValueError("Condition {0} check for actions error: {1}".format(child_name, ex))
Expand All @@ -558,6 +571,7 @@ def update_action_status(action_status, actiontype):
_action_status = _result[1]
if _action_status:
update_action_status(_action_status, 'enter_or_stay')
self._abitem.update_action_status(self.__action_status)

_total_actioncount = _enter_actioncount + _stay_actioncount + _enter_stay_actioncount + _leave_actioncount

Expand All @@ -568,15 +582,19 @@ def update_action_status(action_status, actiontype):
_action_status = self.__actions_enter.complete(item_state, self.__conditions.evals_items)
if _action_status:
update_action_status(_action_status, 'enter')
self._abitem.update_action_status(self.__action_status)
_action_status = self.__actions_stay.complete(item_state, self.__conditions.evals_items)
if _action_status:
update_action_status(_action_status, 'stay')
self._abitem.update_action_status(self.__action_status)
_action_status = self.__actions_enter_or_stay.complete(item_state, self.__conditions.evals_items)
if _action_status:
update_action_status(_action_status, 'enter_or_stay')
self._abitem.update_action_status(self.__action_status)
_action_status = self.__actions_leave.complete(item_state, self.__conditions.evals_items)
if _action_status:
update_action_status(_action_status, 'leave')
self._abitem.update_action_status(self.__action_status)
self._abitem.update_action_status(self.__action_status)
self._abitem.update_attributes(self.__unused_attributes, self.__used_attributes)
_summary = "{} on_enter, {} on_stay , {} on_enter_or_stay, {} on_leave"
Expand Down
Loading