Skip to content

Commit 16e7871

Browse files
committed
Address @bouwew comments
Address sonarqubecloud comments
1 parent c8965f4 commit 16e7871

File tree

6 files changed

+16
-16
lines changed

6 files changed

+16
-16
lines changed

plugwise_usb/network/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ async def _discover_stragglers(self) -> None:
434434
"""Repeat Discovery of Nodes with unknown NodeType."""
435435
while len(self._registry_stragglers) > 0:
436436
await sleep(NODE_RETRY_DISCOVER_INTERVAL)
437-
for mac in list(self._registry_stragglers):
437+
for mac in self._registry_stragglers.copy():
438438
if await self._discover_node(mac, None):
439439
self._registry_stragglers.remove(mac)
440440
_LOGGER.debug(

plugwise_usb/network/cache.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,11 @@ def get_nodetype(self, mac: str) -> NodeType | None:
8080

8181
async def prune_cache(self, registry: list[str]) -> None:
8282
"""Remove items from cache which are not found in registry scan."""
83-
_new_nodetypes: dict[str, NodeType] = {}
83+
new_nodetypes: dict[str, NodeType] = {}
8484
for mac in registry:
8585
if mac == "":
8686
continue
8787
if (node_type := self.get_nodetype(mac)) is not None:
88-
_new_nodetypes[mac] = node_type
89-
self._nodetypes = _new_nodetypes
88+
new_nodetypes[mac] = node_type
89+
self._nodetypes = new_nodetypes
9090
await self.save_cache()

plugwise_usb/network/registry.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ def network_controller(self) -> tuple[str, NodeType | None]:
163163
return self.registry[-1]
164164

165165
async def update_network_nodetype(self, mac: str, node_type: NodeType) -> None:
166-
"""Update NodeType Inside Registry and Cache."""
166+
"""Update NodeType inside registry and cache."""
167167
if self._network_cache is None or mac == "":
168168
return
169169
await self._network_cache.update_nodetypes(mac, node_type)
@@ -228,7 +228,7 @@ async def load_registrations_from_cache(self) -> None:
228228
if self._scan_completed_callback is not None:
229229
await self._scan_completed_callback()
230230

231-
async def update_node_registration(self, mac: str) -> bool:
231+
def update_node_registration(self, mac: str) -> bool:
232232
"""Register (re)joined node to Plugwise network and return network address."""
233233
return self.update_network_registration(mac)
234234

plugwise_usb/nodes/scan.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,9 @@ async def _load_defaults(self) -> None:
147147

148148
async def _load_from_cache(self) -> bool:
149149
"""Load states from previous cached information. Returns True if successful."""
150-
LoadSuccess = True
150+
super_load_success = True
151151
if not await super()._load_from_cache():
152-
LoadSuccess = False
152+
super_load_success = False
153153
self._motion_state = MotionState(
154154
state=self._motion_from_cache(),
155155
timestamp=self._motion_timestamp_from_cache(),
@@ -174,7 +174,7 @@ async def _load_from_cache(self) -> bool:
174174
)
175175
if dirty:
176176
await self._scan_configure_update()
177-
return LoadSuccess
177+
return super_load_success
178178

179179
def _daylight_mode_from_cache(self) -> bool | None:
180180
"""Load awake duration from cache."""

plugwise_usb/nodes/sed.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,9 @@ async def _load_defaults(self) -> None:
142142

143143
async def _load_from_cache(self) -> bool:
144144
"""Load states from previous cached information. Returns True if successful."""
145-
LoadSuccess = True
145+
super_load_success = True
146146
if not await super()._load_from_cache():
147-
LoadSuccess = False
147+
super_load_success = False
148148
dirty = False
149149
if (awake_duration := self._awake_duration_from_cache()) is None:
150150
dirty = True
@@ -174,7 +174,7 @@ async def _load_from_cache(self) -> bool:
174174
await self._sed_configure_update()
175175
self._awake_timestamp_from_cache()
176176
self._awake_reason_from_cache()
177-
return LoadSuccess
177+
return super_load_success
178178

179179
def _awake_duration_from_cache(self) -> int | None:
180180
"""Load awake duration from cache."""

tests/test_usb.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1910,7 +1910,7 @@ async def load_callback(event: pw_api.NodeEvent, mac: str) -> None: # type: ign
19101910
async def test_sed_node(self, monkeypatch: pytest.MonkeyPatch) -> None: # noqa: PLR0915
19111911
"""Testing properties of SED."""
19121912

1913-
def fake_cache(dummy: object, setting: str) -> str | None: # noqa: PLR0911
1913+
def fake_cache(dummy: object, setting: str) -> str | bool | None: # noqa: PLR0911
19141914
"""Fake cache retrieval."""
19151915
if setting == pw_node.CACHE_FIRMWARE:
19161916
return "2011-6-27-8-55-44"
@@ -2106,7 +2106,7 @@ async def load_callback(event: pw_api.NodeEvent, mac: str) -> None: # type: ign
21062106
async def test_scan_node(self, monkeypatch: pytest.MonkeyPatch) -> None: # noqa: PLR0915
21072107
"""Testing properties of scan."""
21082108

2109-
def fake_cache(dummy: object, setting: str) -> str | None: # noqa: PLR0911 PLR0912
2109+
def fake_cache(dummy: object, setting: str) -> str | bool | None: # noqa: PLR0911 PLR0912
21102110
"""Fake cache retrieval."""
21112111
if setting == pw_node.CACHE_FIRMWARE:
21122112
return "2011-6-27-8-55-44"
@@ -2308,7 +2308,7 @@ async def load_callback(event: pw_api.NodeEvent, mac: str) -> None: # type: ign
23082308
async def test_switch_node(self, monkeypatch: pytest.MonkeyPatch) -> None:
23092309
"""Testing properties of switch."""
23102310

2311-
def fake_cache(dummy: object, setting: str) -> str | None: # noqa: PLR0911
2311+
def fake_cache(dummy: object, setting: str) -> str | bool | None: # noqa: PLR0911
23122312
"""Fake cache retrieval."""
23132313
if setting == pw_node.CACHE_FIRMWARE:
23142314
return "2011-5-13-7-26-54"
@@ -2411,7 +2411,7 @@ async def test_node_discovery_and_load( # noqa: PLR0915
24112411
) -> None:
24122412
"""Testing discovery of nodes."""
24132413

2414-
def fake_cache(dummy: object, setting: str) -> str | None: # noqa: PLR0911
2414+
def fake_cache(dummy: object, setting: str) -> str | bool | None: # noqa: PLR0911
24152415
"""Fake cache retrieval."""
24162416
if setting == pw_node.CACHE_FIRMWARE:
24172417
return "2011-5-13-7-26-54"

0 commit comments

Comments
 (0)