Skip to content

Commit 9c62ac8

Browse files
committed
Delay/sync the from_timestamps as well
1 parent 75cf08d commit 9c62ac8

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

plugwise_usb/nodes/helpers/pulses.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,23 @@ def collected_pulses(
172172
self, from_timestamp: datetime, is_consumption: bool
173173
) -> tuple[int | None, datetime | None]:
174174
"""Calculate total pulses from given timestamp."""
175+
176+
# Sync from_timestamp with the device pulsecounter reset-time
177+
# This syncs the hourly/daily reset of energy counters with the corresponding device pulsecounter reset
178+
if is_consumption:
179+
if self._cons_last_hourly_reset is not None :
180+
from_timestamp = from_timestamp + timedelta(
181+
minutes=self._cons_last_hourly_reset.minute,
182+
seconds=self._cons_last_hourly_reset.second,
183+
microseconds=self._cons_last_hourly_reset.microsecond,
184+
)
185+
elif self._prod_last_hourly_reset is not None:
186+
from_timestamp = from_timestamp + timedelta(
187+
minutes=self._prod_last_hourly_reset.minute,
188+
seconds=self._prod_last_hourly_reset.second,
189+
microseconds=self._prod_last_hourly_reset.microsecond,
190+
)
191+
175192
_LOGGER.debug(
176193
"collected_pulses | %s | from_timestamp=%s | is_cons=%s | _log_production=%s",
177194
self._mac,

0 commit comments

Comments
 (0)