Skip to content

Commit 50ef927

Browse files
committed
Improve _collect_pulses_from_logs()
1 parent 5953917 commit 50ef927

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

plugwise_usb/nodes/helpers/pulses.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -221,12 +221,13 @@ def _collect_pulses_from_logs(
221221
self._mac,
222222
)
223223
return None
224+
225+
timestamp = self._last_log_consumption_timestamp
224226
if (
225-
from_timestamp > self._last_log_consumption_timestamp
227+
from_timestamp > timestamp
226228
and self._pulsecounter_reset
227229
):
228-
_LOGGER.debug("_collect_pulses_from_logs | resetting log_pulses collection")
229-
timestamp = self._last_log_consumption_timestamp
230+
_LOGGER.debug("_collect_pulses_from_logs | resetting log_pulses to 0")
230231
return 0
231232
else:
232233
if self._last_log_production_timestamp is None:
@@ -235,12 +236,13 @@ def _collect_pulses_from_logs(
235236
self._mac,
236237
)
237238
return None
239+
240+
timestamp = self._last_log_production_timestamp
238241
if (
239-
from_timestamp > self._last_log_production_timestamp
242+
from_timestamp > timestamp
240243
and self._pulsecounter_reset
241244
):
242-
_LOGGER.debug("_collect_pulses_from_logs | resetting log_pulses collection")
243-
timestamp = self._last_log_production_timestamp
245+
_LOGGER.debug("_collect_pulses_from_logs | resetting log_pulses to 0")
244246
return 0
245247

246248
missing_logs = self._logs_missing(from_timestamp)
@@ -262,8 +264,9 @@ def _collect_pulses_from_logs(
262264
log_pulses += slot_item.pulses
263265

264266
_LOGGER.debug(
265-
"_collect_pulses_from_logs | log_pulses=%s | from %s to %s",
267+
"_collect_pulses_from_logs | log_pulses=%s | is_consumption=%s | from %s to %s",
266268
log_pulses,
269+
is_consumption,
267270
from_timestamp,
268271
timestamp,
269272
)

0 commit comments

Comments
 (0)