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:
@@ -0,0 +1,23 @@
|
||||
from styles.simple import SimpleStyle
|
||||
|
||||
|
||||
def test_simple_keeps_ringing_when_not_pressed():
|
||||
calls = []
|
||||
style = SimpleStyle(lambda on: calls.append(on))
|
||||
assert style.update(0.0, False) is True
|
||||
assert calls[-1] is True # LED solid on while ringing
|
||||
|
||||
|
||||
def test_simple_stops_on_first_press():
|
||||
calls = []
|
||||
style = SimpleStyle(lambda on: calls.append(on))
|
||||
assert style.update(0.0, True) is False # press -> stop
|
||||
|
||||
|
||||
def test_simple_led_off_on_release_after_press():
|
||||
# After a press the style stops; verify it never turns the LED off itself
|
||||
# (the runner's cleanup handles that). It only ever asserts LED on.
|
||||
calls = []
|
||||
style = SimpleStyle(lambda on: calls.append(on))
|
||||
style.update(0.0, False)
|
||||
assert calls == [True]
|
||||
Reference in New Issue
Block a user