Add callbacks support for all media actions
- Add CallbackConfig model for callback scripts - Add callbacks section to config for optional command execution - Add turn_on/turn_off/toggle endpoints (callback-only) - Add callbacks for all media actions (play, pause, stop, next, previous, volume, mute, seek) - Update README with callbacks documentation Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -10,6 +10,15 @@ from pydantic import BaseModel, Field
|
||||
from pydantic_settings import BaseSettings, SettingsConfigDict
|
||||
|
||||
|
||||
class CallbackConfig(BaseModel):
|
||||
"""Configuration for a callback script (no label/description needed)."""
|
||||
|
||||
command: str = Field(..., description="Command or script to execute")
|
||||
timeout: int = Field(default=30, description="Execution timeout in seconds", ge=1, le=300)
|
||||
working_dir: Optional[str] = Field(default=None, description="Working directory")
|
||||
shell: bool = Field(default=True, description="Run command in shell")
|
||||
|
||||
|
||||
class ScriptConfig(BaseModel):
|
||||
"""Configuration for a custom script."""
|
||||
|
||||
@@ -47,6 +56,12 @@ class Settings(BaseSettings):
|
||||
default=1.0, description="Media status poll interval in seconds"
|
||||
)
|
||||
|
||||
# Audio device settings
|
||||
audio_device: Optional[str] = Field(
|
||||
default=None,
|
||||
description="Audio device name to control (None = default device). Use /api/audio/devices to list available devices.",
|
||||
)
|
||||
|
||||
# Logging
|
||||
log_level: str = Field(default="INFO", description="Logging level")
|
||||
|
||||
@@ -56,6 +71,12 @@ class Settings(BaseSettings):
|
||||
description="Custom scripts that can be executed via API",
|
||||
)
|
||||
|
||||
# Callback scripts (executed by integration events, not shown in UI)
|
||||
callbacks: dict[str, CallbackConfig] = Field(
|
||||
default_factory=dict,
|
||||
description="Callback scripts executed by integration events (on_turn_on, on_turn_off, on_toggle)",
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def load_from_yaml(cls, path: Optional[Path] = None) -> "Settings":
|
||||
"""Load settings from a YAML configuration file."""
|
||||
@@ -110,6 +131,9 @@ def generate_default_config(path: Optional[Path] = None) -> Path:
|
||||
"api_token": secrets.token_urlsafe(32),
|
||||
"poll_interval": 1.0,
|
||||
"log_level": "INFO",
|
||||
# Audio device to control (use GET /api/audio/devices to list available devices)
|
||||
# Set to null or remove to use default device
|
||||
# "audio_device": "Speakers (Realtek",
|
||||
"scripts": {
|
||||
"example_script": {
|
||||
"command": "echo Hello from Media Server!",
|
||||
|
||||
Reference in New Issue
Block a user