diff options
| -rw-r--r-- | gd_clock.py | 27 | 
1 files changed, 26 insertions, 1 deletions
diff --git a/gd_clock.py b/gd_clock.py index 438813f..c3a91dc 100644 --- a/gd_clock.py +++ b/gd_clock.py @@ -59,9 +59,26 @@ class Rainbow:  rainbow = Rainbow() +class StatusRing: +    def start(self, clock): +        pixels.fill((0, 0, 0)) +        clock.brightness = 0.1 +        pixels.brightness = clock.brightness + +    def loop(self, clock): +        if any(clock.batteries.values()): +            pixels[0] = (255, 0, 0) +        else: +            pixels[0] = (0, 0, 32) + + +status_ring = StatusRing() + +  class GD_Clock:      brightness = 0.1      current_mode = rainbow +    batteries = {}      def connected(self, client, userdata, flags, rc):          print("Connected to MQTT") @@ -88,6 +105,9 @@ class GD_Clock:              elif value == "rainbow":                  self.current_mode = rainbow                  self.current_mode.start(self) +            elif value == "status": +                self.current_mode = status_ring +                self.current_mode.start(self)          elif cmd == "brightness":              if value == "+":                  self.brightness = min(1.0, self.brightness + 0.1) @@ -104,7 +124,12 @@ class GD_Clock:      def parse_sensor(self, topic, message):          print(f"New sensor message on topic {topic}: {message}") -        pass +        hm, room, sensor = topic.split("/") +        if sensor == "batt_low": +            try: +                self.batteries[room] = bool(int(message)) +            except ValueError: +                pass      def message(self, client, topic, message):          if topic.startswith(CMD_FEED):  | 
