Skip to content

Commit e8b30e3

Browse files
committed
Start adding coverage for None-data in address 0
1 parent 2b2c0e2 commit e8b30e3

File tree

1 file changed

+27
-21
lines changed

1 file changed

+27
-21
lines changed

plugwise_usb/nodes/circle.py

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -446,9 +446,11 @@ 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)
449450
log_address = self._current_log_address
450451
prev_address_timestamp: datetime | None = None
451452
log_interval = self.energy_consumption_interval
453+
_LOGGER.debug("log_interval: %s", log_interval)
452454
factor = 4
453455
if self.energy_production_interval is not None:
454456
factor = 2
@@ -457,29 +459,33 @@ async def get_missing_energy_logs(self) -> None:
457459
await self.energy_log_update(log_address)
458460
# Check if the most recent timestamp of the current address is recent
459461
# (within 2/4 * log_interval plus 5 mins margin)
460-
if (
461-
log_address == self._current_log_address
462-
and self._last_collected_energy_timestamp is not None
463-
and log_interval is not None
464-
and (
465-
datetime.now(tz=UTC) - self._last_collected_energy_timestamp
466-
).total_seconds() // 60 > (factor * log_interval) + 5 # minutes
467-
):
468-
_LOGGER.debug("Energy data collected is outdated, stopping collection")
469-
break
462+
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
466+
and (
467+
datetime.now(tz=UTC) - self._last_collected_energy_timestamp
468+
).total_seconds() // 60 > (factor * log_interval) + 5 # minutes
469+
):
470+
_LOGGER.debug("Energy data collected is outdated, stopping collection")
471+
break
472+
473+
"if pulses=None and timestamp == None:"
474+
" break"
470475

471476
# Check if the most recent timestamp of an earlier address is recent
472-
if (
473-
log_address != self._current_log_address
474-
and self._last_collected_energy_timestamp is not None
475-
and log_interval is not None
476-
and prev_address_timestamp is not None
477-
and (
478-
prev_address_timestamp - self._last_collected_energy_timestamp
479-
).total_seconds() // 60 > (factor * log_interval) + 5 # minutes
480-
):
481-
_LOGGER.debug("Energy data collected is outdated, stopping collection")
482-
break
477+
else:
478+
_LOGGER.debug("prev_address_timestamp: %s", prev_address_timestamp)
479+
if (
480+
self._last_collected_energy_timestamp is not None
481+
and log_interval is not None
482+
and prev_address_timestamp is not None
483+
and (
484+
prev_address_timestamp - self._last_collected_energy_timestamp
485+
).total_seconds() // 60 > (factor * log_interval) + 5 # minutes
486+
):
487+
_LOGGER.debug("Energy data collected is outdated, stopping collection")
488+
break
483489

484490
if self._last_collected_energy_timestamp is not None:
485491
prev_address_timestamp = self._last_collected_energy_timestamp

0 commit comments

Comments
 (0)