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.
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
import shlex
|
||||
import uuid
|
||||
from crontab import CronTab, CronSlices
|
||||
|
||||
from styles import LEGACY_STYLE
|
||||
|
||||
|
||||
class CrontabManager:
|
||||
COMMENT_PREFIX = "wecker-alarm:"
|
||||
@@ -28,6 +31,7 @@ class CrontabManager:
|
||||
"cron_expression": str(job.slices),
|
||||
"command": job.command,
|
||||
"is_enabled": job.is_enabled(),
|
||||
"style": _parse_style(job.command),
|
||||
}
|
||||
)
|
||||
return alarms
|
||||
@@ -64,3 +68,21 @@ class CrontabManager:
|
||||
comment = f"{self.COMMENT_PREFIX}{alarm_id}"
|
||||
cron.remove_all(comment=comment)
|
||||
cron.write()
|
||||
|
||||
|
||||
def _parse_style(command: str) -> str:
|
||||
"""Extract the --style value from a cron command.
|
||||
|
||||
Returns LEGACY_STYLE ('blink') for entries that predate --style, so an
|
||||
upgrade never silently changes an existing alarm's behaviour.
|
||||
"""
|
||||
try:
|
||||
tokens = shlex.split(command)
|
||||
except ValueError:
|
||||
return LEGACY_STYLE
|
||||
for i, tok in enumerate(tokens):
|
||||
if tok == "--style" and i + 1 < len(tokens):
|
||||
return tokens[i + 1]
|
||||
if tok.startswith("--style="):
|
||||
return tok.split("=", 1)[1]
|
||||
return LEGACY_STYLE
|
||||
|
||||
Reference in New Issue
Block a user