Skip to content

Commit 800f307

Browse files
committed
Switch pulses and timestamp positions
1 parent 526b2ba commit 800f307

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

plugwise_usb/nodes/circle.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,7 @@ async def _energy_log_records_load_from_cache(self) -> bool: # noqa: PLR0912
603603
"Failed to restore energy log records from cache for node %s", self.name
604604
)
605605
return False
606-
restored_logs: dict[int, dict[int, tuple[int, datetime]]] = {}
606+
restored_logs: dict[int, dict[int, tuple[datetime, int]]] = {}
607607
if cache_data == "":
608608
_LOGGER.debug("Cache-record is empty")
609609
return False
@@ -628,17 +628,17 @@ async def _energy_log_records_load_from_cache(self) -> bool: # noqa: PLR0912
628628
)
629629
if restored_logs.get(address) is None:
630630
restored_logs[address] = {}
631-
restored_logs[address][slot] = (pulses, timestamp)
631+
restored_logs[address][slot] = tuple((timestamp, pulses))
632632
_LOGGER.debug("HOI restored_logs=%s", restored_logs)
633633

634634
# Sort and prune the records loaded from cache
635-
sorted_logs: dict[int, dict[int, tuple[int, datetime]]] = {}
635+
sorted_logs: dict[int, dict[int, tuple[datetime, int]]] = {}
636636
skip_before = datetime.now(tz=UTC) - timedelta(hours=DAY_IN_HOURS)
637637
sorted_addresses = sorted(restored_logs.keys(), reverse=True)
638638
for address in sorted_addresses:
639639
sorted_slots = sorted(restored_logs[address].keys(), reverse=True)
640640
for slot in sorted_slots:
641-
if restored_logs[address][slot][1] > skip_before:
641+
if restored_logs[address][slot][0] > skip_before:
642642
if sorted_logs.get(address) is None:
643643
sorted_logs[address] = {}
644644
sorted_logs[address][slot] = restored_logs[address][slot]
@@ -648,8 +648,8 @@ async def _energy_log_records_load_from_cache(self) -> bool: # noqa: PLR0912
648648
self._energy_counters.add_pulse_log(
649649
address=address,
650650
slot=slot,
651-
pulses=pulse_data[0],
652-
timestamp=pulse_data[1],
651+
pulses=pulse_data[1],
652+
timestamp=pulse_data[0],
653653
import_only=True,
654654
)
655655

0 commit comments

Comments
 (0)