From e29c3dddcb419774587e5c3cff31043481a9bb6e Mon Sep 17 00:00:00 2001 From: puddly <32534428+puddly@users.noreply.github.com> Date: Wed, 22 Jan 2025 16:06:21 -0500 Subject: [PATCH] Use the simplified interface --- zigpy_cli/radio.py | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/zigpy_cli/radio.py b/zigpy_cli/radio.py index 64ba107..3f47093 100644 --- a/zigpy_cli/radio.py +++ b/zigpy_cli/radio.py @@ -261,7 +261,7 @@ async def packet_capture( def channels_iter_func(): while True: - yield random.choice(channels) + yield random.choice(tuple(channels)) channels_iter = channels_iter_func() @@ -270,23 +270,24 @@ def channels_iter_func(): await app.connect() - async with app.packet_capture(channel=next(channels_iter)) as capture: - async with asyncio.TaskGroup() as tg: + writer = PcapWriter(output) + writer.write_header() - async def channel_hopper(): - for channel in channels_iter: - await asyncio.sleep(channel_hop_period) - LOGGER.debug("Changing channel to %s", channel) - await capture.change_channel(channel) + async with asyncio.TaskGroup() as tg: + channel_hopper_task = None - tg.create_task(channel_hopper()) + async def channel_hopper(): + for channel in channels_iter: + await asyncio.sleep(channel_hop_period) + LOGGER.debug("Changing channel to %s", channel) + await app.packet_capture_change_channel(channel) - writer = PcapWriter(output) - writer.write_header() + async for packet in app.packet_capture(channel=next(channels_iter)): + if channel_hopper_task is None: + channel_hopper_task = tg.create_task(channel_hopper()) - async for packet in capture: - LOGGER.debug("Got a packet %s", packet) - writer.write_packet(packet) + LOGGER.debug("Got a packet %s", packet) + writer.write_packet(packet) - if output.name == "": # Surely there's a better way? - output.flush() + if output.name == "": # Surely there's a better way? + output.flush()