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
This commit is contained in:
Markus Graf
2026-05-19 15:15:05 +02:00
parent 29aff04e33
commit 558c4ff5b6
6 changed files with 98 additions and 5 deletions
+2 -2
View File
@@ -6,6 +6,8 @@ import random
import sys
import os
from common import PID_FILE
# Configure logging
logging.basicConfig(
level=logging.INFO,
@@ -13,8 +15,6 @@ logging.basicConfig(
handlers=[logging.FileHandler("wecker.log"), logging.StreamHandler()],
)
PID_FILE = "wecker.pid"
def ensure_single_instance():
"""Ensures that only one instance of the script is running."""