feat: add typed qBittorrent scheduled polling
This commit is contained in:
@@ -9,6 +9,8 @@ from __future__ import annotations
|
||||
|
||||
from typing import TYPE_CHECKING, Any, Literal
|
||||
|
||||
from pydantic import Field
|
||||
|
||||
from media_library_viewer_api.clients.qbittorrent import QbittorrentClient
|
||||
from media_library_viewer_api.integrations.base import (
|
||||
SecretField,
|
||||
@@ -52,10 +54,24 @@ def test_connection(
|
||||
|
||||
|
||||
class QbittorrentConfig(ServiceConfigBase):
|
||||
"""Non-secret qBittorrent connection config."""
|
||||
"""Non-secret qBittorrent connection and sampling config."""
|
||||
|
||||
base_url: ServiceBaseUrl
|
||||
timeout_seconds: int = 60
|
||||
timeout_seconds: int = Field(default=60, ge=1, le=300)
|
||||
polling_enabled: bool = Field(default=True, description="Collect speed samples without an open dashboard")
|
||||
poll_interval_seconds: int = Field(default=15, ge=5, le=300, description="Seconds between speed samples")
|
||||
sample_retention_seconds: int = Field(
|
||||
default=1_800,
|
||||
ge=60,
|
||||
le=86_400,
|
||||
description="How long speed samples remain available",
|
||||
)
|
||||
sample_max_rows: int = Field(
|
||||
default=1_200,
|
||||
ge=60,
|
||||
le=1_200,
|
||||
description="Maximum speed samples retained per service",
|
||||
)
|
||||
|
||||
|
||||
class QbittorrentWidgetConfig(WidgetConfigBase):
|
||||
@@ -67,6 +83,7 @@ class QbittorrentWidgetConfig(WidgetConfigBase):
|
||||
class QbittorrentSpeedWidgetConfig(WidgetConfigBase):
|
||||
"""Speed chart config. The source returns raw bytes/sec; the frontend scales."""
|
||||
|
||||
window_seconds: int = Field(default=1_800, ge=60, le=86_400)
|
||||
unit: Literal[
|
||||
"none",
|
||||
"bytes",
|
||||
@@ -110,7 +127,7 @@ DEFINITION = ServiceDefinition(
|
||||
name="Speed chart",
|
||||
description="Live download/upload speed over a short window.",
|
||||
model_cls=QbittorrentSpeedWidgetConfig,
|
||||
default_config={"unit": "bytes_per_sec", "scale": "auto"},
|
||||
default_config={"window_seconds": 1_800, "unit": "bytes_per_sec", "scale": "auto"},
|
||||
refresh_interval_ms=15_000,
|
||||
),
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user