Skip to content

Commit f96de0d

Browse files
committed
Improve counter update()
1 parent 458a378 commit f96de0d

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

plugwise_usb/nodes/helpers/counter.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -286,14 +286,14 @@ def update(
286286
if self._energy_id in ENERGY_HOUR_COUNTERS:
287287
last_reset = last_reset.replace(minute=0, second=0, microsecond=0)
288288
if self._energy_id in ENERGY_DAY_COUNTERS:
289-
last_reset = last_reset.replace(hour=0, minute=0, second=0, microsecond=0)
290-
# Postpone the last_reset time-changes at day-end until a device pulsecounter resets
289+
reset: bool = pulse_collection.pulse_counter_reset
291290
_LOGGER.debug("energycounter_update | last reset hour=%s", last_reset.hour)
292291
_LOGGER.debug(
293292
"energycounter_update | pulse_counter_reset=%s, midnight_reset_passed=%s",
294-
pulse_collection.pulse_counter_reset,
293+
reset,
295294
self._midnight_reset_passed,
296295
)
296+
# Postpone the last_reset time-changes at day-end until a device pulsecounter resets
297297
if last_reset.hour == 0 and (
298298
not pulse_collection.pulse_counter_reset
299299
and not self._midnight_reset_passed
@@ -302,6 +302,8 @@ def update(
302302
hour=0, minute=0, second=0, microsecond=0
303303
)
304304
self._midnight_reset_passed = True
305+
else:
306+
last_reset = last_reset.replace(hour=0, minute=0, second=0, microsecond=0)
305307

306308
pulses, last_update = pulse_collection.collected_pulses(
307309
last_reset, self._is_consumption

0 commit comments

Comments
 (0)