Skip to content

Commit 3d81c71

Browse files
author
autoruff
committed
fixup: pair-plus Python code fixed using Ruff
1 parent 00d9735 commit 3d81c71

File tree

2 files changed

+94
-91
lines changed

2 files changed

+94
-91
lines changed

plugwise_usb/messages/requests.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,9 @@ async def send(self) -> StickInitResponse | StickInitShortResponse | None:
534534
if self._send_fn is None:
535535
raise MessageError("Send function missing")
536536
result = await self._send_request()
537-
if isinstance(result, StickInitResponse) or isinstance(result, StickInitShortResponse):
537+
if isinstance(result, StickInitResponse) or isinstance(
538+
result, StickInitShortResponse
539+
):
538540
return result
539541
if result is None:
540542
return None

tests/test_pairing.py

Lines changed: 91 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -300,65 +300,65 @@ async def dummy_fn(self, request: pw_requests.PlugwiseRequest, test: bool) -> No
300300
"""Callable dummy routine."""
301301
return
302302

303-
# @pytest.mark.asyncio
304-
# async def test_stick_connect(self, monkeypatch: pytest.MonkeyPatch) -> None:
305-
# """Test connecting to stick."""
306-
# monkeypatch.setattr(
307-
# pw_connection_manager,
308-
# "create_serial_connection",
309-
# MockSerial(None).mock_connection,
310-
# )
311-
# stick = pw_stick.Stick(port="test_port", cache_enabled=False)
312-
313-
# unsub_connect = stick.subscribe_to_stick_events(
314-
# stick_event_callback=self.connected,
315-
# events=(pw_api.StickEvent.CONNECTED,),
316-
# )
317-
# self.test_connected = asyncio.Future()
318-
# await stick.connect("test_port")
319-
# assert await self.test_connected
320-
# await stick.initialize()
321-
# assert stick.mac_stick == "0123456789012345"
322-
# assert stick.name == "Stick 12345"
323-
# assert stick.mac_coordinator == "0098765432101234"
324-
# assert stick.firmware == dt(2011, 6, 27, 8, 47, 37, tzinfo=UTC)
325-
# assert stick.hardware == "070085"
326-
# assert not stick.network_discovered
327-
# assert stick.network_state
328-
# assert stick.network_id == 17185
329-
# unsub_connect()
330-
# await stick.disconnect()
331-
# assert not stick.network_state
332-
# with pytest.raises(pw_exceptions.StickError):
333-
# stick.mac_stick
334-
335-
# @pytest.mark.asyncio
336-
# async def test_stick_network_down(self, monkeypatch: pytest.MonkeyPatch) -> None:
337-
# """Testing Stick init without paired Circle."""
338-
# mock_serial = MockSerial(
339-
# {
340-
# b"\x05\x05\x03\x03000AB43C\r\n": (
341-
# "STICK INIT",
342-
# b"000000C1", # Success ack
343-
# b"0011" # response msg_id
344-
# + b"0123456789012345" # stick mac
345-
# + b"00" # unknown1
346-
# + b"00", # network_is_offline
347-
# ),
348-
# }
349-
# )
350-
# monkeypatch.setattr(
351-
# pw_connection_manager,
352-
# "create_serial_connection",
353-
# mock_serial.mock_connection,
354-
# )
355-
# monkeypatch.setattr(pw_sender, "STICK_TIME_OUT", 0.2)
356-
# monkeypatch.setattr(pw_requests, "NODE_TIME_OUT", 1.0)
357-
# stick = pw_stick.Stick(port="test_port", cache_enabled=False)
358-
# await stick.connect()
359-
# with pytest.raises(pw_exceptions.StickError):
360-
# await stick.initialize()
361-
# await stick.disconnect()
303+
# @pytest.mark.asyncio
304+
# async def test_stick_connect(self, monkeypatch: pytest.MonkeyPatch) -> None:
305+
# """Test connecting to stick."""
306+
# monkeypatch.setattr(
307+
# pw_connection_manager,
308+
# "create_serial_connection",
309+
# MockSerial(None).mock_connection,
310+
# )
311+
# stick = pw_stick.Stick(port="test_port", cache_enabled=False)
312+
313+
# unsub_connect = stick.subscribe_to_stick_events(
314+
# stick_event_callback=self.connected,
315+
# events=(pw_api.StickEvent.CONNECTED,),
316+
# )
317+
# self.test_connected = asyncio.Future()
318+
# await stick.connect("test_port")
319+
# assert await self.test_connected
320+
# await stick.initialize()
321+
# assert stick.mac_stick == "0123456789012345"
322+
# assert stick.name == "Stick 12345"
323+
# assert stick.mac_coordinator == "0098765432101234"
324+
# assert stick.firmware == dt(2011, 6, 27, 8, 47, 37, tzinfo=UTC)
325+
# assert stick.hardware == "070085"
326+
# assert not stick.network_discovered
327+
# assert stick.network_state
328+
# assert stick.network_id == 17185
329+
# unsub_connect()
330+
# await stick.disconnect()
331+
# assert not stick.network_state
332+
# with pytest.raises(pw_exceptions.StickError):
333+
# stick.mac_stick
334+
335+
# @pytest.mark.asyncio
336+
# async def test_stick_network_down(self, monkeypatch: pytest.MonkeyPatch) -> None:
337+
# """Testing Stick init without paired Circle."""
338+
# mock_serial = MockSerial(
339+
# {
340+
# b"\x05\x05\x03\x03000AB43C\r\n": (
341+
# "STICK INIT",
342+
# b"000000C1", # Success ack
343+
# b"0011" # response msg_id
344+
# + b"0123456789012345" # stick mac
345+
# + b"00" # unknown1
346+
# + b"00", # network_is_offline
347+
# ),
348+
# }
349+
# )
350+
# monkeypatch.setattr(
351+
# pw_connection_manager,
352+
# "create_serial_connection",
353+
# mock_serial.mock_connection,
354+
# )
355+
# monkeypatch.setattr(pw_sender, "STICK_TIME_OUT", 0.2)
356+
# monkeypatch.setattr(pw_requests, "NODE_TIME_OUT", 1.0)
357+
# stick = pw_stick.Stick(port="test_port", cache_enabled=False)
358+
# await stick.connect()
359+
# with pytest.raises(pw_exceptions.StickError):
360+
# await stick.initialize()
361+
# await stick.disconnect()
362362

