Skip to content

Commit 53769ff

Browse files
committed
Correct corrected_pulses to 0 when negative
corrected_pulses should always be >= 0
1 parent 2913766 commit 53769ff

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

plugwise_usb/nodes/circle.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1039,20 +1039,23 @@ def _calc_watts(self, pulses: int, seconds: int, nano_offset: int) -> float | No
10391039
negative = True
10401040
pulses_per_s = abs(pulses_per_s)
10411041

1042-
corrected_pulses = seconds * (
1043-
(
1042+
corrected_pulses = max(
1043+
0,
1044+
seconds * (
10441045
(
1045-
((pulses_per_s + self._calibration.off_noise) ** 2)
1046-
* self._calibration.gain_b
1047-
)
1048-
+ (
1049-
(pulses_per_s + self._calibration.off_noise)
1050-
* self._calibration.gain_a
1046+
(
1047+
((pulses_per_s + self._calibration.off_noise) ** 2)
1048+
* self._calibration.gain_b
1049+
)
1050+
+ (
1051+
(pulses_per_s + self._calibration.off_noise)
1052+
* self._calibration.gain_a
1053+
)
10511054
)
1055+
+ self._calibration.off_tot
10521056
)
1053-
+ self._calibration.off_tot
10541057
)
1055-
if negative:
1058+
if negative and corrected_pulses != 0:
10561059
corrected_pulses = -corrected_pulses
10571060

10581061
return corrected_pulses / PULSES_PER_KW_SECOND / seconds * (1000)

0 commit comments

Comments
 (0)