Skip to content

Commit 6f305dd

Browse files
committed
_missing_addresses_after(): further complexity reduction
1 parent 069a9fd commit 6f305dd

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

plugwise_usb/nodes/helpers/pulses.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@ def calc_log_address(address: int, slot: int, offset: int) -> tuple[int, int]:
3636
offset -= 4
3737
return (address, slot + offset)
3838

39+
def update_addresses(address: int, addresses: list[int]) -> list[int]:
40+
"""Helper for _missing_addresses_after()."""
41+
if address not in addresses:
42+
addresses.append(address)
43+
44+
return addresses
45+
3946

4047
@dataclass
4148
class PulseLogRecord:
@@ -993,15 +1000,13 @@ def get_interval(config_value, default_hours):
9931000
if not self._log_production:
9941001
# Only consumption interval is considered
9951002
while timestamp_cons < target:
996-
if address not in addresses:
997-
addresses.append(address)
1003+
addresses = update_addresses(address, addresses)
9981004
timestamp_cons += timedelta(hours=1) # Always increment by 1 hour here
9991005
address, slot = calc_log_address(address, slot, 1)
10001006
else:
10011007
# Consider both consumption and production timestamps
10021008
while timestamp_cons < target or timestamp_prod < target:
1003-
if address not in addresses:
1004-
addresses.append(address)
1009+
addresses = update_addresses(address, addresses)
10051010
if timestamp_prod < timestamp_cons:
10061011
timestamp_prod += interval_prod
10071012
else:

0 commit comments

Comments
 (0)