Skip to content

Commit 27bd8ca

Browse files
committed
Change negative _pulses handling
1 parent 2738abd commit 27bd8ca

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

plugwise_usb/nodes/helpers/counter.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,11 @@ def energy(self) -> float | None:
263263
if self._pulses == 0:
264264
return 0.0
265265
# Handle both positive and negative pulses values
266-
pulses_per_s = abs(self._pulses / float(HOUR_IN_SECONDS))
266+
negative = False
267+
if self._pulses < 0:
268+
negative = True
269+
270+
pulses_per_s = abs(self._pulses) / float(HOUR_IN_SECONDS)
267271
corrected_pulses = HOUR_IN_SECONDS * (
268272
(
269273
(
@@ -278,6 +282,8 @@ def energy(self) -> float | None:
278282
+ self._calibration.off_tot
279283
)
280284
calc_value = corrected_pulses / PULSES_PER_KW_SECOND / HOUR_IN_SECONDS
285+
if negative:
286+
calc_value = -calc_value
281287
return calc_value
282288

283289
@property

0 commit comments

Comments
 (0)