feat: Introduce quick capture widget configuration and validation
- Added support for the "quick_capture" widget, allowing users to configure visibility for weight and baseline vitals (resting HR, HRV, VO₂max). - Implemented validation logic to ensure correct configuration input and prevent errors. - Updated the widget catalog and dashboard layout to reflect the new quick capture features. - Removed the "training_type_distribution" widget from the catalog as part of the refactor. - Bumped app_dashboard version to 1.6.2 to incorporate these enhancements.
This commit is contained in:
1 parent
3d498d03c1
commit
7f833b2cb1
9 files changed
+267
-107
No files matched your search
@@ -16,8 +16,15 @@ WIDGETS_ALLOWING_CONFIG: frozenset[str] = frozenset({
|
||||
"body_overview",
|
||||
"activity_overview",
|
||||
"kpi_board",
|
||||
"quick_capture",
|
||||
"trend_kcal_weight",
|
||||
"training_type_distribution",
|
||||
})
|
||||
|
||||
_QUICK_CAPTURE_KEYS: frozenset[str] = frozenset({
|
||||
"show_weight",
|
||||
"show_resting_hr",
|
||||
"show_hrv",
|
||||
"show_vo2_max",
|
||||
})
|
||||
|
||||
_KPI_TILE_FIXED: frozenset[str] = frozenset({"body_fat", "avg_kcal"})
|
||||
@@ -47,14 +54,34 @@ def validate_widget_entry_config(widget_id: str, raw: Any) -> dict[str, Any]:
|
||||
return _validate_chart_days_only(raw, label="activity_overview")
|
||||
if widget_id == "kpi_board":
|
||||
return _validate_kpi_board_config(raw)
|
||||
if widget_id == "quick_capture":
|
||||
return _validate_quick_capture_config(raw)
|
||||
if widget_id == "trend_kcal_weight":
|
||||
return _validate_chart_days_only(raw, label="trend_kcal_weight")
|
||||
if widget_id == "training_type_distribution":
|
||||
return _validate_distribution_days_only(raw)
|
||||
|
||||
raise ValueError(f"Widget {widget_id}: keine Konfiguration unterstützt")
|
||||
|
||||
|
||||
def _validate_quick_capture_config(raw: dict[str, Any]) -> dict[str, Any]:
|
||||
label = "quick_capture"
|
||||
unknown = set(raw) - _QUICK_CAPTURE_KEYS
|
||||
if unknown:
|
||||
raise ValueError(f"{label}: unbekannte config-Felder: {sorted(unknown)}")
|
||||
out: dict[str, bool] = {}
|
||||
for k in _QUICK_CAPTURE_KEYS:
|
||||
if k not in raw:
|
||||
continue
|
||||
v = raw[k]
|
||||
if not isinstance(v, bool):
|
||||
raise ValueError(f"{label}: {k} muss boolean sein")
|
||||
out[k] = v
|
||||
merged = {k: True for k in _QUICK_CAPTURE_KEYS}
|
||||
merged.update(out)
|
||||
if not any(merged.values()):
|
||||
raise ValueError(f"{label}: mindestens ein Bereich muss sichtbar sein (show_*)")
|
||||
return out
|
||||
|
||||
|
||||
def _kpi_tile_id_valid(tid: str) -> bool:
|
||||
if tid in _KPI_TILE_FIXED:
|
||||
return True
|
||||
@@ -130,15 +157,3 @@ def _validate_chart_days_only(raw: dict[str, Any], *, label: str) -> dict[str, A
|
||||
return {"chart_days": v}
|
||||
|
||||
|
||||
def _validate_distribution_days_only(raw: dict[str, Any]) -> dict[str, Any]:
|
||||
label = "training_type_distribution"
|
||||
allowed = frozenset({"distribution_days"})
|
||||
unknown = set(raw) - allowed
|
||||
if unknown:
|
||||
raise ValueError(f"{label}: unbekannte config-Felder: {sorted(unknown)}")
|
||||
if "distribution_days" not in raw:
|
||||
return {}
|
||||
v = _parse_chart_days(raw["distribution_days"], label)
|
||||
if v < 7 or v > 120:
|
||||
raise ValueError(f"{label}: distribution_days muss zwischen 7 und 120 liegen")
|
||||
return {"distribution_days": v}
|
||||
Reference in new issue
Block a user