split code up into modules and add pubsub and timers

This commit is contained in:
Travis Shears 2023-08-10 08:11:39 +02:00
parent 05c470197f
commit 001f99db7c
Signed by: travisshears
GPG key ID: D4C2E4DFAB8BABF8
7 changed files with 228 additions and 137 deletions

View file

@ -0,0 +1,10 @@
class Timer:
def __init__(self, pubsub, timer_length):
self.timer_length = timer_length
self.last_tick = 0
self.pubsub = pubsub
self.topic = f"tick {self.timer_length}"
def tick(self, now):
if (now - self.last_tick) > self.timer_length:
self.last_tick = now
self.pubsub.publish(self.topic, {})