Added value-error for negative integration (#1390)

old-commit-hash: 15f57c4c22bb8e1f091344891e5b7d88443683d1
This commit is contained in:
robbederks
2020-04-17 14:05:43 -07:00
committed by GitHub
parent a4c5bffd75
commit a072639865
+4 -1
View File
@@ -152,7 +152,10 @@ class PowerMonitoring:
try:
if self.last_measurement_time:
integration_time_h = (t - self.last_measurement_time) / 3600
self.power_used_uWh += (current_power * 1000000) * integration_time_h
power_used = (current_power * 1000000) * integration_time_h
if power_used < 0:
raise ValueError(f"Negative power used! Integration time: {integration_time_h} h Current Power: {power_used} uWh")
self.power_used_uWh += power_used
self.last_measurement_time = t
except Exception:
cloudlog.exception("Integration failed")