Skip to content

Commit 1cf6289

Browse files
committed
Only request backlog for last 48 hours
Instead of steadily asking 13 addresses, only ask for the last 48 hours.
1 parent b3702b9 commit 1cf6289

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

plugwise_usb/nodes/circle.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Plugwise Circle node object."""
22
from datetime import datetime, timedelta
33
import logging
4+
import math
45

56
from ..constants import (
67
FEATURE_ENERGY_CONSUMPTION_TODAY,
@@ -681,7 +682,16 @@ def request_energy_counters(self, log_address=None, callback=None):
681682
# TODO: validate range of log_addresses
682683
self._energy_history_collecting = True
683684
self._energy_history_collecting_timestamp = datetime.now()
684-
for req_log_address in range(log_address - 13, log_address):
685+
_log_delta = datetime.utcnow().replace(
686+
minute=0, second=0, microsecond=0
687+
) - (
688+
_yesterday_timestamp = datetime.utcnow().replace(
689+
hour=0, minute=0, second=0, microsecond=0
690+
) - timedelta(days=1)
691+
)
692+
_log_count = math.ceil(_log_delta.total_seconds()/60/60/4)
693+
694+
for req_log_address in range(log_address - _log_count, log_address):
685695
if self._energy_memory.get(req_log_address, 0) < 4:
686696
self.message_sender(
687697
CircleEnergyCountersRequest(self._mac, req_log_address),

0 commit comments

Comments
 (0)