Skip to content

Commit c6b2031

Browse files
committed
Change logic: collect energy_logs for address 0 first, then check if earlier address contains outdated data
1 parent ddc6c90 commit c6b2031

File tree

1 file changed

+8
-19
lines changed

1 file changed

+8
-19
lines changed

plugwise_usb/nodes/circle.py

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -450,16 +450,8 @@ async def get_missing_energy_logs(self) -> None:
450450
total_addresses = 11
451451
log_address = self._current_log_address
452452
prev_address_timestamp: datetime | None = None
453-
log_interval = self.energy_consumption_interval
454-
_LOGGER.debug("log_interval: %s", log_interval)
455-
factor = 4
456-
if self.energy_production_interval is not None:
457-
factor = 2
458-
459453
while total_addresses > 0:
460454
await self.energy_log_update(log_address)
461-
# Check if the most recent timestamp of the current address is recent
462-
# (within 2/4 * log_interval plus 5 mins margin), or None
463455
if log_address == self._current_log_address:
464456
if self._last_collected_energy_timestamp is None:
465457
# Handle case with no data in slot 0
@@ -468,19 +460,16 @@ async def get_missing_energy_logs(self) -> None:
468460
)
469461
break
470462

471-
elif (
472-
log_interval is not None
473-
and (
474-
datetime.now(tz=UTC) - self._last_collected_energy_timestamp
475-
).total_seconds() // 60 > (factor * log_interval) + 5 # minutes
476-
):
477-
_LOGGER.debug(
478-
"Energy data collected from the current log address is outdated, stopping collection"
479-
)
480-
break
481-
482463
# Check if the most recent timestamp of an earlier address is recent
464+
# (within 2/4 * log_interval plus 5 mins margin)
483465
else:
466+
log_interval = self.energy_consumption_interval
467+
_LOGGER.debug("log_interval: %s", log_interval)
468+
_LOGGER.debug("energy_production_interval: %s", self.energy_production_interval)
469+
factor = 4
470+
if self.energy_production_interval is not None:
471+
factor = 2
472+
484473
_LOGGER.debug("prev_address_timestamp: %s", prev_address_timestamp)
485474
if (
486475
self._last_collected_energy_timestamp is not None

0 commit comments

Comments
 (0)