소스 검색

Fix energy costs not updating per timeframe in statistics (#695)

  In "total" energy tracking mode, the stats endpoint queried smart plug
  lifetime counters which can't be filtered by date range. Energy costs
  and kWh stayed the same regardless of timeframe selection. Fall back to
  per-print archive data when date filters are active.
maziggy 5 달 전
부모
커밋
d8770b2bce
1개의 변경된 파일3개의 추가작업 그리고 1개의 파일을 삭제
  1. 3 1
      backend/app/api/routes/archives.py

+ 3 - 1
backend/app/api/routes/archives.py

@@ -642,7 +642,9 @@ async def get_archive_stats(
     energy_cost_per_kwh_str = await get_setting(db, "energy_cost_per_kwh")
     energy_cost_per_kwh = float(energy_cost_per_kwh_str) if energy_cost_per_kwh_str else 0.15
 
-    if energy_tracking_mode == "total":
+    # When date filters are active, smart plug lifetime totals can't be
+    # filtered by date range — fall back to per-print archive data instead.
+    if energy_tracking_mode == "total" and not date_from and not date_to:
         # Total mode: sum up 'total' counter from all smart plugs (lifetime consumption)
         from backend.app.models.smart_plug import SmartPlug
         from backend.app.services.homeassistant import homeassistant_service