aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xautomato/command_line.py26
-rw-r--r--automato/trigger.py11
2 files changed, 32 insertions, 5 deletions
diff --git a/automato/command_line.py b/automato/command_line.py
index ef09078..b47bfac 100755
--- a/automato/command_line.py
+++ b/automato/command_line.py
@@ -41,11 +41,29 @@ def main():
# TODO should we do that in Endpoint.__init__()?
+ # TODO We also need better connectivity handling, eg. auto reconnect
for k in endpoints:
endpoints[k].connectTransport()
- for act_key in action_config:
- actions[act_key].execute()
+ looptime = 5 # TODO
+ while True:
+ starttime = time.time()
- for act_key in action_config:
- actions[act_key].execute()
+ for act_key in action_config:
+ actions[act_key].execute()
+
+ elapsed = time.time() - starttime
+ wait = max(0, looptime - elapsed)
+ logging.debug(f'Loop took {elapsed:.2f}s. Waiting {wait:.2f}s before next run.')
+ if wait <= 0.1 * looptime:
+ logging.warn(f'System seems overloaded. Actions did not run in specified looptime {looptime}s.')
+
+ time.sleep(max(0, looptime - elapsed))
+
+
+
+ #for act_key in action_config:
+ # actions[act_key].execute()
+
+ #for act_key in action_config:
+ # actions[act_key].execute()
diff --git a/automato/trigger.py b/automato/trigger.py
index 5608f17..eda40d5 100644
--- a/automato/trigger.py
+++ b/automato/trigger.py
@@ -120,5 +120,14 @@ class ConditionalTrigger(Trigger):
return self._endpoints[endpoint].getState(key)
def _evaluate(self, action: str) -> bool:
- return all(self._parser.parse_string(str(s)) for s in self._instances[action]['args']['when'])
+ logging.debug(f"{self._instances[action]['args']['when']}")
+
+ results = []
+
+ for s in self._instances[action]['args']['when']:
+ r = self._parser.parse_string(str(s))[0]
+ logging.debug(f'Condition "{s}" evaluated to "{r}"')
+ results.append(r)
+
+ return all(results)