Refactor AlarmClock to remove relay functionality and add Relay class for GPIO control
This commit is contained in:
@@ -17,7 +17,6 @@ class AlarmClock:
|
||||
wakeup_actions: list[WakeUpAction] = []
|
||||
led_gpio: GPIO
|
||||
button_gpio: GPIO
|
||||
relay_gpio: GPIO
|
||||
last_known_button_state: bool = False
|
||||
lcd: JHD1802
|
||||
last_button_press_time: float = 0.0
|
||||
@@ -36,7 +35,6 @@ class AlarmClock:
|
||||
def __init__(self, pins: dict = {}):
|
||||
self.led_gpio = GPIO(pins.get("led", 5), GPIO.OUT)
|
||||
self.button_gpio = GPIO(pins.get("button", 6), GPIO.IN)
|
||||
self.relay_gpio = GPIO(pins.get("relay", 16), GPIO.OUT)
|
||||
self.lcd = JHD1802()
|
||||
self.wakeup_actions = []
|
||||
self.add_wakeup_action(0, lambda: self.trigger_alarm()) # Activate alarm state
|
||||
@@ -121,10 +119,6 @@ class AlarmClock:
|
||||
while True:
|
||||
self.loop()
|
||||
|
||||
def set_relay_state(self, state: bool):
|
||||
"""Set the relay GPIO state."""
|
||||
self.relay_gpio.write(1 if state else 0)
|
||||
|
||||
def loop(self):
|
||||
"""Main loop iteration - handles display and button input."""
|
||||
current_button_state = not self.button_gpio.read()
|
||||
@@ -185,9 +179,7 @@ class AlarmClock:
|
||||
# Dismiss active alarm
|
||||
self.dismiss_alarm()
|
||||
else:
|
||||
# Normal mode: toggle relay
|
||||
self.set_relay_state(not self.relay_gpio.read())
|
||||
set_shelly_plug_state(SHELLY_DEVICE_ID, self.relay_gpio.read() == 0)
|
||||
print("pressed in normal mode - no active alarm to dismiss")
|
||||
elif self.config_mode == "set_hour":
|
||||
# Increment hour
|
||||
self.alarm_time = self.alarm_time.replace(hour=(self.alarm_time.hour + 1) % 24)
|
||||
|
||||
Reference in New Issue
Block a user