Skip to content

Commit dd65ed9

Browse files
committed
Implement suggestions
1 parent 25f059f commit dd65ed9

File tree

1 file changed

+16
-18
lines changed

1 file changed

+16
-18
lines changed

plugwise_usb/nodes/circle.py

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -510,28 +510,25 @@ async def get_missing_energy_logs(self) -> None:
510510

511511
async def energy_log_update(self, address: int | None) -> bool:
512512
"""Request energy log statistics from node. Returns true if successful."""
513-
result = False
513+
any_record_stored = False
514514
if address is None:
515-
return result
515+
return False
516516

517517
_LOGGER.debug(
518518
"Requesting EnergyLogs from node %s address %s",
519-
str(address),
520-
self.name,
519+
self._mac_in_str,
520+
address,
521521
)
522522
request = CircleEnergyLogsRequest(self._send, self._mac_in_bytes, address)
523523
if (response := await request.send()) is None:
524524
_LOGGER.debug(
525525
"Retrieving EnergyLogs data from node %s failed",
526526
self._mac_in_str,
527527
)
528-
return result
528+
return False
529529

530-
_LOGGER.debug(
531-
"EnergyLogs data from node %s, address=%s", self._mac_in_str, address
532-
)
530+
_LOGGER.debug("EnergyLogs from node %s, address=%s:", self._mac_in_str, address)
533531
await self._available_update_state(True, response.timestamp)
534-
energy_record_update = False
535532

536533
# Forward historical energy log information to energy counters
537534
# Each response message contains 4 log counters (slots) of the
@@ -557,7 +554,7 @@ async def energy_log_update(self, address: int | None) -> bool:
557554
log_pulses,
558555
import_only=True,
559556
):
560-
energy_record_update = True
557+
any_record_stored = True
561558
if not last_energy_timestamp_collected:
562559
# Collect the timestamp of the most recent response
563560
self._last_collected_energy_timestamp = log_timestamp.replace(
@@ -569,25 +566,26 @@ async def energy_log_update(self, address: int | None) -> bool:
569566
)
570567
last_energy_timestamp_collected = True
571568

572-
result = True
573569
self._energy_counters.update()
574-
if energy_record_update:
570+
if any_record_stored:
575571
_LOGGER.debug(
576572
"Saving energy record update to cache for %s", self._mac_in_str
577573
)
578574
await self.save_cache()
579575

580-
return result
576+
return any_record_stored
581577

582-
def _check_timestamp_is_recent(self, address, slot, timestamp) -> bool:
578+
def _check_timestamp_is_recent(
579+
self, address: int, slot: int, timestamp: datetime
580+
) -> bool:
583581
"""Check if the timestamp of the received log-record is recent.
584582
585583
A timestamp from within the last 24 hours is considered recent.
586584
"""
587-
if (
588-
(datetime.now(tz=UTC) - timestamp.replace(tzinfo=UTC)).total_seconds()
589-
// 3600
590-
) > DAY_IN_HOURS:
585+
age_seconds = (
586+
datetime.now(tz=UTC) - timestamp.replace(tzinfo=UTC)
587+
).total_seconds()
588+
if age_seconds > DAY_IN_HOURS * 3600:
591589
_LOGGER.warning(
592590
"EnergyLog from Node %s | address %s | slot %s | timestamp %s is outdated, ignoring...",
593591
self._mac_in_str,

0 commit comments

Comments
 (0)