Skip to content

Separate into base, templates, import and validation#547

Merged
amilcarlucas merged 1 commit into
masterfrom
data_model_vehicle_components_improvements
Jun 12, 2025
Merged

Separate into base, templates, import and validation#547
amilcarlucas merged 1 commit into
masterfrom
data_model_vehicle_components_improvements

Conversation

@amilcarlucas
Copy link
Copy Markdown
Collaborator

This makes it simpler to test and keeps the linters happier

Make the GNSS protocol depend on the GNSS connection type Restrict the RC receiver, telemetry and battery protocols depending on the selected FC connection type Improve and simplify the data validation code
Update protocol choices when the type changes and is written. The cell voltage now changes when chemistry changes The TOW limits are checked against each other.

This pull request introduces significant updates to the Ardupilot Methodic Configurator, focusing on schema data extraction and a new data model for vehicle components. Key changes include adding methods for extracting and mapping schema-defined data types, implementing a structured data model for component operations, and enhancing JSON format versioning and validation logic.

Schema Data Extraction Enhancements:

  • Added get_all_value_datatypes method in ardupilot_methodic_configurator/backend_filesystem_vehicle_components.py to extract and map all schema-defined data types into a nested dictionary. This includes recursive handling of schema references and allOf constructs.
  • Introduced helper methods _extract_datatypes_from_component, _extract_datatypes_from_property, and _json_type_to_python_type to support recursive traversal and type conversion for JSON schemas.

New Data Model for Components:

  • Created ComponentDataModelBase class in ardupilot_methodic_configurator/data_model_vehicle_components_base.py to separate data operations from UI logic, improving testability.
  • Implemented methods for safely retrieving (get_component_value) and setting (set_component_value) component values with type-safe casting based on schema-defined data types.
  • Added logic for updating JSON structures to ensure compatibility with the latest format, including automatic addition of missing fields and handling legacy naming inconsistencies.

These changes enhance the configurator's robustness by enabling schema-driven data validation and ensuring backward compatibility with older JSON formats.

Copilot AI review requested due to automatic review settings June 10, 2025 16:37
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This pull request refactors the vehicle components handling by separating the logic into base, templates, import, and validation modules. Key changes include enhancing schema data extraction (with new helper methods), introducing a new data model for components to improve testability and JSON structure consistency, and updating various protocols and validation rules for FC parameters.

Reviewed Changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated no comments.

Show a summary per file
File Description
update_vehicle_templates.py Updated call to ComponentDataModel with datatypes from get_all_value_datatypes.
tests/test_backend_filesystem_vehicle_components.py Added comprehensive tests for schema data extraction and type mapping.
ardupilot_methodic_configurator/data_model_vehicle_components_templates.py Introduced a separate template interface with data operations.
ardupilot_methodic_configurator/data_model_vehicle_components_import.py Enhanced FC parameters processing with improved validation and mapping.
ardupilot_methodic_configurator/data_model_vehicle_components_base.py Created base data model with updated JSON structure and type-safe casting.
ardupilot_methodic_configurator/backend_filesystem_vehicle_components.py Added methods for recursive extraction of Python datatypes from the vehicle components JSON schema.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 10, 2025

☂️ Python Coverage

current status: ✅

Overall Coverage

Lines Covered Coverage Threshold Status
6807 4650 68% 60% 🟢

New Files

File Coverage Status
ardupilot_methodic_configurator/data_model_vehicle_components_base.py 89% 🟢
ardupilot_methodic_configurator/data_model_vehicle_components_import.py 99% 🟢
ardupilot_methodic_configurator/data_model_vehicle_components_templates.py 97% 🟢
ardupilot_methodic_configurator/data_model_vehicle_components_validation.py 93% 🟢
TOTAL 95% 🟢

Modified Files

File Coverage Status
ardupilot_methodic_configurator/backend_filesystem_vehicle_components.py 85% 🟢
ardupilot_methodic_configurator/data_model_vehicle_components.py 0% 🟢
TOTAL 43% 🟢

