Skip to content

Commit 3d548c8

Browse files
committed
Delay/sync the from_timestamps as well
1 parent 75cf08d commit 3d548c8

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

plugwise_usb/nodes/helpers/pulses.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,22 @@ 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+
from_timestamp = from_timestamp + timedelta(
180+
minutes=self._cons_last_hourly_reset.minute,
181+
seconds=self._cons_last_hourly_reset.second,
182+
microseconds=self._cons_last_hourly_reset.microsecond,
183+
)
184+
else:
185+
from_timestamp = from_timestamp + timedelta(
186+
minutes=self._prod_last_hourly_reset.minute,
187+
seconds=self._prod_last_hourly_reset.second,
188+
microseconds=self._prod_last_hourly_reset.microsecond,
189+
)
190+
175191
_LOGGER.debug(
176192
"collected_pulses | %s | from_timestamp=%s | is_cons=%s | _log_production=%s",
177193
self._mac,

0 commit comments

Comments
 (0)