Skip to content

Commit b874af5

Browse files
committed
Improve logic, the first collection is from the current_log_address
1 parent db088bf commit b874af5

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

plugwise_usb/nodes/circle.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -448,13 +448,24 @@ async def get_missing_energy_logs(self) -> None:
448448
)
449449
total_addresses = 11
450450
log_address = self._current_log_address
451+
prev_address_timestamp: datetime | None = None
451452
while total_addresses > 0:
452453
await self.energy_log_update(log_address)
453-
if self._last_collected_energy_timestamp is not None and (
454-
datetime.now(tz=UTC) - self._last_collected_energy_timestamp
455-
).total_seconds // 60 > 65: # assuming log_interval is 60 minutes
454+
# Check if the most recent timestamp of an earlier address is recent (4 * log_interval plus 5 mins margin)
455+
if (
456+
log_address != self._current_log_address
457+
and self._last_collected_energy_timestamp is not None
458+
and prev_address_timestamp is not None
459+
and (
460+
prev_address_timestamp - self._last_collected_energy_timestamp
461+
).total_seconds() // 60 > (4 * 60) + 5 # minutes
462+
):
456463
_LOGGER.debug("Energy data collected is outdated, stopping collection")
457464
break
465+
466+
if self._last_collected_energy_timestamp is not None:
467+
prev_address_timestamp = self._last_collected_energy_timestamp
468+
458469
log_address, _ = calc_log_address(log_address, 1, -4)
459470
total_addresses -= 1
460471

0 commit comments

Comments
 (0)