updated for commit: 44d7997 by action🐍

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 10, 2025

Test Results

    2 files  ±  0      2 suites  ±0   1m 29s ⏱️ +9s
1 099 tests +196  1 098 ✅ +196  1 💤 ±0  0 ❌ ±0 
2 198 runs  +392  2 196 ✅ +392  2 💤 ±0  0 ❌ ±0 

Results for commit 44d7997. ± Comparison against base commit 40c29ad.

This pull request removes 62 and adds 258 tests. Note that renamed tests count towards both.
tests.test_data_model_vehicle_components.TestComponentDataModel ‑ test_battery_cell_voltage_validation
tests.test_data_model_vehicle_components.TestComponentDataModel ‑ test_battery_cell_voltage_validation_edge_cases
tests.test_data_model_vehicle_components.TestComponentDataModel ‑ test_battery_monitor_error_handling
tests.test_data_model_vehicle_components.TestComponentDataModel ‑ test_can_gnss_connection
tests.test_data_model_vehicle_components.TestComponentDataModel ‑ test_can_gnss_connection_edge_cases
tests.test_data_model_vehicle_components.TestComponentDataModel ‑ test_combobox_values_edge_cases
tests.test_data_model_vehicle_components.TestComponentDataModel ‑ test_complex_component_extraction
tests.test_data_model_vehicle_components.TestComponentDataModel ‑ test_component_data_model_integration
tests.test_data_model_vehicle_components.TestComponentDataModel ‑ test_component_validation_rules
tests.test_data_model_vehicle_components.TestComponentDataModel ‑ test_comprehensive_data_validation
…
tests.test_backend_filesystem_vehicle_components.TestVehicleComponents ‑ test_get_all_value_datatypes
tests.test_backend_filesystem_vehicle_components.TestVehicleComponents ‑ test_get_all_value_datatypes_empty_schema
tests.test_backend_filesystem_vehicle_components.TestVehicleComponents ‑ test_get_all_value_datatypes_unknown_types
tests.test_data_model_vehicle_components_base.TestComponentDataModelBase ‑ test_basic_component_data_structure
tests.test_data_model_vehicle_components_base.TestComponentDataModelBase ‑ test_battery_chemistry_initialization
tests.test_data_model_vehicle_components_base.TestComponentDataModelBase ‑ test_boundary_value_testing
tests.test_data_model_vehicle_components_base.TestComponentDataModelBase ‑ test_combobox_values_basic_functionality
tests.test_data_model_vehicle_components_base.TestComponentDataModelBase ‑ test_component_access_patterns
tests.test_data_model_vehicle_components_base.TestComponentDataModelBase ‑ test_component_data_immutability
tests.test_data_model_vehicle_components_base.TestComponentDataModelBase ‑ test_component_data_modification
…

♻️ This comment has been updated with latest results.

@amilcarlucas amilcarlucas force-pushed the data_model_vehicle_components_improvements branch from 67999d5 to 9775209 Compare June 11, 2025 23:44
…s, import and validation

This makes it simpler to test and keeps the linters happier

Make the GNSS protocol depend on the GNSS connection type
Restrict the RC receiver, telemetry and battery protocols depending on the selected FC connection type
Improve and simplify the data validation code
Update protocol choices when the type changes and is written.
The cell voltage now changes when chemistry changes
The TOW limits are checked against each other
Validate the dict constants used to validate the data
Re-use common fixatures to prevent code duplication
@amilcarlucas amilcarlucas force-pushed the data_model_vehicle_components_improvements branch from 9775209 to 44d7997 Compare June 12, 2025 01:28
@amilcarlucas amilcarlucas enabled auto-merge (rebase) June 12, 2025 01:50
@amilcarlucas amilcarlucas disabled auto-merge June 12, 2025 09:09
@amilcarlucas amilcarlucas merged commit 69fe608 into master Jun 12, 2025
20 of 22 checks passed
@amilcarlucas amilcarlucas deleted the data_model_vehicle_components_improvements branch June 12, 2025 09:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants