Skip to content

Commit 21f9321

Browse files
committed
refactor(flightcontroller): Use DRY in the baudrate property
1 parent cefe343 commit 21f9321

3 files changed

Lines changed: 14 additions & 5 deletions

File tree

ardupilot_methodic_configurator/backend_flightcontroller.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,6 @@ def __init__( # pylint: disable=too-many-arguments, too-many-positional-argumen
123123
logging_warning(_("You should uninstall ModemManager as it conflicts with ArduPilot"))
124124

125125
self._reboot_time = reboot_time
126-
self._baudrate = baudrate
127126
self._network_ports = network_ports if network_ports is not None else FlightControllerConnection.DEFAULT_NETWORK_PORTS
128127

129128
# Component managers (delegation pattern with dependency injection support)
@@ -132,7 +131,7 @@ def __init__( # pylint: disable=too-many-arguments, too-many-positional-argumen
132131
# Share the same FlightControllerInfo instance across all managers
133132
_info = info or FlightControllerInfo()
134133
self._connection_manager: FlightControllerConnectionProtocol = connection_manager or FlightControllerConnection(
135-
info=_info, baudrate=self._baudrate, network_ports=self._network_ports
134+
info=_info, baudrate=baudrate, network_ports=self._network_ports
136135
)
137136

138137
self._params_manager: FlightControllerParamsProtocol = params_manager or FlightControllerParams(
@@ -210,8 +209,8 @@ def reboot_time(self) -> int:
210209

211210
@property
212211
def baudrate(self) -> int:
213-
"""Get the baudrate setting."""
214-
return self._baudrate
212+
"""Get the baudrate setting - delegates to connection manager."""
213+
return self._connection_manager.baudrate
215214

216215
@property
217216
def PARAM_FETCH_POLL_DELAY(self) -> float: # noqa: N802 # pylint: disable=invalid-name
@@ -290,7 +289,7 @@ def reset_and_reconnect(
290289
reset_progress_callback(current_step, sleep_time)
291290

292291
# Reconnect to the flight controller
293-
return self.create_connection_with_retry(connection_progress_callback, baudrate=self._baudrate)
292+
return self.create_connection_with_retry(connection_progress_callback, baudrate=self.baudrate)
294293

295294
def discover_connections(self) -> None:
296295
"""Discover available connections - delegates to connection manager."""

ardupilot_methodic_configurator/backend_flightcontroller_connection.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -940,6 +940,11 @@ def comport_device(self) -> str:
940940
return ""
941941
return str(self.comport.device)
942942

943+
@property
944+
def baudrate(self) -> int:
945+
"""Get the default baud rate for serial connections."""
946+
return self._baudrate
947+
943948
def set_master_for_testing(
944949
self,
945950
master: Optional[mavutil.mavlink_connection], # pyright: ignore[reportGeneralTypeIssues]

ardupilot_methodic_configurator/backend_flightcontroller_protocols.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,11 @@ def comport(self) -> Union[mavutil.SerialPort, serial.tools.list_ports_common.Li
8989
@property
9090
def comport_device(self) -> str: ...
9191

92+
@property
93+
def baudrate(self) -> int:
94+
"""Get the default baud rate for serial connections."""
95+
... # pylint: disable=unnecessary-ellipsis
96+
9297
def discover_connections(self) -> None: ...
9398

9499
def disconnect(self) -> None: ...

0 commit comments

Comments
 (0)