|
2 | 2 |
|
3 | 3 | from __future__ import annotations |
4 | 4 |
|
5 | | -from datetime import datetime |
| 5 | +from datetime import datetime, timedelta |
6 | 6 | from enum import Enum, auto |
7 | 7 | import logging |
8 | 8 | from typing import Final |
@@ -280,12 +280,14 @@ def update( |
280 | 280 | """Get pulse update.""" |
281 | 281 | last_reset = datetime.now(tz=LOCAL_TIMEZONE) |
282 | 282 | if self._energy_id in ENERGY_HOUR_COUNTERS: |
283 | | - # No syncing needed for the hour-counters, they reset when the device pulsecounter(s) reset |
284 | 283 | last_reset = last_reset.replace(minute=0, second=0, microsecond=0) |
285 | 284 | 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 | + ) |
289 | 291 |
|
290 | 292 | pulses, last_update = pulse_collection.collected_pulses( |
291 | 293 | last_reset, self._is_consumption |
|
0 commit comments