Commit Graph
16 Commits
Author SHA1 Message Date
gurix 000b204215 refactor: keep style-specific config off the base class via **kwargs
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.
2026-08-02 22:09:46 +02:00
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 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
Markus Graf 0f70e832bf fix: set SDL_AUDIODRIVER=pulse and XDG_RUNTIME_DIR for cron/API audio 2026-06-26 07:42:42 +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 b62a1d10c1 fix: rotate wecker.log to prevent unbounded growth 2026-06-18 16:41:30 +02:00
gurix 7e8e915024 fix: use fcntl file lock to prevent PID file race condition 2026-06-18 15:27:21 +02:00
Markus Graf 558c4ff5b6 Add isRinging query to check alarm state via API
Features:
- New GraphQL query 'isRinging' returns true/false if wecker is active
- Checks the wecker process via PID file (PID_FILE in common.py)

DRY refactoring:
- Extract PID_FILE into shared common.py module
- Both wecker.py and api/schema.py import from common
- DRY enforcement tests verify identity (is) not just equality

Tests:
- test_is_ringing_returns_false_when_not_running
- test_is_ringing_returns_true_when_running
- test_pid_file_defined_once_across_modules (DRY enforcement)
- test_pid_file_same_shared_constant_in_api (DRY enforcement)
- Cleaned up unused imports in test_single_instance.py

Docs:
- Updated README.md with isRinging query documentation
2026-05-19 15:15:05 +02:00
Markus Graf 6c088661fd Implement single instance enforcement using PID file 2026-05-19 14:39:51 +02:00
Markus Graf ff79224560 feat: make command parameter optional in set_alarm mutation 2026-05-11 15:05:29 +02:00
Markus Graf 5b5b845e41 Fix premature evaluation after blinking completes
When transitioning from STATE_BLINKING to STATE_WAIT_FOR_INPUT, the script used a stale timestamp `now` from before the blocking `blink_led` function. This caused the puzzle to immediately evaluate as failed. Updated to use `time.time()` after blinking finishes to ensure the user gets the full 3 seconds to enter their answer.
2026-05-10 07:41:00 +02:00
Markus Graf a7c4febd67 test: add tests and refactor wecker.py state machine for testability 2026-05-09 22:31:28 +02:00
Markus Graf f44e0c5fdb Initial commit: Add smart arcade button alarm clock 2026-04-30 13:32:32 +02:00