22
33import asyncio
44from collections .abc import Callable , Coroutine
5- from datetime import UTC , datetime as dt , timedelta as td
65import importlib
76import logging
87import random
98from typing import Any
10- from unittest .mock import MagicMock , Mock , patch
9+ from unittest .mock import MagicMock
1110
1211import pytest
1312
1413import aiofiles # type: ignore[import-untyped]
1514import crcmod
16- from freezegun import freeze_time
1715
1816crc_fun = crcmod .mkCrcFun (0x11021 , rev = False , initCrc = 0x0000 , xorOut = 0x0000 )
1917
@@ -350,7 +348,7 @@ async def send(
350348
351349
352350aiofiles .threadpool .wrap .register (MagicMock )(
353- lambda * args , ** kwargs : aiofiles .threadpool .AsyncBufferedIOBase (* args , ** kwargs ) # pylint: disable=unnecessary-lambda
351+ lambda * args , ** kwargs : aiofiles .threadpool .AsyncBufferedIOBase (* args , ** kwargs ) # noqa: PLW0108 pylint: disable=unnecessary-lambda
354352)
355353
356354
@@ -380,66 +378,6 @@ async def dummy_fn(self, request: pw_requests.PlugwiseRequest, test: bool) -> No
380378 """Callable dummy routine."""
381379 return
382380
383- # @pytest.mark.asyncio
384- # async def test_stick_connect(self, monkeypatch: pytest.MonkeyPatch) -> None:
385- # """Test connecting to stick."""
386- # monkeypatch.setattr(
387- # pw_connection_manager,
388- # "create_serial_connection",
389- # MockSerial(None).mock_connection,
390- # )
391- # stick = pw_stick.Stick(port="test_port", cache_enabled=False)
392-
393- # unsub_connect = stick.subscribe_to_stick_events(
394- # stick_event_callback=self.connected,
395- # events=(pw_api.StickEvent.CONNECTED,),
396- # )
397- # self.test_connected = asyncio.Future()
398- # await stick.connect("test_port")
399- # assert await self.test_connected
400- # await stick.initialize()
401- # assert stick.mac_stick == "0123456789012345"
402- # assert stick.name == "Stick 12345"
403- # assert stick.mac_coordinator == "0098765432101234"
404- # assert stick.firmware == dt(2011, 6, 27, 8, 47, 37, tzinfo=UTC)
405- # assert stick.hardware == "070085"
406- # assert not stick.network_discovered
407- # assert stick.network_state
408- # assert stick.network_id == 17185
409- # unsub_connect()
410- # await stick.disconnect()
411- # assert not stick.network_state
412- # with pytest.raises(pw_exceptions.StickError):
413- # stick.mac_stick
414-
415- # @pytest.mark.asyncio
416- # async def test_stick_network_down(self, monkeypatch: pytest.MonkeyPatch) -> None:
417- # """Testing Stick init without paired Circle."""
418- # mock_serial = MockSerial(
419- # {
420- # b"\x05\x05\x03\x03000AB43C\r\n": (
421- # "STICK INIT",
422- # b"000000C1", # Success ack
423- # b"0011" # response msg_id
424- # + b"0123456789012345" # stick mac
425- # + b"00" # unknown1
426- # + b"00", # network_is_offline
427- # ),
428- # }
429- # )
430- # monkeypatch.setattr(
431- # pw_connection_manager,
432- # "create_serial_connection",
433- # mock_serial.mock_connection,
434- # )
435- # monkeypatch.setattr(pw_sender, "STICK_TIME_OUT", 0.2)
436- # monkeypatch.setattr(pw_requests, "NODE_TIME_OUT", 1.0)
437- # stick = pw_stick.Stick(port="test_port", cache_enabled=False)
438- # await stick.connect()
439- # with pytest.raises(pw_exceptions.StickError):
440- # await stick.initialize()
441- # await stick.disconnect()
442-
443381 @pytest .mark .asyncio
444382 async def test_pair_plus (self , monkeypatch : pytest .MonkeyPatch ) -> None :
445383 """Test pairing a plus-device."""
@@ -453,54 +391,10 @@ async def test_pair_plus(self, monkeypatch: pytest.MonkeyPatch) -> None:
453391 monkeypatch .setattr (pw_requests , "NODE_TIME_OUT" , 0.5 )
454392 stick = pw_stick .Stick (port = "test_port" , cache_enabled = False )
455393 await stick .connect ("test_port" )
456- # with pytest.raises(pw_exceptions.StickError):
457394 await stick .initialize ()
458395
459396 await asyncio .sleep (0.2 )
460397 await stick .plus_pair_request ("0098765432101234" )
461398 await asyncio .sleep (0.2 )
462399
463400 await stick .disconnect ()
464-
465-
466- # async def node_join(self, event: pw_api.NodeEvent, mac: str) -> None: # type: ignore[name-defined]
467- # """Handle join event callback."""
468- # if event == pw_api.NodeEvent.JOIN:
469- # self.test_node_join.set_result(mac)
470- # else:
471- # self.test_node_join.set_exception(
472- # BaseException(
473- # f"Invalid {event} event, expected " + f"{pw_api.NodeEvent.JOIN}"
474- # )
475- # )
476-
477- # @pytest.mark.asyncio
478- # async def test_stick_node_join_subscription(
479- # self, monkeypatch: pytest.MonkeyPatch
480- # ) -> None:
481- # """Testing "new_node" subscription."""
482- # mock_serial = MockSerial(None)
483- # monkeypatch.setattr(
484- # pw_connection_manager,
485- # "create_serial_connection",
486- # mock_serial.mock_connection,
487- # )
488- # monkeypatch.setattr(pw_sender, "STICK_TIME_OUT", 0.1)
489- # monkeypatch.setattr(pw_requests, "NODE_TIME_OUT", 0.5)
490- # stick = pw_stick.Stick("test_port", cache_enabled=False)
491- # await stick.connect()
492- # await stick.initialize()
493- # await stick.discover_nodes(load=False)
494-
495- # self.test_node_join = asyncio.Future()
496- # unusb_join = stick.subscribe_to_node_events(
497- # node_event_callback=self.node_join,
498- # events=(pw_api.NodeEvent.JOIN,),
499- # )
500-
501- ## Inject NodeJoinAvailableResponse
502- # mock_serial.inject_message(b"00069999999999999999", b"1253") # @bouwew: seq_id is not FFFC!
503- # mac_join_node = await self.test_node_join
504- # assert mac_join_node == "9999999999999999"
505- # unusb_join()
506- # await stick.disconnect()
0 commit comments