Skip to content

Commit bb221fe

Browse files
committed
Update _reset_log_references()
1 parent c8bfd57 commit bb221fe

File tree

1 file changed

+22
-41
lines changed

1 file changed

+22
-41
lines changed

plugwise_usb/nodes/helpers/pulses.py

Lines changed: 22 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -436,50 +436,31 @@ def _update_last_log_reference(
436436

437437
def _reset_log_references(self) -> None:
438438
"""Reset log references."""
439-
self._last_log_consumption_address = None
440-
self._last_log_consumption_slot = None
441-
self._last_log_consumption_timestamp = None
442-
self._first_log_consumption_address = None
443-
self._first_log_consumption_slot = None
444-
self._first_log_consumption_timestamp = None
445-
self._last_log_production_address = None
446-
self._last_log_production_slot = None
447-
self._last_log_production_timestamp = None
448-
self._first_log_production_address = None
449-
self._first_log_production_slot = None
450-
self._first_log_production_timestamp = None
439+
self._last_log_address = None
440+
self._last_log_slot = None
441+
self._last_log_timestamp = None
442+
self._first_log_address = None
443+
self._first_log_slot = None
444+
self._first_log_timestamp = None
445+
451446
if self._logs is None:
452447
return
448+
453449
for address in self._logs:
454-
for slot, log_record in self._logs[address].items():
455-
if log_record.is_consumption:
456-
if self._last_log_consumption_timestamp is None:
457-
self._last_log_consumption_timestamp = log_record.timestamp
458-
if self._last_log_consumption_timestamp <= log_record.timestamp:
459-
self._last_log_consumption_timestamp = log_record.timestamp
460-
self._last_log_consumption_address = address
461-
self._last_log_consumption_slot = slot
462-
463-
if self._first_log_consumption_timestamp is None:
464-
self._first_log_consumption_timestamp = log_record.timestamp
465-
if self._first_log_consumption_timestamp >= log_record.timestamp:
466-
self._first_log_consumption_timestamp = log_record.timestamp
467-
self._first_log_consumption_address = address
468-
self._first_log_consumption_slot = slot
469-
else:
470-
if self._last_log_production_timestamp is None:
471-
self._last_log_production_timestamp = log_record.timestamp
472-
if self._last_log_production_timestamp <= log_record.timestamp:
473-
self._last_log_production_timestamp = log_record.timestamp
474-
self._last_log_production_address = address
475-
self._last_log_production_slot = slot
476-
477-
if self._first_log_production_timestamp is None:
478-
self._first_log_production_timestamp = log_record.timestamp
479-
if self._first_log_production_timestamp > log_record.timestamp:
480-
self._first_log_production_timestamp = log_record.timestamp
481-
self._first_log_production_address = address
482-
self._first_log_production_slot = slot
450+
for slot, _ in self._logs[address].items():
451+
if self._last_log_timestamp is None:
452+
self._last_log_timestamp = log_record.timestamp
453+
if self._last_log_timestamp <= log_record.timestamp:
454+
self._last_log_timestamp = log_record.timestamp
455+
self._last_log_address = address
456+
self._last_log_slot = slot
457+
458+
if self._first_log_timestamp is None:
459+
self._first_log_timestamp = log_record.timestamp
460+
if self._first_log_timestamp >= log_record.timestamp:
461+
self._first_log_timestamp = log_record.timestamp
462+
self._first_log_address = address
463+
self._first_log_slot = slot
483464

484465
def _update_first_log_reference(
485466
self, address: int, slot: int, timestamp: datetime, is_consumption: bool

0 commit comments

Comments
 (0)