feat: add pluggable alarm styles and migrate wecker.py

Introduce a styles/ plugin package:
- styles/base.py: AlarmStyle ABC (injected set_led, update()->bool contract)
- styles/blink.py: BlinkStyle, the existing count-the-blinks puzzle moved
  out of wecker.py's AlarmClock
- styles/simple.py: SimpleStyle, press-once-to-stop (the new default style)
- styles/__init__.py: STYLES registry + get_style() validator + LEGACY_STYLE

wecker.py now resolves the style via the registry and owns only the shared
music/button/cleanup loop; the --style CLI arg defaults to blink so existing
cron entries keep their behaviour. Unknown styles raise before hardware init.
This commit is contained in:
2026-07-31 16:19:14 +02:00
parent 7ee28d72b6
commit b3f3db6f13
9 changed files with 395 additions and 212 deletions
+18
View File
@@ -0,0 +1,18 @@
from styles.base import AlarmStyle
class SimpleStyle(AlarmStyle):
"""Press the button once to stop the alarm."""
def update(self, now, is_pressed):
# LED solid on so the button is findable in the dark.
self.set_led(True)
return not is_pressed # first press -> False -> stop
if __name__ == "__main__":
# Self-check: not pressed keeps ringing; a press stops it.
style = SimpleStyle(lambda on: None)
assert style.update(0.0, False) is True
assert style.update(0.1, True) is False
print("simple self-check ok")