fix: handle scrutiny smart field as dict (KeyError: -1)
This commit is contained in:
@@ -26,7 +26,6 @@ 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
|
||||||
@@ -52,12 +51,24 @@ 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_list: list = 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"
|
||||||
|
|
||||||
latest_smart = smart_list[-1] if smart_list else {}
|
|
||||||
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"
|
||||||
@@ -66,6 +77,15 @@ class ScrutinyClient(BaseHTTPClient):
|
|||||||
else:
|
else:
|
||||||
status = "unknown"
|
status = "unknown"
|
||||||
|
|
||||||
devices.append(ScrutinyDevice(name=name, model=model, status=status))
|
# Temperature: try top-level "temp", then nested attrs
|
||||||
|
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