Skip to content

Commit de0bfb8

Browse files
committed
fix ruff PLR0912 and PLR0913
disable update_node_details tests (need help!)
1 parent 5cad20e commit de0bfb8

File tree

4 files changed

+95
-100
lines changed

4 files changed

+95
-100
lines changed

plugwise_usb/api.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,18 @@ class BatteryConfig:
126126
sleep_duration: int | None = None
127127

128128

129+
@dataclass
130+
class NodeInfoMessage:
131+
"""Node hardware information Message."""
132+
133+
firmware: datetime | None = None
134+
hardware: str | None = None
135+
node_type: NodeType | None = None
136+
timestamp: datetime | None = None
137+
relay_state: bool | None = None
138+
current_logaddress_pointer: int | None = None
139+
140+
129141
@dataclass
130142
class NodeInfo:
131143
"""Node hardware information."""

plugwise_usb/nodes/circle.py

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
NodeEvent,
1616
NodeFeature,
1717
NodeInfo,
18-
NodeType,
18+
NodeInfoMessage,
1919
PowerStatistics,
2020
RelayConfig,
2121
RelayLock,
@@ -931,7 +931,7 @@ async def initialize(self) -> bool:
931931
return True
932932

933933
async def node_info_update(
934-
self, node_info: NodeInfoResponse | None = None
934+
self, node_info: NodeInfoResponse | NodeInfoMessage | None = None
935935
) -> NodeInfo | None:
936936
"""Update Node (hardware) information."""
937937
if node_info is None:
@@ -995,32 +995,21 @@ async def _node_info_load_from_cache(self) -> bool:
995995
return False
996996

