diff options
author | Jonas Gunz <himself@jonasgunz.de> | 2023-02-07 14:32:32 +0100 |
---|---|---|
committer | Jonas Gunz <himself@jonasgunz.de> | 2023-02-07 14:32:32 +0100 |
commit | b904ef52c5c6df6e720a91675d9ca489ea59590e (patch) | |
tree | 30cc4c9a54a1d1df9d1ebb80412c808f29916c98 | |
parent | 31661017765371d5426f4d7244d33d994afb7365 (diff) | |
download | automato-b904ef52c5c6df6e720a91675d9ca489ea59590e.tar.gz |
implement loop
-rwxr-xr-x | automato/command_line.py | 26 | ||||
-rw-r--r-- | automato/trigger.py | 11 |
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) |