Commit Graph
25 Commits
Author SHA1 Message Date
gurix 3a7b6ac7a3 refactor: styles own their ringing tone directly (Pattern C)
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.
2026-08-02 21:50:00 +02:00
gurix 92eba762ce feat: styles own their ringing tone (simple beeps, blink plays music)
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.
2026-08-02 16:29:40 +02:00
gurix 88a57dab6e refactor: drop unused AlarmStyle re-export from styles package
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.
2026-08-02 10:01:46 +02:00
gurix 670119f93e docs: document alarm styles and per-alarm style selection
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.
2026-07-31 16:20:50 +02:00
gurix c50f296232 feat: pass alarm style through crontab manager and GraphQL API
- 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.
2026-07-31 16:20:16 +02:00
gurix b3f3db6f13 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.
2026-07-31 16:19:14 +02:00
gurix 7ee28d72b6 docs: plan for pluggable alarm styles 2026-07-31 13:41:17 +02:00
gurix e118dbc357 refactor: share alarm loading between get_alarms and get_alarm 2026-06-22 10:37:52 +02:00
gurix 3fae274aa0 refactor: centralize alarm dict-to-GraphQL mapping 2026-06-22 10:30:01 +02:00
gurix a67f57c37e refactor: remove command field from GraphQL Alarm type
command is generated internally and has no informational value to API
consumers, so stop exposing it on getAlarms/getAlarm/setAlarm.
2026-06-22 10:04:48 +02:00
gurix b2bb5bdaf9 docs: document API security considerations and rate-limiting recommendation 2026-06-18 17:22:55 +02:00
gurix 8a46ff8487 refactor: locate project root by pyproject.toml marker 2026-06-18 17:20:51 +02:00
gurix 77f215be84 refactor: explicitly handle missing API key header 2026-06-18 17:20:01 +02:00
gurix 0472de5a5d fix: add SIGKILL fallback when SIGTERM does not stop the alarm 2026-06-18 17:17:56 +02:00
gurix 4d9f08f21f refactor: make blink_led non-blocking in the state machine 2026-06-18 17:09:10 +02:00
gurix dfc9f0cd94 feat: make alarm music file configurable via env var and CLI arg 2026-06-18 17:01:26 +02:00
gurix 434c49b609 refactor: move GPIO and pygame initialization into setup() 2026-06-18 16:58:57 +02:00
gurix 0621ab6190 chore: replace weak example API key with strong generated key 2026-06-18 16:53:15 +02:00
gurix 748a3be4b8 fix: validate cron expression before writing to crontab 2026-06-18 16:47:56 +02:00
gurix 1a8e4e2186 fix: verify /proc/PID/cmdline in isRinging to prevent PID reuse false positives 2026-06-18 16:45:52 +02:00
gurix b62a1d10c1 fix: rotate wecker.log to prevent unbounded growth 2026-06-18 16:41:30 +02:00
gurix d349478e07 fix: start wecker without shell=True 2026-06-18 16:38:58 +02:00
gurix 7e8e915024 fix: use fcntl file lock to prevent PID file race condition 2026-06-18 15:27:21 +02:00
gurix 058de8089c fix: use constant-time comparison for API key 2026-06-18 15:23:57 +02:00
gurix 124a6a4916 fix: remove custom command from setAlarm to prevent command injection 2026-06-18 15:23:14 +02:00