From e58b1b21ed00f991b2152ff4744edf41d0538150 Mon Sep 17 00:00:00 2001 From: Dessa Simpson Date: Thu, 26 May 2022 05:01:51 +0000 Subject: [PATCH] Fire process_sequence immediately if no further options --- wallmote.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/wallmote.py b/wallmote.py index d0084a2..b7d4536 100644 --- a/wallmote.py +++ b/wallmote.py @@ -35,6 +35,8 @@ class WallmotePlumbing(hass.Hass): def shortpress(self, key): self.currentSequence.append(key); self.reset_tot(); + # Don't wait for tot to expire if we've already hit the end of a branch + if (self.check_action(self.currentSequence.copy())): self.process_sequence(); def reset_tot(self): if (hasattr(self,"tot")): self.tot.cancel(); @@ -48,6 +50,17 @@ class WallmotePlumbing(hass.Hass): self.log(sequence); self.run_action(sequence); + def check_action(self, sequence, tree=tree): + if (len(sequence) > 0): + # Deeper into the rabbit hole + category = sequence.pop(0); + if (category in tree): return self.check_action(sequence,tree[category]); + else: return false; + else: + # We've the end of the sequence thus far, check if this is the end of a branch + # If any of {1..4} exist as keys in tree there's more options + return not any(i in tree for i in range(1,4)); + def run_action(self, sequence, tree=tree): if (len(sequence) > 0): # Deeper into the rabbit hole