Skip to content

Commit e81fc18

Browse files
committed
Update last_reset logic once more
1 parent ca83ca2 commit e81fc18

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

plugwise_usb/nodes/helpers/counter.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from __future__ import annotations
44

5-
from datetime import datetime
5+
from datetime import datetime, timedelta
66
from enum import Enum, auto
77
import logging
88
from typing import Final
@@ -280,12 +280,14 @@ def update(
280280
"""Get pulse update."""
281281
last_reset = datetime.now(tz=LOCAL_TIMEZONE)
282282
if self._energy_id in ENERGY_HOUR_COUNTERS:
283-
# No syncing needed for the hour-counters, they reset when the device pulsecounter(s) reset
284283
last_reset = last_reset.replace(minute=0, second=0, microsecond=0)
285284
if self._energy_id in ENERGY_DAY_COUNTERS:
286-
# Postpone the daily last_reset time-change until a device pulsecounter resets
287-
if pulse_collection.pulse_counter_reset:
288-
last_reset = last_reset.replace(hour=0, minute=0, second=0, microsecond=0)
285+
last_reset = last_reset.replace(hour=0, minute=0, second=0, microsecond=0)
286+
# Postpone the last_reset time-changes at day-end until a device pulsecounter resets
287+
if last_reset.hour == 0 and not pulse_collection.pulse_counter_reset:
288+
last_reset = (last_reset - timedelta(days=1)).replace(
289+
hour=0, minute=0, second=0, microsecond=0
290+
)
289291

290292
pulses, last_update = pulse_collection.collected_pulses(
291293
last_reset, self._is_consumption

0 commit comments

Comments
 (0)