Skip to content

Commit d2f6471

Browse files
committed
Improve logic
1 parent ff2add5 commit d2f6471

File tree

1 file changed

+22
-18
lines changed

1 file changed

+22
-18
lines changed

plugwise_usb/nodes/helpers/pulses.py

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,12 @@ def update_pulse_counter(
279279

280280
######### still to finish
281281
def _update_rollover(self) -> None:
282-
"""Update rollover states. Returns True if rollover is applicable."""
282+
"""Update rollover states.
283+
284+
When the last found timestamp is outside the interval `_last_log_timestamp`
285+
to `_next_log_timestamp` the pulses should not be counted as part of the
286+
ongoing collection-interval.
287+
"""
283288
if self._log_addresses_missing is not None and self._log_addresses_missing:
284289
return
285290

@@ -302,8 +307,10 @@ def _update_rollover(self) -> None:
302307
_LOGGER.debug(
303308
"_update_rollover | %s | set production rollover => pulses newer",
304309
self._mac,
305-
)
306-
elif self._pulses_timestamp < self._last_log_timestamp:
310+
)
311+
return
312+
313+
if self._pulses_timestamp < self._last_log_timestamp:
307314
if CONSUMPTION: # TODO
308315
self._rollover_consumption = True
309316
_LOGGER.debug(
@@ -316,21 +323,18 @@ def _update_rollover(self) -> None:
316323
"_update_rollover | %s | reset production rollover => log newer",
317324
self._mac,
318325
)
319-
elif (
320-
self._last_log_timestamp
321-
< self._pulses_timestamp
322-
< self._next_log_timestamp
323-
):
324-
if CONSUMPTION: # TODO
325-
if self._rollover_consumption:
326-
_LOGGER.debug("_update_rollover | %s | reset consumption", self._mac)
327-
self._rollover_consumption = False
328-
if PRODUCTION: # TODO
329-
if self._rollover_production:
330-
_LOGGER.debug("_update_rollover | %s | reset production", self._mac)
331-
self._rollover_production = False
332-
else:
333-
_LOGGER.debug("_update_rollover | %s | unexpected consumption/production", self._mac)
326+
return
327+
328+
# _last_log_timestamp <= _pulses_timestamp <= _next_log_timestamp
329+
if CONSUMPTION: # TODO
330+
if self._rollover_consumption:
331+
_LOGGER.debug("_update_rollover | %s | reset consumption", self._mac)
332+
self._rollover_consumption = False
333+
if PRODUCTION: # TODO
334+
if self._rollover_production:
335+
_LOGGER.debug("_update_rollover | %s | reset production", self._mac)
336+
self._rollover_production = False
337+
return
334338

335339
def add_empty_log(self, address: int, slot: int) -> None:
336340
"""Add empty energy log record to mark any start of beginning of energy log collection."""

0 commit comments

Comments
 (0)