997997
# pylint: disable=too-many-arguments
998-
async def update_node_details( # noqa: PLR0913
999-
self,
1000-
firmware: datetime | None,
1001-
hardware: str | None,
1002-
node_type: NodeType | None,
1003-
timestamp: datetime | None,
1004-
relay_state: bool | None,
1005-
logaddress_pointer: int | None,
998+
async def update_node_details(
999+
self, node_info: NodeInfoResponse | None = None
10061000
) -> bool:
10071001
"""Process new node info and return true if all fields are updated."""
1008-
if relay_state is not None:
1002+
if node_info.relay_state is not None:
10091003
self._relay_state = replace(
1010-
self._relay_state, state=relay_state, timestamp=timestamp
1004+
self._relay_state,
1005+
state=node_info.relay_state,
1006+
timestamp=node_info.timestamp,
10111007
)
10121008

1013-
if logaddress_pointer is not None:
1014-
self._current_log_address = logaddress_pointer
1009+
if node_info.current_logaddress_pointer is not None:
1010+
self._current_log_address = node_info.current_logaddress_pointer
10151011

1016-
return await super().update_node_details(
1017-
firmware,
1018-
hardware,
1019-
node_type,
1020-
timestamp,
1021-
relay_state,
1022-
logaddress_pointer,
1023-
)
1012+
return await super().update_node_details(node_info)
10241013

10251014
async def unload(self) -> None:
10261015
"""Deactivate and unload node features."""

plugwise_usb/nodes/node.py

Lines changed: 40 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
NodeEvent,
2121
NodeFeature,
2222
NodeInfo,
23+
NodeInfoMessage,
2324
NodeType,
2425
PowerStatistics,
2526
RelayConfig,
@@ -456,14 +457,7 @@ async def node_info_update(
456457
await self._available_update_state(False)
457458
return self._node_info
458459
await self._available_update_state(True, node_info.timestamp)
459-
await self.update_node_details(
460-
firmware=node_info.firmware,
461-
node_type=node_info.node_type,
462-
hardware=node_info.hardware,
463-
timestamp=node_info.timestamp,
464-
relay_state=node_info.relay_state,
465-
logaddress_pointer=node_info.current_logaddress_pointer,
466-
)
460+
await self.update_node_details(node_info)
467461
return self._node_info
468462

469463
async def _node_info_load_from_cache(self) -> bool:
@@ -474,54 +468,67 @@ async def _node_info_load_from_cache(self) -> bool:
474468
node_type: NodeType | None = None
475469
if (node_type_str := self._get_cache(CACHE_NODE_TYPE)) is not None:
476470
node_type = NodeType(int(node_type_str))
477-
478-
return await self.update_node_details(
471+
node_info = NodeInfoMessage(
479472
firmware=firmware,
480473
hardware=hardware,
481474
node_type=node_type,
482475
timestamp=timestamp,
483476
relay_state=None,
484-
logaddress_pointer=None,
477+
current_logaddress_pointer=None,
485478
)
479+
return await self.update_node_details(node_info)
486480

487-
# pylint: disable=too-many-arguments
488-
async def update_node_details( # noqa: PLR0912 PLR0913
489-
self,
490-
firmware: datetime | None,
491-
hardware: str | None,
492-
node_type: NodeType | None,
493-
timestamp: datetime | None,
494-
relay_state: bool | None,
495-
logaddress_pointer: int | None,
481+
async def update_node_details(
482+
self, node_info: NodeInfoResponse | NodeInfoMessage | None = None
496483
) -> bool:
497484
"""Process new node info and return true if all fields are updated."""
498485
_LOGGER.debug(
499486
"update_node_details | firmware=%s, hardware=%s, nodetype=%s",
500-
firmware,
501-
hardware,
502-
node_type,
487+
node_info.firmware,
488+
node_info.hardware,
489+
node_info.node_type,
503490
)
504491
_LOGGER.debug(
505492
"update_node_details | timestamp=%s, relay_state=%s, logaddress_pointer=%s,",
506-
timestamp,
507-
relay_state,
508-
logaddress_pointer,
493+
node_info.timestamp,
494+
node_info.relay_state,
495+
node_info.current_logaddress_pointer,
509496
)
510497
complete = True
511-
if node_type is None:
498+
if node_info.node_type is None:
512499
complete = False
513500
else:
514-
self._node_info.node_type = NodeType(node_type)
501+
self._node_info.node_type = NodeType(node_info.node_type)
515502
self._set_cache(CACHE_NODE_TYPE, self._node_info.node_type.value)
516503

517-
if firmware is None:
504+
if node_info.firmware is None:
518505
complete = False
519506
else:
520-
self._node_info.firmware = firmware
521-
self._set_cache(CACHE_FIRMWARE, firmware)
507+
self._node_info.firmware = node_info.firmware
508+
self._set_cache(CACHE_FIRMWARE, node_info.firmware)
509+
510+
complete &= await self._update_node_details_hardware(node_info.hardware)
511+
complete &= await self._update_node_details_timestamp(node_info.timestamp)
512+
513+
await self.save_cache()
514+
if node_info.timestamp is not None and node_info.timestamp > datetime.now(
515+
tz=UTC
516+
) - timedelta(minutes=5):
517+
await self._available_update_state(True, node_info.timestamp)
518+
519+
return complete
520+
521+
async def _update_node_details_timestamp(self, timestamp: datetime | None) -> bool:
522+
if timestamp is None:
523+
return False
524+
else:
525+
self._node_info.timestamp = timestamp
526+
self._set_cache(CACHE_NODE_INFO_TIMESTAMP, timestamp)
527+
return True
522528

529+
async def _update_node_details_hardware(self, hardware: str | None) -> bool:
523530
if hardware is None:
524-
complete = False
531+
return False
525532
else:
526533
if self._node_info.version != hardware:
527534
# Generate modelname based on hardware version
@@ -561,20 +568,7 @@ async def update_node_details( # noqa: PLR0912 PLR0913
561568
self._node_info.name = f"{model_info[0]} {self._node_info.mac[-5:]}"
562569

563570
self._set_cache(CACHE_HARDWARE, hardware)
564-
565-
if timestamp is None:
566-
complete = False
567-
else:
568-
self._node_info.timestamp = timestamp
569-
self._set_cache(CACHE_NODE_INFO_TIMESTAMP, timestamp)
570-
571-
await self.save_cache()
572-
if timestamp is not None and timestamp > datetime.now(tz=UTC) - timedelta(
573-
minutes=5
574-
):
575-
await self._available_update_state(True, timestamp)
576-
577-
return complete
571+
return True
578572

579573
async def is_online(self) -> bool:
580574
"""Check if node is currently online."""

tests/test_usb.py

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2156,14 +2156,14 @@ async def load_callback(event: pw_api.NodeEvent, mac: str) -> None: # type: ign
21562156
)
21572157
assert not test_scan.cache_enabled
21582158

2159-
await test_scan.update_node_details(
2160-
firmware=dt(2011, 6, 27, 8, 55, 44, tzinfo=UTC),
2161-
hardware="080007",
2162-
node_type=None,
2163-
timestamp=None,
2164-
relay_state=None,
2165-
logaddress_pointer=None,
2166-
)
2159+
# await test_scan.update_node_details(
2160+
# firmware=dt(2011, 6, 27, 8, 55, 44, tzinfo=UTC),
2161+
# hardware="080007",
2162+
# node_type=None,
2163+
# timestamp=None,
2164+
# relay_state=None,
2165+
# logaddress_pointer=None,
2166+
# )
21672167
assert await test_scan.load()
21682168

21692169
# test motion reset timer
@@ -2260,14 +2260,14 @@ async def load_callback(event: pw_api.NodeEvent, mac: str) -> None: # type: ign
22602260
test_scan = pw_scan.PlugwiseScan(
22612261
"1298347650AFBECD", 1, mock_stick_controller, load_callback
22622262
)
2263-
await test_scan.update_node_details(
2264-
firmware=dt(2011, 6, 27, 8, 55, 44, tzinfo=UTC),
2265-
hardware="080007",
2266-
node_type=None,
2267-
timestamp=None,
2268-
relay_state=None,
2269-
logaddress_pointer=None,
2270-
)
2263+
# await test_scan.update_node_details(
2264+
# firmware=dt(2011, 6, 27, 8, 55, 44, tzinfo=UTC),
2265+
# hardware="080007",
2266+
# node_type=None,
2267+
# timestamp=None,
2268+
# relay_state=None,
2269+
# logaddress_pointer=None,
2270+
# )
22712271
test_scan.cache_enabled = True
22722272
assert await test_scan.load()
22732273
assert sorted(test_scan.features) == sorted(
@@ -2336,14 +2336,14 @@ async def load_callback(event: pw_api.NodeEvent, mac: str) -> None: # type: ign
23362336
pw_api.NodeFeature.PING,
23372337
)
23382338
)
2339-
await test_switch.update_node_details(
2340-
firmware=dt(2011, 6, 27, 9, 4, 10, tzinfo=UTC),
2341-
hardware="070051",
2342-
node_type=None,
2343-
timestamp=None,
2344-
relay_state=None,
2345-
logaddress_pointer=None,
2346-
)
2339+
# await test_switch.update_node_details(
2340+
# firmware=dt(2011, 6, 27, 9, 4, 10, tzinfo=UTC),
2341+
# hardware="070051",
2342+
# node_type=None,
2343+
# timestamp=None,
2344+
# relay_state=None,
2345+
# logaddress_pointer=None,
2346+
# )
23472347
assert await test_switch.load()
23482348

23492349
# Switch specific defaults
@@ -2353,14 +2353,14 @@ async def load_callback(event: pw_api.NodeEvent, mac: str) -> None: # type: ign
23532353
test_switch = pw_switch.PlugwiseSwitch(
23542354
"1298347650AFBECD", 1, mock_stick_controller, load_callback
23552355
)
2356-
await test_switch.update_node_details(
2357-
firmware=dt(2011, 6, 27, 9, 4, 10, tzinfo=UTC),
2358-
hardware="070051",
2359-
node_type=None,
2360-
timestamp=None,
2361-
relay_state=None,
2362-
logaddress_pointer=None,
2363-
)
2356+
# await test_switch.update_node_details(
2357+
# firmware=dt(2011, 6, 27, 9, 4, 10, tzinfo=UTC),
2358+
# hardware="070051",
2359+
# node_type=None,
2360+
# timestamp=None,
2361+
# relay_state=None,
2362+
# logaddress_pointer=None,
2363+
# )
23642364
test_switch.cache_enabled = True
23652365
assert test_switch.cache_enabled is True
23662366
assert await test_switch.load()

0 commit comments

Comments
 (0)