Skip to content

Commit 24d2f73

Browse files
committed
Handle no data present in address 0
1 parent ced369c commit 24d2f73

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

plugwise_usb/nodes/circle.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,6 @@ async def get_missing_energy_logs(self) -> None:
448448
self._mac_in_str,
449449
)
450450
total_addresses = 11
451-
_LOGGER.debug("_last_collected_energy_timestamp: %s", self._last_collected_energy_timestamp)
452451
log_address = self._current_log_address
453452
prev_address_timestamp: datetime | None = None
454453
log_interval = self.energy_consumption_interval
@@ -460,20 +459,25 @@ async def get_missing_energy_logs(self) -> None:
460459
while total_addresses > 0:
461460
await self.energy_log_update(log_address)
462461
# Check if the most recent timestamp of the current address is recent
463-
# (within 2/4 * log_interval plus 5 mins margin)
462+
# (within 2/4 * log_interval plus 5 mins margin), or None
464463
if log_address == self._current_log_address:
465-
if (
466-
self._last_collected_energy_timestamp is not None
467-
and log_interval is not None
464+
if self._last_collected_energy_timestamp is None:
465+
# Handle case with no data in slot 0
466+
_LOGGER.debug(
467+
"Energy data collected from the current log address is None, stopping collection"
468+
)
469+
break
470+
471+
elif (
472+
log_interval is not None
468473
and (
469474
datetime.now(tz=UTC) - self._last_collected_energy_timestamp
470475
).total_seconds() // 60 > (factor * log_interval) + 5 # minutes
471476
):
472-
_LOGGER.debug("Energy data collected is outdated, stopping collection")
477+
_LOGGER.debug(
478+
"Energy data collected from the current log address is outdated, stopping collection"
479+
)
473480
break
474-
475-
"if pulses=None and timestamp == None:"
476-
" break"
477481

478482
# Check if the most recent timestamp of an earlier address is recent
479483
else:
@@ -486,7 +490,7 @@ async def get_missing_energy_logs(self) -> None:
486490
prev_address_timestamp - self._last_collected_energy_timestamp
487491
).total_seconds() // 60 > (factor * log_interval) + 5 # minutes
488492
):
489-
_LOGGER.debug("Energy data collected is outdated, stopping collection")
493+
_LOGGER.debug("Collected energy data is outdated, stopping collection")
490494
break
491495

492496
if self._last_collected_energy_timestamp is not None:

0 commit comments

Comments
 (0)