feat(widgets): add unit/scale config to chart widget kinds
Graph widgets need consistent value scaling (kB/MB/GB, kbps/Mbps, …). Add shared `unit` (none/bytes/bytes_per_sec/bits_per_sec/bits/percent/seconds) and `scale` (auto/k/m/g/t) enum fields to: - PrometheusChartWidgetConfig (alongside promql/window) - new QbittorrentSpeedWidgetConfig — the speed widget previously had NO config options at all; totals/active keep their empty config. Declared as Pydantic Literal enums so the widget-kind JSON schema exposes `enum`, which the frontend config dialog renders as a dropdown. The data sources are unchanged (raw values); scaling is a display concern handled client-side. qBittorrent speed defaults to bytes/sec. Test: chart widget kinds expose the shared unit/scale enums; speed defaults to bytes_per_sec; totals/active stay option-less. 389/389 backend tests pass.
This commit is contained in:
@@ -7,7 +7,7 @@ password), and three widget kinds (totals, active, speed). Models on
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import TYPE_CHECKING, Any
|
||||
from typing import TYPE_CHECKING, Any, Literal
|
||||
|
||||
from media_library_viewer_api.clients.qbittorrent import QbittorrentClient
|
||||
from media_library_viewer_api.integrations.base import (
|
||||
@@ -59,11 +59,26 @@ class QbittorrentConfig(ServiceConfigBase):
|
||||
|
||||
|
||||
class QbittorrentWidgetConfig(WidgetConfigBase):
|
||||
"""Per-widget config (empty — all three kinds derive from the service connection)."""
|
||||
"""Per-widget config for totals/active (empty — derived from the service connection)."""
|
||||
|
||||
pass
|
||||
|
||||
|
||||
class QbittorrentSpeedWidgetConfig(WidgetConfigBase):
|
||||
"""Speed chart config. The source returns raw bytes/sec; the frontend scales."""
|
||||
|
||||
unit: Literal[
|
||||
"none",
|
||||
"bytes",
|
||||
"bytes_per_sec",
|
||||
"bits_per_sec",
|
||||
"bits",
|
||||
"percent",
|
||||
"seconds",
|
||||
] = "bytes_per_sec"
|
||||
scale: Literal["auto", "k", "m", "g", "t"] = "auto"
|
||||
|
||||
|
||||
DEFINITION = ServiceDefinition(
|
||||
service_type="qbittorrent",
|
||||
name="qBittorrent",
|
||||
@@ -94,8 +109,8 @@ DEFINITION = ServiceDefinition(
|
||||
kind="speed",
|
||||
name="Speed chart",
|
||||
description="Live download/upload speed over a short window.",
|
||||
model_cls=QbittorrentWidgetConfig,
|
||||
default_config={},
|
||||
model_cls=QbittorrentSpeedWidgetConfig,
|
||||
default_config={"unit": "bytes_per_sec", "scale": "auto"},
|
||||
refresh_interval_ms=5_000,
|
||||
),
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user