Führt ein pluggable Style-System für den Wecker ein: Das hardcoded Blink-Puzzle wird aus wecker.py in ein styles/-Paket ausgelagert (AlarmStyle-ABC, Registry, zwei Implementierungen), der Style wird per --style-Flag über Cron-Kommando, GraphQL-API und CLI transportiert.
Bestehende Cron-Einträge ohne --style laufen weiter mit blink (Legacy-Fallback), das Alarmverhalten ändert sich für Bestandsalarms nicht.
Review
Externes Review (Subagent, GLM-5.3): ruff ✓, pytest ✓ (62 passed). Ein Finding (setAlarm-Update ohne style setzt auf simple zurück) wurde geprüft und ist als bewusst akzeptiertes Verhalten abgenickt – Default für neue Alarms, Updates überführen auf den Default, dokumentiert im README.
Deploy-Hinweis
Nach Merge: git pull auf dem Pi + systemctl --user restart wecker-api.service. Abnahme auf echter Hardware empfohlen (je ein simple- und blink-Alarm klingeln lassen, da Tests pygame mocken).
## Zusammenfassung
Führt ein pluggable Style-System für den Wecker ein: Das hardcoded Blink-Puzzle wird aus `wecker.py` in ein `styles/`-Paket ausgelagert (`AlarmStyle`-ABC, Registry, zwei Implementierungen), der Style wird per `--style`-Flag über Cron-Kommando, GraphQL-API und CLI transportiert.
**Neu: `styles/`-Paket**
- `base.py`: `AlarmStyle`-ABC (`__init__(set_led, **kwargs)`, `start()`, `update(now, is_pressed) -> bool`)
- `blink.py`: unverändertes Puzzle als erste Implementierung (Musik-Loop)
- `simple.py`: neuer Stil – LED dauerhaft an + synthetisierter Beep (stdlib, kein MP3), ein Tastendruck stoppt
- `__init__.py`: Registry `STYLES`, `get_style()`, `LEGACY_STYLE = "blink"`
**Runner (`wecker.py`)** – Style-Validierung vor Hardware-Init, `--style` mit Default `blink`
**API** – `style`-Feld auf `Alarm`, `setAlarm(style=…)` / `startRinging(style=…)` mit Registry-Validierung, `shlex.quote` beim Cron-Eintrag
**Tests** – 5 neue Testdateien + zentrales `conftest.py` (GPIO/pygame-Stubbing), 62 Tests grün
**Doku** – README (Styles-Tabelle, Plugin-Contract, GraphQL-Beispiele) + `docs/alarm-styles-plan.md`
## Rückwärtskompatibilität
Bestehende Cron-Einträge ohne `--style` laufen weiter mit `blink` (Legacy-Fallback), das Alarmverhalten ändert sich für Bestandsalarms nicht.
## Review
Externes Review (Subagent, GLM-5.3): ruff ✓, pytest ✓ (62 passed). Ein Finding (setAlarm-Update ohne `style` setzt auf `simple` zurück) wurde geprüft und ist als **bewusst akzeptiertes Verhalten** abgenickt – Default für neue Alarms, Updates überführen auf den Default, dokumentiert im README.
## Deploy-Hinweis
Nach Merge: `git pull` auf dem Pi + `systemctl --user restart wecker-api.service`. Abnahme auf echter Hardware empfohlen (je ein `simple`- und `blink`-Alarm klingeln lassen, da Tests pygame mocken).
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.
- crontab_manager.get_alarms now parses --style from the cron command
(defaults to 'blink' for legacy entries without --style)
- GraphQL Alarm type gains a 'style' field
- setAlarm accepts a 'style' arg (default 'simple') and validates it
against the styles registry; unknown styles raise a GraphQL error
- _default_command embeds --style <name> into the cron command
- startRinging accepts 'style' (default 'simple') and passes --style to
the spawned wecker.py
The crontab remains the single source of truth; the style simply rides
in the cron command alongside --music-file.
Add an Alarm Styles section (simple vs blink), show --style in manual usage,
and update the GraphQL examples (setAlarm/getAlarms/startRinging) to include
the style field/argument. Note backward compat for legacy cron entries.
Nothing imports AlarmStyle via the styles namespace (blink/simple both
import from styles.base directly), so the redundant-alias re-export was
dead weight that only existed to silence ruff F401.
Move audio ownership out of the shared runner and into each style via an
injected Sound capability (play_music(path) / play_beep()). The runner now
only owns button sampling and cleanup; the style kicks off its own tone in
start() and drives the LED.
- simple: a repeating square-wave beep (ordinary alarm-clock tone), no music
file required. The beep is synthesised in memory as signed-16-bit stereo
PCM (stdlib array+math) and played via pygame.mixer.Sound — no shipped
audio asset, no new dependency.
- blink: unchanged behaviour — music on an endless loop from --music-file /
MUSIC_FILE / the default track, via pygame.mixer.music.
- AlarmStyle contract gains sound + music_file in __init__ and a start()
lifecycle hook; AlarmSound Protocol documents the audio seam for future
styles that handle their own tone.
- setup() no longer loads music (that is the style's job now).
README updated: per-style ringing tone, the --music-file note (blink only),
and the extended plugin contract.
Drop the injected AlarmSound Protocol and the wecker.Sound class. Each style
now owns its tone by using pygame directly; the runner owns only the audio
engine lifecycle (mixer init/quit), button sampling, and cleanup. This is the
seam for future styles that handle their own tone — a 'talk' style would just
import pygame and play speech, with no shared interface to extend.
- styles/base.py: AlarmStyle.__init__(set_led, music_file) + start() + update()
- styles/blink.py: start() loads+plays music via pygame.mixer.music
- styles/simple.py: owns its beep — synthesises a square-wave buffer in
module (stdlib array+math) and plays it via pygame.mixer.Sound
- wecker.py: setup() brings up the mixer only; run_alarm constructs the style
and guards start() with a clean log+exit on failure
Tests: a shared tests/conftest.py stubs RPi.GPIO/pygame in sys.modules before
any SUT import (order-independent, removes duplicated inline mocking); the
wecker mock_pygame fixture patches one fresh pygame mock into wecker + both
style modules so assertions see the same calls.
README: tone-ownership and plugin-contract updated.
The base AlarmStyle contract carried music_file, forcing SimpleStyle to
accept a parameter it never uses. Move style-specific config to the
subclass: the base __init__ takes only set_led (**kwargs swallows the rest);
each style declares the keyword args it actually uses (BlinkStyle: music_file;
SimpleStyle: none). The runner passes config as keyword args and each style
keeps only what it needs, so the base contract never grows as styles are
added — a future 'talk' style adds talk_file to its own signature, not to the
base. README plugin contract updated.
You are not authorized to merge this pull request.
This pull request can be merged automatically.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Zusammenfassung
Führt ein pluggable Style-System für den Wecker ein: Das hardcoded Blink-Puzzle wird aus
wecker.pyin einstyles/-Paket ausgelagert (AlarmStyle-ABC, Registry, zwei Implementierungen), der Style wird per--style-Flag über Cron-Kommando, GraphQL-API und CLI transportiert.Neu:
styles/-Paketbase.py:AlarmStyle-ABC (__init__(set_led, **kwargs),start(),update(now, is_pressed) -> bool)blink.py: unverändertes Puzzle als erste Implementierung (Musik-Loop)simple.py: neuer Stil – LED dauerhaft an + synthetisierter Beep (stdlib, kein MP3), ein Tastendruck stoppt__init__.py: RegistrySTYLES,get_style(),LEGACY_STYLE = "blink"Runner (
wecker.py) – Style-Validierung vor Hardware-Init,--stylemit DefaultblinkAPI –
style-Feld aufAlarm,setAlarm(style=…)/startRinging(style=…)mit Registry-Validierung,shlex.quotebeim Cron-EintragTests – 5 neue Testdateien + zentrales
conftest.py(GPIO/pygame-Stubbing), 62 Tests grünDoku – README (Styles-Tabelle, Plugin-Contract, GraphQL-Beispiele) +
docs/alarm-styles-plan.mdRückwärtskompatibilität
Bestehende Cron-Einträge ohne
--stylelaufen weiter mitblink(Legacy-Fallback), das Alarmverhalten ändert sich für Bestandsalarms nicht.Review
Externes Review (Subagent, GLM-5.3): ruff ✓, pytest ✓ (62 passed). Ein Finding (setAlarm-Update ohne
stylesetzt aufsimplezurück) wurde geprüft und ist als bewusst akzeptiertes Verhalten abgenickt – Default für neue Alarms, Updates überführen auf den Default, dokumentiert im README.Deploy-Hinweis
Nach Merge:
git pullauf dem Pi +systemctl --user restart wecker-api.service. Abnahme auf echter Hardware empfohlen (je einsimple- undblink-Alarm klingeln lassen, da Tests pygame mocken).View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.