safraeli commited on
Commit
db442e6
·
verified ·
1 Parent(s): b09e6cd

Wrap sensor history imports in try/except, add logging to all failure points

Browse files
Files changed (1) hide show
  1. src/data/data_providers.py +8 -3
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
- from src.thingsboard_client import (
336
- AIR_KEYS, CROP_KEYS, SOIL_KEYS, DEVICE_REGISTRY, VineArea,
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