refactor: improve code readability

This commit is contained in:
Lloyd
2026-06-02 10:31:47 +01:00
parent 9e26068a10
commit 416310befd
3 changed files with 11 additions and 18 deletions
+1 -3
View File
@@ -1141,9 +1141,7 @@ class RepeaterHandler(BaseHandler):
return False
try:
sent = await self.dispatcher.send_packet(
fwd_pkt, wait_for_ack=False
)
sent = await self.dispatcher.send_packet(fwd_pkt, wait_for_ack=False)
if not sent:
logger.warning(
"Retransmit failed (attempt %d): dispatcher returned false",
+4 -11
View File
@@ -172,9 +172,7 @@ class PacketRouter:
# (avoids duty-cycle or dispatcher races where a later packet goes out first)
async with self._inject_lock:
# Use local_transmission=True to bypass forwarding logic
sent = await self.daemon.repeater_handler(
packet, metadata, local_transmission=True
)
sent = await self.daemon.repeater_handler(packet, metadata, local_transmission=True)
if not sent:
logger.warning("Injected packet failed local transmission")
return False
@@ -194,9 +192,7 @@ class PacketRouter:
await push_rx(raw, 0, 0.0, exclude_hash=origin_hash)
servers = getattr(self.daemon, "companion_frame_servers", [])
pushed = sum(
1
for fs in servers
if getattr(fs, "companion_hash", None) != origin_hash
1 for fs in servers if getattr(fs, "companion_hash", None) != origin_hash
)
logger.debug(
"Echoed injected TX as raw RX (0x88) to %d companion client(s) "
@@ -221,9 +217,7 @@ class PacketRouter:
if dispatcher and hasattr(dispatcher, "wait_for_ack"):
try:
expected_crc = packet.get_crc()
ack_ok = await dispatcher.wait_for_ack(
expected_crc, timeout=5.0
)
ack_ok = await dispatcher.wait_for_ack(expected_crc, timeout=5.0)
if not ack_ok:
logger.warning(
"Injected packet ACK timeout (crc=%08X)", expected_crc
@@ -517,8 +511,7 @@ class PacketRouter:
sent = await self.daemon.repeater_handler(packet, metadata)
if sent is False:
logger.warning(
"Inbound packet not transmitted by repeater handler "
"(type=%s, header=0x%02x)",
"Inbound packet not transmitted by repeater handler (type=%s, header=0x%02x)",
payload_type,
getattr(packet, "header", 0),
)
+6 -4
View File
@@ -12,7 +12,6 @@ import time
from unittest.mock import AsyncMock, MagicMock, patch
import pytest
from pymc_core.protocol import Packet, PacketBuilder
from pymc_core.protocol.constants import (
MAX_PATH_SIZE,
@@ -24,7 +23,6 @@ from pymc_core.protocol.constants import (
ROUTE_TYPE_TRANSPORT_FLOOD,
)
# ---------------------------------------------------------------------------
# Helpers — build minimal config / mocks needed by RepeaterHandler.__init__
# ---------------------------------------------------------------------------
@@ -1083,7 +1081,9 @@ class TestTxMode:
with patch("repeater.engine.asyncio.sleep", new_callable=AsyncMock):
with patch.object(
handler, "schedule_retransmit", new=AsyncMock(return_value=asyncio.create_task(_boom()))
handler,
"schedule_retransmit",
new=AsyncMock(return_value=asyncio.create_task(_boom())),
):
with pytest.raises(RuntimeError, match="simulated tx failure"):
await handler(pkt, {"snr": 0.0, "rssi": -80}, local_transmission=True)
@@ -1102,7 +1102,9 @@ class TestTxMode:
return False
with patch.object(
handler, "schedule_retransmit", new=AsyncMock(return_value=asyncio.create_task(_tx_false()))
handler,
"schedule_retransmit",
new=AsyncMock(return_value=asyncio.create_task(_tx_false())),
):
transmitted = await handler(pkt, {"snr": 0.0, "rssi": -80}, local_transmission=False)