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.base import AlarmStyle as AlarmStyle
|
||||
from styles.blink import BlinkStyle
|
||||
from styles.simple import SimpleStyle
|
||||
|
||||
# Registry of available alarm styles. Add a line here when you add a style.
|
||||
STYLES = {
|
||||
"blink": BlinkStyle,
|
||||
"simple": SimpleStyle,
|
||||
}
|
||||
|
||||
# Fallback style for legacy cron entries that predate --style, so an upgrade
|
||||
# never silently changes an existing alarm's behaviour.
|
||||
LEGACY_STYLE = "blink"
|
||||
|
||||
|
||||
def get_style(name: str):
|
||||
"""Return the style class for ``name`` or raise ValueError."""
|
||||
try:
|
||||
return STYLES[name]
|
||||
except KeyError:
|
||||
raise ValueError(
|
||||
f"Unknown alarm style: {name!r}. Known: {sorted(STYLES)}"
|
||||
)
|
||||
Reference in New Issue
Block a user