Skip to content

Commit dad5576

Browse files
committed
Handle no data present in address 0
1 parent e8b30e3 commit dad5576

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
@@ -446,7 +446,6 @@ async def get_missing_energy_logs(self) -> None:
446446
self._mac_in_str,
447447
)
448448
total_addresses = 11
449-
_LOGGER.debug("_last_collected_energy_timestamp: %s", self._last_collected_energy_timestamp)
450449
log_address = self._current_log_address
451450
prev_address_timestamp: datetime | None = None
452451
log_interval = self.energy_consumption_interval
@@ -458,20 +457,25 @@ async def get_missing_energy_logs(self) -> None:
458457
while total_addresses > 0:
459458
await self.energy_log_update(log_address)
460459
# Check if the most recent timestamp of the current address is recent
461-
# (within 2/4 * log_interval plus 5 mins margin)
460+
# (within 2/4 * log_interval plus 5 mins margin), or None
462461
if log_address == self._current_log_address:
463-
if (
464-
self._last_collected_energy_timestamp is not None
465-
and log_interval is not None
462+
if self._last_collected_energy_timestamp is None:
463+
# Handle case with no data in slot 0
464+
_LOGGER.debug(
465+
"Energy data collected from the current log address is None, stopping collection"
466+
)
467+
break
468+
469+
elif (
470+
log_interval is not None
466471
and (
467472
datetime.now(tz=UTC) - self._last_collected_energy_timestamp
468473
).total_seconds() // 60 > (factor * log_interval) + 5 # minutes
469474
):
470-
_LOGGER.debug("Energy data collected is outdated, stopping collection")
475+
_LOGGER.debug(
476+
"Energy data collected from the current log address is outdated, stopping collection"
477+
)
471478
break
472-
473-
"if pulses=None and timestamp == None:"
474-
" break"
475479

476480
# Check if the most recent timestamp of an earlier address is recent
477481
else:
@@ -484,7 +488,7 @@ async def get_missing_energy_logs(self) -> None:
484488
prev_address_timestamp - self._last_collected_energy_timestamp
485489
).total_seconds() // 60 > (factor * log_interval) + 5 # minutes
486490
):
487-
_LOGGER.debug("Energy data collected is outdated, stopping collection")
491+
_LOGGER.debug("Collected energy data is outdated, stopping collection")
488492
break
489493

490494
if self._last_collected_energy_timestamp is not None:

0 commit comments

Comments
 (0)