apps/dashboard/backend/app/clients/scrutiny_client.py aktualisiert
This commit is contained in:
@@ -26,6 +26,7 @@ class ScrutinyClient(BaseHTTPClient):
|
|||||||
return snapshot
|
return snapshot
|
||||||
|
|
||||||
data = await self._request_json("GET", "/api/summary")
|
data = await self._request_json("GET", "/api/summary")
|
||||||
|
|
||||||
if data is None:
|
if data is None:
|
||||||
logger.warning("scrutiny: empty or failed response")
|
logger.warning("scrutiny: empty or failed response")
|
||||||
return snapshot
|
return snapshot
|
||||||
@@ -51,24 +52,20 @@ class ScrutinyClient(BaseHTTPClient):
|
|||||||
|
|
||||||
for device_path, device_data in summary.items():
|
for device_path, device_data in summary.items():
|
||||||
device_info: dict = device_data.get("device") or {}
|
device_info: dict = device_data.get("device") or {}
|
||||||
|
smart_data = device_data.get("smart") or []
|
||||||
# "smart" may be a list OR a dict keyed by timestamp — handle both
|
|
||||||
smart_raw = device_data.get("smart") or {}
|
|
||||||
if isinstance(smart_raw, dict):
|
|
||||||
smart_values = list(smart_raw.values())
|
|
||||||
elif isinstance(smart_raw, list):
|
|
||||||
smart_values = smart_raw
|
|
||||||
else:
|
|
||||||
smart_values = []
|
|
||||||
|
|
||||||
# Sort by date if values have a date field, otherwise take last entry
|
|
||||||
if smart_values and isinstance(smart_values[0], dict) and "date" in smart_values[0]:
|
|
||||||
smart_values = sorted(smart_values, key=lambda x: x.get("date", ""))
|
|
||||||
latest_smart = smart_values[-1] if smart_values else {}
|
|
||||||
|
|
||||||
name = device_info.get("device_name") or device_path.split("/")[-1]
|
name = device_info.get("device_name") or device_path.split("/")[-1]
|
||||||
model = device_info.get("model_name") or "Unknown"
|
model = device_info.get("model_name") or "Unknown"
|
||||||
|
|
||||||
|
if isinstance(smart_data, dict):
|
||||||
|
# smart is a dict keyed by timestamp strings; grab the most recent value
|
||||||
|
latest_smart = smart_data[max(smart_data)] if smart_data else {}
|
||||||
|
elif isinstance(smart_data, list):
|
||||||
|
latest_smart = smart_data[-1] if smart_data else {}
|
||||||
|
else:
|
||||||
|
latest_smart = {}
|
||||||
|
if not isinstance(latest_smart, dict):
|
||||||
|
latest_smart = {}
|
||||||
status_code = latest_smart.get("Status", -1)
|
status_code = latest_smart.get("Status", -1)
|
||||||
if status_code == 0:
|
if status_code == 0:
|
||||||
status = "passed"
|
status = "passed"
|
||||||
@@ -77,15 +74,6 @@ class ScrutinyClient(BaseHTTPClient):
|
|||||||
else:
|
else:
|
||||||
status = "unknown"
|
status = "unknown"
|
||||||
|
|
||||||
# Temperature: try top-level "temp", then nested attrs
|
devices.append(ScrutinyDevice(name=name, model=model, status=status))
|
||||||
temperature: int | None = None
|
|
||||||
temp_val = latest_smart.get("temp") or latest_smart.get("temperature")
|
|
||||||
if temp_val is not None:
|
|
||||||
try:
|
|
||||||
temperature = int(temp_val)
|
|
||||||
except (TypeError, ValueError):
|
|
||||||
pass
|
|
||||||
|
|
||||||
devices.append(ScrutinyDevice(name=name, model=model, status=status, temperature=temperature))
|
|
||||||
|
|
||||||
return sorted(devices, key=lambda d: d.name)
|
return sorted(devices, key=lambda d: d.name)
|
||||||
|
|||||||
Reference in New Issue
Block a user