diff options
author | Elena ``of Valhalla'' Grandi <valhalla@trueelena.org> | 2025-03-13 20:31:49 +0100 |
---|---|---|
committer | Elena ``of Valhalla'' Grandi <valhalla@trueelena.org> | 2025-03-13 20:31:49 +0100 |
commit | d268db641278659e1bc85bb11e373e4eab60ec17 (patch) | |
tree | f147bf74c6ced68a1954e7d81de3bab85774223e | |
parent | 9fe33abafe1c3d3264d78bf485a0ceb17e4aacd4 (diff) |
Add a mode that monitors the batteries from homemon
-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): |