Skip to content

Commit

Permalink
stateengine plugin: minor webif code fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
onkelandy committed Jul 18, 2024
1 parent 50b5652 commit f43c6f4
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 12 deletions.
33 changes: 22 additions & 11 deletions stateengine/StateEngineWebif.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
class WebInterface(StateEngineTools.SeItemChild):
# Constructor
# abitem: parent SeItem instance
def __init__(self, smarthome, abitem):
def __init__(self, abitem):
super().__init__(abitem)

if not REQUIRED_PACKAGE_IMPORTED:
Expand Down Expand Up @@ -70,6 +70,7 @@ def _check_webif_conditions(action_dict, condition_to_meet: str, conditionset: s
_condition_necessary = 1 if _condition_check != 'None' else 0
_condition_check = _condition_check if isinstance(_condition_check, list) else [_condition_check]
_condition_count = 0
_condition = False
for cond in _condition_check:
try:
_cond = re.compile(cond)
Expand Down Expand Up @@ -117,14 +118,15 @@ def _check_webif_conditions(action_dict, condition_to_meet: str, conditionset: s
cond1 = conditionset in ['', self.__active_conditionset] and state == self.__active_state
cond2 = self.__states[state]['conditionsets'].get(conditionset) is not None
cond_delta = float(_delta) < float(_mindelta)
fontcolor = "white" if cond1 and cond2 and (cond_delta or\
(not condition_met or (_repeat is False and originaltype == 'actions_stay')))\
else "#5c5646" if _delay > 0 else "darkred" if _delay < 0 \
else "#303030" if not condition_met or _issue else "black"
condition_info = condition_to_meet if condition1 is False\
else previouscondition_to_meet if condition2 is False\
else previousstate_condition_to_meet if condition3 is False\
else ""
fontcolor = "white" if cond1 and cond2 and (
cond_delta or
(not condition_met or (_repeat is False and originaltype == 'actions_stay'))) \
else "#5c5646" if _delay > 0 else "darkred" if _delay < 0 \
else "#303030" if not condition_met or _issue else "black"
condition_info = condition_to_meet if condition1 is False \
else previouscondition_to_meet if condition2 is False \
else previousstate_condition_to_meet if condition3 is False \
else ""
if _issue:
if tooltip_count > 0:
action_tooltip += '&#13;&#10;&#13;&#10;'
Expand Down Expand Up @@ -219,7 +221,10 @@ def _conditionlabel(self, state, conditionset, i):
if condition not in conditions_done:
current_clean = ", ".join(f"{k} = {v}" for k, v in current.items())
text = " Current {}".format(current_clean) if current and len(current) > 0 else " Not evaluated."
conditionlist += '<tr><td align="center" colspan="4"><table border="0" cellpadding="0" cellborder="0"><tr><td></td><td align="center">{}:{}</td><td></td></tr><tr><td width="40%"></td><td align="center" border="1" height="1"></td><td width="40%"></td></tr></table></td></tr>'.format(condition.upper(), text)
conditionlist += ('<tr><td align="center" colspan="4"><table border="0" cellpadding="0" '
'cellborder="0"><tr><td></td><td align="center">{}:{}</td><td></td></tr><tr>'
'<td width="40%"></td><td align="center" border="1" height="1"></td>'
'<td width="40%"></td></tr></table></td></tr>').format(condition.upper(), text)
conditions_done.append(condition)
conditionlist += '<tr><td align="center"><b>'
info_status = str(condition_dict.get('status') or '')
Expand Down Expand Up @@ -292,7 +297,7 @@ def _conditionlabel(self, state, conditionset, i):
and condition_dict.get('updatedbynegate') == 'True')\
else "updated by" if not updatedby_none and compare == "updatedby"\
else "not triggered by" if (not triggeredby_none and compare == "triggeredby"
and condition_dict.get('triggeredbynegate') == 'True')\
and condition_dict.get('triggeredbynegate') == 'True')\
else "triggered by" if not triggeredby_none and compare == "triggeredby"\
else "!=" if (not value_none and compare == "value"
and condition_dict.get('negate') == 'True')\
Expand Down Expand Up @@ -433,6 +438,12 @@ def drawgraph(self, filename):
actions_enter_or_stay = self.__states[state].get('actions_enter_or_stay') or []
actions_stay = self.__states[state].get('actions_stay') or []
actions_leave = self.__states[state].get('actions_leave') or []
action_tooltip_count_enter = 0
action_tooltip_count_stay = 0
action_tooltip_count_leave = 0
action_tooltip_enter = ""
action_tooltip_stay = ""
action_tooltip_leave = ""
for j, conditionset in enumerate(self.__states[state]['conditionsets']):

if len(actions_enter) > 0 or len(actions_enter_or_stay) > 0:
Expand Down
2 changes: 1 addition & 1 deletion stateengine/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ def get_items(self):
def get_graph(self, abitem, graphtype='link'):
if isinstance(abitem, str):
abitem = self._items[abitem]
webif = StateEngineWebif.WebInterface(self.__sh, abitem)
webif = StateEngineWebif.WebInterface(abitem)
try:
os.makedirs(self.path_join(self.get_plugin_dir(), 'webif/static/img/visualisations/'))
except OSError:
Expand Down

0 comments on commit f43c6f4

Please sign in to comment.