Skip to content

Commit

Permalink
Keep track of the packet capture channel
Browse files Browse the repository at this point in the history
  • Loading branch information
puddly committed Jan 22, 2025
1 parent 59cabcc commit f12472b
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion bellows/zigbee/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ def __init__(self, config: dict):
self._watchdog_feed_counter = 0

self._req_lock = asyncio.Lock()
self._packet_capture_channel: int | None = None

@property
def controller_event(self):
Expand Down Expand Up @@ -753,10 +754,16 @@ async def _network_scan(
rssi=lastHopRssi,
)

def _check_status(self, status: t.sl_Status | t.EmberStatus) -> None:
if t.sl_Status.from_ember_status(status) != t.sl_Status.OK:
raise ControllerError(f"Command failed: {status!r}")

async def _packet_capture(self, channel: int):
try:
(status,) = await self._ezsp.mfglibStart(rxCallback=True)
self._check_status(status)
await self._packet_capture_change_channel(channel=channel)
assert self._packet_capture_channel is not None

queue = asyncio.Queue()

Expand All @@ -774,14 +781,17 @@ async def _packet_capture(self, channel: int):
timestamp=datetime.now(timezone.utc),
rssi=rssi,
lqi=linkQuality,
channel=0, # zigpy will fill it in
channel=self._packet_capture_channel,
data=packetContents,
)
finally:
(status,) = await self._ezsp.mfglibEnd()
self._check_status(status)

async def _packet_capture_change_channel(self, channel: int):
(status,) = await self._ezsp.mfglibSetChannel(channel=channel)
self._check_status(status)
self._packet_capture_channel = channel

async def send_packet(self, packet: zigpy.types.ZigbeePacket) -> None:
if not self.is_controller_running:
Expand Down

0 comments on commit f12472b

Please sign in to comment.