363363
@pytest.mark.asyncio
364364
async def test_pair_plus(self, monkeypatch: pytest.MonkeyPatch) -> None:
@@ -375,13 +375,14 @@ async def test_pair_plus(self, monkeypatch: pytest.MonkeyPatch) -> None:
375375
await stick.connect("test_port")
376376
with pytest.raises(pw_exceptions.StickError):
377377
await stick.initialize()
378-
378+
379379
await asyncio.sleep(5)
380380
await stick.plus_pair_request("0123456789012345")
381381
await asyncio.sleep(5)
382382

383383
await stick.disconnect()
384384

385+
385386
# async def node_join(self, event: pw_api.NodeEvent, mac: str) -> None: # type: ignore[name-defined]
386387
# """Handle join event callback."""
387388
# if event == pw_api.NodeEvent.JOIN:
@@ -393,33 +394,33 @@ async def test_pair_plus(self, monkeypatch: pytest.MonkeyPatch) -> None:
393394
# )
394395
# )
395396

396-
# @pytest.mark.asyncio
397-
# async def test_stick_node_join_subscription(
398-
# self, monkeypatch: pytest.MonkeyPatch
399-
# ) -> None:
400-
# """Testing "new_node" subscription."""
401-
# mock_serial = MockSerial(None)
402-
# monkeypatch.setattr(
403-
# pw_connection_manager,
404-
# "create_serial_connection",
405-
# mock_serial.mock_connection,
406-
# )
407-
# monkeypatch.setattr(pw_sender, "STICK_TIME_OUT", 0.1)
408-
# monkeypatch.setattr(pw_requests, "NODE_TIME_OUT", 0.5)
409-
# stick = pw_stick.Stick("test_port", cache_enabled=False)
410-
# await stick.connect()
411-
# await stick.initialize()
412-
# await stick.discover_nodes(load=False)
413-
414-
# self.test_node_join = asyncio.Future()
415-
# unusb_join = stick.subscribe_to_node_events(
416-
# node_event_callback=self.node_join,
417-
# events=(pw_api.NodeEvent.JOIN,),
418-
# )
419-
420-
## Inject NodeJoinAvailableResponse
421-
# mock_serial.inject_message(b"00069999999999999999", b"1253") # @bouwew: seq_id is not FFFC!
422-
# mac_join_node = await self.test_node_join
423-
# assert mac_join_node == "9999999999999999"
424-
# unusb_join()
425-
# await stick.disconnect()
397+
# @pytest.mark.asyncio
398+
# async def test_stick_node_join_subscription(
399+
# self, monkeypatch: pytest.MonkeyPatch
400+
# ) -> None:
401+
# """Testing "new_node" subscription."""
402+
# mock_serial = MockSerial(None)
403+
# monkeypatch.setattr(
404+
# pw_connection_manager,
405+
# "create_serial_connection",
406+
# mock_serial.mock_connection,
407+
# )
408+
# monkeypatch.setattr(pw_sender, "STICK_TIME_OUT", 0.1)
409+
# monkeypatch.setattr(pw_requests, "NODE_TIME_OUT", 0.5)
410+
# stick = pw_stick.Stick("test_port", cache_enabled=False)
411+
# await stick.connect()
412+
# await stick.initialize()
413+
# await stick.discover_nodes(load=False)
414+
415+
# self.test_node_join = asyncio.Future()
416+
# unusb_join = stick.subscribe_to_node_events(
417+
# node_event_callback=self.node_join,
418+
# events=(pw_api.NodeEvent.JOIN,),
419+
# )
420+
421+
## Inject NodeJoinAvailableResponse
422+
# mock_serial.inject_message(b"00069999999999999999", b"1253") # @bouwew: seq_id is not FFFC!
423+
# mac_join_node = await self.test_node_join
424+
# assert mac_join_node == "9999999999999999"
425+
# unusb_join()
426+
# await stick.disconnect()

0 commit comments

Comments
 (0)