Skip to content

Commit 8be2821

Browse files
committed
Make use of the known energy intervals
1 parent 428b724 commit 8be2821

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

plugwise_usb/nodes/circle.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -449,16 +449,22 @@ async def get_missing_energy_logs(self) -> None:
449449
total_addresses = 11
450450
log_address = self._current_log_address
451451
prev_address_timestamp: datetime | None = None
452+
log_interval = self.energy_consumption_interval
453+
factor = 4
454+
if self.energy_production_interval is not None:
455+
factor = 2
456+
452457
while total_addresses > 0:
453458
await self.energy_log_update(log_address)
454-
# Check if the most recent timestamp of an earlier address is recent (4 * log_interval plus 5 mins margin)
459+
# Check if the most recent timestamp of an earlier address is recent
460+
# (within 2/4 * log_interval plus 5 mins margin)
455461
if (
456462
log_address != self._current_log_address
457463
and self._last_collected_energy_timestamp is not None
458464
and prev_address_timestamp is not None
459465
and (
460466
prev_address_timestamp - self._last_collected_energy_timestamp
461-
).total_seconds() // 60 > (4 * 60) + 5 # minutes
467+
).total_seconds() // 60 > (factor * log_interval) + 5 # minutes
462468
):
463469
_LOGGER.debug("Energy data collected is outdated, stopping collection")
464470
break

0 commit comments

Comments
 (0)