Skip to content

Commit 4d3e013

Browse files
committed
refactor(validation): remove dead code in connection type and duplicate checks
The elif branches in battery monitor and GNSS protocol lookups were unreachable because all conn_type values in BATT_MONITOR_CONNECTION and GNSS_RECEIVER_CONNECTION are list objects. The Battery Monitor ESC duplicate-connection allowance was also unreachable: BATT_MONITOR=9 maps to type "other", which is never a serial port and therefore never triggers the duplicate check.
1 parent 2598c8e commit 4d3e013

1 file changed

Lines changed: 3 additions & 24 deletions

File tree

ardupilot_methodic_configurator/data_model_vehicle_components_validation.py

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -387,12 +387,7 @@ def _update_possible_choices_for_path( # pylint: disable=too-many-branches
387387
batt_available_protocols: list[str] = []
388388
for conn_dict in BATT_MONITOR_CONNECTION.values():
389389
conn_type = conn_dict["type"]
390-
# Handle both list and direct port type references
391-
if isinstance(conn_type, list):
392-
if value in conn_type:
393-
batt_available_protocols.append(str(conn_dict["protocol"]))
394-
elif value in conn_type:
395-
# conn_type is a reference to a port list (e.g., ANALOG_PORTS, I2C_PORTS)
390+
if isinstance(conn_type, list) and value in conn_type:
396391
batt_available_protocols.append(str(conn_dict["protocol"]))
397392

398393
self._possible_choices[protocol_path] = (
@@ -421,19 +416,14 @@ def _update_possible_choices_for_path( # pylint: disable=too-many-branches
421416
gnss_available_protocols: list[str] = []
422417
for conn_dict in GNSS_RECEIVER_CONNECTION.values():
423418
conn_type = conn_dict["type"]
424-
# Handle both list and direct port type references
425-
if isinstance(conn_type, list):
426-
if value in conn_type:
427-
gnss_available_protocols.append(str(conn_dict["protocol"]))
428-
elif value in conn_type:
429-
# conn_type is a reference to a port list (e.g., SERIAL_PORTS, CAN_PORTS)
419+
if isinstance(conn_type, list) and value in conn_type:
430420
gnss_available_protocols.append(str(conn_dict["protocol"]))
431421

432422
self._possible_choices[protocol_path] = (
433423
tuple(gnss_available_protocols) if gnss_available_protocols else ("None",)
434424
)
435425

436-
def validate_entry_limits(self, value: str, path: ComponentPath) -> tuple[str, Optional[float]]: # noqa: PLR0911 # pylint: disable=too-many-return-statements
426+
def validate_entry_limits(self, value: str, path: ComponentPath) -> tuple[str, Optional[float]]:
437427
"""
438428
Validate entry values against limits.
439429
@@ -598,20 +588,9 @@ def validate_all_data(self, entry_values: dict[ComponentPath, str]) -> tuple[boo
598588
# Check for duplicate connections
599589
if len(path) >= 3 and path[1] == "FC Connection" and path[2] == "Type":
600590
if value in fc_serial_connection and value not in {"CAN1", "CAN2", "I2C1", "I2C2", "I2C3", "I2C4", "None"}:
601-
battery_monitor_protocol = entry_values.get(
602-
("Battery Monitor", "FC Connection", "Protocol"),
603-
self.get_component_value(("Battery Monitor", "FC Connection", "Protocol")),
604-
)
605-
606591
# Allow certain combinations
607592
if path[0] in {"Telemetry", "RC Receiver"} and fc_serial_connection[value] in {"Telemetry", "RC Receiver"}:
608593
continue
609-
if (
610-
battery_monitor_protocol == "ESC"
611-
and path[0] in {"Battery Monitor", "ESC"}
612-
and fc_serial_connection[value] in {"Battery Monitor", "ESC"}
613-
):
614-
continue
615594

616595
error_msg = _("Duplicate FC connection type '{value}' for {paths_str}")
617596
errors.append(error_msg.format(value=value, paths_str=paths_str))

0 commit comments

Comments
 (0)