Wrap sensor history imports in try/except, add logging to all failure points
Browse files
src/data/data_providers.py
CHANGED
|
@@ -332,9 +332,13 @@ class VineSensorService(BaseService):
|
|
| 332 |
hours_back: int = 24,
|
| 333 |
) -> Dict[str, Any]:
|
| 334 |
"""Hourly averages for a device group over the last N hours."""
|
| 335 |
-
|
| 336 |
-
|
| 337 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 338 |
|
| 339 |
key_map = {"air": AIR_KEYS, "crop": CROP_KEYS, "soil": SOIL_KEYS}
|
| 340 |
keys = key_map.get(device_type.lower())
|
|
@@ -373,6 +377,7 @@ class VineSensorService(BaseService):
|
|
| 373 |
hourly = merged.resample("1h").mean(numeric_only=True)
|
| 374 |
return summarise_dataframe(hourly)
|
| 375 |
except Exception as exc:
|
|
|
|
| 376 |
return {"error": f"Sensor history failed: {exc}"}
|
| 377 |
|
| 378 |
|
|
|
|
| 332 |
hours_back: int = 24,
|
| 333 |
) -> Dict[str, Any]:
|
| 334 |
"""Hourly averages for a device group over the last N hours."""
|
| 335 |
+
try:
|
| 336 |
+
from src.thingsboard_client import (
|
| 337 |
+
AIR_KEYS, CROP_KEYS, SOIL_KEYS, DEVICE_REGISTRY, VineArea,
|
| 338 |
+
)
|
| 339 |
+
except Exception as exc:
|
| 340 |
+
log.error("ThingsBoard client import failed: %s", exc)
|
| 341 |
+
return {"error": f"ThingsBoard client unavailable: {exc}"}
|
| 342 |
|
| 343 |
key_map = {"air": AIR_KEYS, "crop": CROP_KEYS, "soil": SOIL_KEYS}
|
| 344 |
keys = key_map.get(device_type.lower())
|
|
|
|
| 377 |
hourly = merged.resample("1h").mean(numeric_only=True)
|
| 378 |
return summarise_dataframe(hourly)
|
| 379 |
except Exception as exc:
|
| 380 |
+
log.error("Sensor history query failed: %s", exc)
|
| 381 |
return {"error": f"Sensor history failed: {exc}"}
|
| 382 |
|
| 383 |
|