Skip to content

Commit 195f227

Browse files
committed
feat(configuration_steps): Only delete or derive fc_parameter dependent parameters if an FC is connected.
1 parent 6851fdf commit 195f227

4 files changed

Lines changed: 268 additions & 174 deletions

File tree

ardupilot_methodic_configurator/backend_filesystem_configuration_steps.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,9 @@ def compute_parameters( # pylint: disable=too-many-arguments, too-many-position
488488
from a previous call for this file are cleared first, so that parameters whose
489489
condition has since become False are not carried forward.
490490
491+
For parameters with conditions referencing ``fc_parameters``, automatically skips
492+
evaluation when ``fc_parameters`` is not available (e.g., when no FC is connected).
493+
491494
Side effect: updates ``self.forced_parameters`` (when *parameter_type* is
492495
``"forced"``) or ``self.derived_parameters`` (when ``"derived"``) in place.
493496
@@ -505,6 +508,9 @@ def compute_parameters( # pylint: disable=too-many-arguments, too-many-position
505508
errors: list[str] = []
506509

507510
for parameter, parameter_info in file_info[parameter_type + "_parameters"].items():
511+
# Skip parameters with conditions referencing fc_parameters if fc_parameters is unavailable
512+
if "if" in parameter_info and "fc_parameters" in str(parameter_info["if"]) and "fc_parameters" not in variables:
513+
continue
508514
if not self._condition_passes(parameter_info, variables):
509515
continue
510516
error_msg = self._compute_single_parameter(
@@ -521,6 +527,11 @@ def compute_deletions(self, filename: str, file_info: dict, variables: dict) ->
521527
Evaluates the optional 'if' condition for each entry in the 'delete_parameters' section.
522528
A parameter is deleted when its condition evaluates to True (or when no condition is present).
523529
530+
For conditions referencing ``fc_parameters``, automatically skips evaluation when ``fc_parameters``
531+
is not available (e.g., when no FC is connected). This allows users to write conditions like
532+
``'PARAM' not in fc_parameters`` without needing a defensive ``fc_parameters and`` guard.
533+
Conditions not referencing ``fc_parameters`` are always evaluated.
534+
524535
Args:
525536
filename: The name of the configuration file (used for error logging).
526537
file_info: The configuration step dictionary for this file.
@@ -537,6 +548,9 @@ def compute_deletions(self, filename: str, file_info: dict, variables: dict) ->
537548
return set()
538549
to_delete: set[str] = set()
539550
for parameter, parameter_info in file_info["delete_parameters"].items():
551+
# Skip parameters with conditions referencing fc_parameters if fc_parameters is unavailable
552+
if "if" in parameter_info and "fc_parameters" in str(parameter_info["if"]) and "fc_parameters" not in variables:
553+
continue
540554
if self._condition_passes(parameter_info, variables):
541555
to_delete.add(parameter)
542556
if to_delete:

0 commit comments

Comments
 (0)