Skip to content

upgrade garmin fit sdk profile version 21.188.0#22

Closed
shaonianche wants to merge 53 commits intomainfrom
update-profile
Closed

upgrade garmin fit sdk profile version 21.188.0#22
shaonianche wants to merge 53 commits intomainfrom
update-profile

Conversation

@shaonianche
Copy link
Owner

#14

- Updated import paths in test_profile.py and test_record.py for consistency.
- Refactored test methods in test_record.py to use assert methods instead of plain assertions.
- Modified test_sdk_files.py to improve readability and structure.
- Updated test_workout_files.py to enhance logging and maintain consistency in test methods.
- Refactored test_write_activity_file.py to improve clarity and maintainability.
- Updated pyproject.toml to specify dependencies and improve project metadata.
- Revised setup.py to align with updated dependencies and project structure.
Refactor test files and update dependencies #1
- Updated string formatting to use double quotes consistently across multiple files.
- Changed minor formatting issues in `fit_tool/fit_file_header.py`, `fit_tool/gen/gen_profile.py`, and `fit_tool/gen/profile.py`.
- Improved type hinting for function parameters and return types in several classes.
- Refactored `to_bytes` and `from_bytes` methods for better clarity and consistency.
- Adjusted comments and docstrings for improved understanding.
- Removed unnecessary imports and organized existing ones.
- Updated `pyproject.toml` to exclude specific directories from linting.
Refactor code for consistency and readability #4
Add CI workflow for linting and testing across multiple Python versions #5
Enhance CI workflow to include coverage reporting in pytest tests #2
fix(pyproject.toml): update bitstruct dependency to version 8.21.0

The Python version matrix in the CI configuration was updated to include version 3.14 to ensure compatibility and testing with the latest Python release. Additionally, the bitstruct dependency was updated to version 8.21.0 to address a security vulnerability and improve the overall security of the project.
fix(ci.yml): update Python version matrix to include 3.14
fix(pyproject.toml): update license format and add MIT License classi…
fix(pyproject.toml): add setuptools-scm to build requirements and change version to dynamic
shaonianche and others added 23 commits June 26, 2025 23:39
…string interpolation

docs(release.yml): update changelog configuration to use double quotes for consistency
style(release.yml): fix indentation and formatting issues in release workflow

The changes improve the consistency and readability of the release workflow file. Using double quotes for string interpolation and configuration values ensures that the YAML file is properly formatted and easier to maintain. The indentation and formatting fixes make the file more readable and consistent with common YAML style guidelines.
…he latest version

docs(fit_tool/gen/gen_profile.py): add comments to clarify the purpose of the code block
The SDK_VERSION in __init__.py was updated to 21.171.00 to ensure compatibility with the latest version of the SDK. Additionally, comments were added to gen_profile.py to improve code readability and maintainability.
chore(pyproject.toml): configure coverage settings for fit_tool package
The pytest command in tox.toml now includes coverage reporting to ensure code coverage is checked during testing. The pyproject.toml file has been updated to configure coverage settings, including setting the minimum coverage threshold to 80% and enabling the display of missing coverage.
fix(fit_tool/__init__.py): update SDK_VERSION to 21.171.00 #13
Refactor code structure for improved readability and maintainability
Signed-off-by: shaonianche <github@duanfei.org>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
fix:calculation of version numbers with different digits
* fix:default header crc

* Update fit_tool/fit_file_builder.py

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>

---------

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
* fix:code type warning

Signed-off-by: shaonianche <github@duanfei.org>

* fix lint

Signed-off-by: shaonianche <github@duanfei.org>

* fix

Signed-off-by: shaonianche <github@duanfei.org>

* fix

Signed-off-by: shaonianche <github@duanfei.org>

* fix

Signed-off-by: shaonianche <github@duanfei.org>

* update

---------

Signed-off-by: shaonianche <github@duanfei.org>
Signed-off-by: shaonianche <github@duanfei.org>
@shaonianche shaonianche closed this Feb 5, 2026
@shaonianche shaonianche deleted the update-profile branch February 5, 2026 08:38
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @shaonianche, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request focuses on updating the project to align with the latest Garmin FIT SDK profile. It involves a comprehensive regeneration of FIT message definitions and associated code, alongside general code modernization efforts such as enhanced type hinting and improved string formatting. The changes ensure compatibility with newer FIT file structures and improve the robustness of the library's internal mechanisms.

Highlights

  • FIT SDK Profile Upgrade: The core of this pull request is an upgrade of the Garmin FIT SDK profile to version 21.171.00. This update is reflected in fit_tool/__init__.py and drives many of the generated code changes.
  • Code Generation Enhancements: The code generation script (fit_tool/gen/gen_profile.py and fit_tool/gen/profile.py) has been significantly refactored to support the new SDK version, including improved type handling, safer integer/string/float conversions, and better management of generated files.
  • Type Hinting and Modern Python Syntax: Numerous files have been updated to use from __future__ import annotations and modern type hinting syntax (e.g., Optional[Type] to Type | None), improving code readability and maintainability.
  • Code Style and Readability Improvements: Minor code style changes, such as using f-strings for string formatting and consistent hexadecimal literal casing (e.g., 0xff to 0xFF), have been applied across the codebase.
  • New Message Types and Fields: Several new message types and fields have been introduced or updated in the fit_tool/profile/messages directory, reflecting the expanded capabilities of the new FIT SDK profile. Examples include aad_accel_features, beat_intervals, chrono_shot_data, chrono_shot_session, and device_aux_battery_info.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • .gitignore
    • Added '.vscode/' to ignore VS Code specific files.
  • README.md
    • Added a note indicating that this is a fork of the original repository.
    • Updated installation instructions to use 'fit-tool' instead of 'fit_tool' for pip install.
  • fit_tool/init.py
    • Updated PROTOCOL_VERSION from '2.3' to '2.4'.
    • Updated SDK_VERSION from '21.60' to '21.171.00'.
    • Changed string literals to use double quotes for consistency.
  • fit_tool/base_type.py
    • Added 'from future import annotations' import.
    • Updated type hints from 'Optional' to '| None'.
    • Reformatted the list of BaseType integers in is_integer method for better readability.
    • Changed hexadecimal literals to uppercase (e.g., 0xff to 0xFF).
  • fit_tool/cli.py
    • Removed the shebang line #!/usr/bin/env python.
    • Removed from __future__ import print_function and import logging.config.
    • Reformatted argument parser and logger calls for improved readability and consistency.
    • Replaced old string formatting with f-strings for logger messages.
  • fit_tool/data_message.py
    • Added 'from future import annotations' import.
    • Updated type hints from 'Optional' to '| None'.
    • Reformatted method signatures for better readability.
    • Replaced old string formatting with f-strings for exceptions and warnings.
  • fit_tool/definition_message.py
    • Added 'from future import annotations' import.
    • Updated type hints from 'Optional' to '| None'.
    • Reformatted method signatures for better readability.
    • Replaced old string formatting with f-strings for exceptions and warnings.
    • Corrected calculate_size method logic to handle empty field lists gracefully.
  • fit_tool/developer_field.py
    • Added 'from future import annotations' import.
    • Updated type hints from 'Optional' to '| None'.
    • Reformatted method signatures for better readability.
  • fit_tool/developer_field_definition.py
    • Changed PACK_FORMAT hexadecimal literal to uppercase ('BBB' to 'BBB').
  • fit_tool/examples/modify_activity_example.py
    • Updated file paths to use relative paths from the project root.
    • Added type imports for DataMessage and DefinitionMessage.
    • Added type checking (isinstance) for message before calling remove_field.
    • Added type checking for power before comparison.
  • fit_tool/examples/read_activity_example.py
    • Updated file paths to use relative paths from the project root.
  • fit_tool/examples/write_activity_example.py
    • Added os import for path manipulation.
    • Updated file paths to use relative paths from the project root.
    • Changed field names to snake_case (e.g., timeCreated to time_created, serialNumber to serial_number).
  • fit_tool/examples/write_course_example.py
    • Updated file paths to use relative paths from the project root.
    • Changed field names to snake_case (e.g., timeCreated to time_created, serialNumber to serial_number, courseName to course_name, eventType to event_type, endPositionLong to end_position_long).
  • fit_tool/examples/write_workout_example.py
    • Changed field names to snake_case (e.g., durationValue to duration_value, workoutName to workout_name).
    • Updated file paths to use relative paths from the project root.
  • fit_tool/field.py
    • Added 'from future import annotations' import.
    • Updated type hints from 'Optional' to '| None'.
    • Reformatted method signatures for better readability.
    • Replaced old string formatting with f-strings for exceptions.
    • Changed hexadecimal literals to uppercase (e.g., 0xff to 0xFF).
    • Added bytes() cast to encoded_value_to_bytes return.
    • Added type_ attribute to Field class initialization.
  • fit_tool/field_component.py
    • Converted FieldComponent to a dataclass for conciseness.
  • fit_tool/field_definition.py
    • Changed PACK_FORMAT hexadecimal literal to uppercase ('BBB' to 'BBB').
  • fit_tool/fit_file.py
    • Added 'from future import annotations' import.
    • Updated type hints from 'Optional' to '| None'.
    • Replaced old string formatting with f-strings for exceptions and warnings.
    • Updated struct.unpack calls to use tuple unpacking.
    • Added gen_crc=True to FitFileHeader initialization in from_bytes.
  • fit_tool/fit_file_builder.py
    • Added 'from future import annotations' import.
    • Updated type hints from [Record] to list[Record].
    • Changed Exception to ValueError in add method for specific error cases.
    • Added gen_crc=True to FitFileHeader initialization in build method.
  • fit_tool/fit_file_header.py
    • Added 'from future import annotations' import.
    • Updated DEFAULT_PROTOCOL_VERSION to 2.4 and DEFAULT_PROFILE_VERSION to 21.171.
    • Modified ProfileVersion class to correctly handle 3-digit minor versions (e.g., 21.171).
    • Replaced old string formatting with f-strings.
    • Changed hexadecimal literals to uppercase.
    • Updated struct.pack calls to use tuple unpacking.
  • fit_tool/gen/gen_profile.py
    • Updated DEFAULT_BUILD_PATH to 'fit_tool'.
    • Added shutil import for directory cleanup.
    • Modified template loader to use Path(__file__).parent.parent for better path resolution.
    • Replaced print statements with logger.info for consistent logging.
    • Improved handling of ref_field_key by using next(iter(...)).
    • Added type checks for type_base_type_name and type_name to prevent errors.
    • Updated Field and SubField instantiation with safe_int, safe_str, safe_float helper functions.
  • fit_tool/gen/profile.py
    • Added SubField import.
    • Added logger import for consistent logging.
    • Introduced safe_int, safe_str, safe_float helper functions for robust type conversion.
    • Added type checks for units and field_type_name.
    • Updated get_type_by_name to use f-strings for exceptions.
    • Modified subfield.ref_field_map to subfield.reference_map for consistency.
    • Improved error handling and type safety in create_field and create_field_definition methods.
  • fit_tool/generic_message.py
    • Added 'from future import annotations' import.
    • Updated type hints from 'Optional' to '| None'.
    • Reformatted method signatures for better readability.
    • Changed exception string to use f-string.
  • fit_tool/message.py
    • Changed exception strings to use double quotes.
  • fit_tool/profile/messages/aad_accel_features_message.py
    • New file generated for FIT SDK Profile 21.171.00.
  • fit_tool/profile/messages/accelerometer_data_message.py
    • Updated profile version to 21.171.00.
    • Added 'from future import annotations' import.
    • Updated type hints from 'Optional' to '| None'.
    • Reformatted method signatures and field definitions for consistency.
  • fit_tool/profile/messages/activity_message.py
    • Updated profile version to 21.171.00.
    • Added 'from future import annotations' import.
    • Updated type hints from 'Optional' to '| None'.
    • Reformatted method signatures and field definitions for consistency.
  • fit_tool/profile/messages/ant_channel_id_message.py
    • Updated profile version to 21.171.00.
    • Added 'from future import annotations' import.
    • Updated type hints from 'Optional' to '| None'.
    • Reformatted method signatures and field definitions for consistency.
  • fit_tool/profile/messages/ant_rx_message.py
    • Updated profile version to 21.171.00.
    • Added 'from future import annotations' import.
    • Updated type hints from 'Optional' to '| None'.
    • Reformatted method signatures and field definitions for consistency.
  • fit_tool/profile/messages/ant_tx_message.py
    • Updated profile version to 21.171.00.
    • Added 'from future import annotations' import.
    • Updated type hints from 'Optional' to '| None'.
    • Reformatted method signatures and field definitions for consistency.
  • fit_tool/profile/messages/aviation_attitude_message.py
    • Updated profile version to 21.171.00.
    • Added 'from future import annotations' import.
    • Updated type hints from 'Optional' to '| None'.
    • Reformatted method signatures and field definitions for consistency.
  • fit_tool/profile/messages/barometer_data_message.py
    • Updated profile version to 21.171.00.
    • Added 'from future import annotations' import.
    • Updated type hints from 'Optional' to '| None'.
    • Reformatted method signatures and field definitions for consistency.
  • fit_tool/profile/messages/beat_intervals_message.py
    • New file generated for FIT SDK Profile 21.171.00.
  • fit_tool/profile/messages/bike_profile_message.py
    • Updated profile version to 21.171.00.
    • Added 'from future import annotations' import.
    • Updated type hints from 'Optional' to '| None'.
    • Reformatted method signatures and field definitions for consistency.
  • fit_tool/profile/messages/blood_pressure_message.py
    • Updated profile version to 21.171.00.
    • Added 'from future import annotations' import.
    • Updated type hints from 'Optional' to '| None'.
    • Reformatted method signatures and field definitions for consistency.
  • fit_tool/profile/messages/cadence_zone_message.py
    • Updated profile version to 21.171.00.
    • Added 'from future import annotations' import.
    • Updated type hints from 'Optional' to '| None'.
    • Reformatted method signatures and field definitions for consistency.
  • fit_tool/profile/messages/camera_event_message.py
    • Updated profile version to 21.171.00.
    • Added 'from future import annotations' import.
    • Updated type hints from 'Optional' to '| None'.
    • Reformatted method signatures and field definitions for consistency.
  • fit_tool/profile/messages/capabilities_message.py
    • Updated profile version to 21.171.00.
    • Added 'from future import annotations' import.
    • Updated type hints from 'Optional' to '| None'.
    • Reformatted method signatures and field definitions for consistency.
  • fit_tool/profile/messages/chrono_shot_data_message.py
    • New file generated for FIT SDK Profile 21.171.00.
  • fit_tool/profile/messages/chrono_shot_session_message.py
    • New file generated for FIT SDK Profile 21.171.00.
  • fit_tool/profile/messages/climb_pro_message.py
    • Updated profile version to 21.171.00.
    • Added 'from future import annotations' import.
    • Updated type hints from 'Optional' to '| None'.
    • Reformatted method signatures and field definitions for consistency.
  • fit_tool/profile/messages/common_fields.py
    • Updated profile version to 21.171.00.
  • fit_tool/profile/messages/connectivity_message.py
    • Updated profile version to 21.171.00.
    • Added 'from future import annotations' import.
    • Updated type hints from 'Optional' to '| None'.
    • Reformatted method signatures and field definitions for consistency.
  • fit_tool/profile/messages/course_message.py
    • Updated profile version to 21.171.00.
    • Added 'from future import annotations' import.
    • Updated type hints from 'Optional' to '| None'.
    • Reformatted method signatures and field definitions for consistency.
  • fit_tool/profile/messages/course_point_message.py
    • Updated profile version to 21.171.00.
    • Added 'from future import annotations' import.
    • Updated type hints from 'Optional' to '| None'.
    • Reformatted method signatures and field definitions for consistency.
  • fit_tool/profile/messages/developer_data_id_message.py
    • Updated profile version to 21.171.00.
    • Added 'from future import annotations' import.
    • Updated type hints from 'Optional' to '| None'.
    • Reformatted method signatures and field definitions for consistency.
  • fit_tool/profile/messages/device_aux_battery_info_message.py
    • New file generated for FIT SDK Profile 21.171.00.
  • fit_tool/profile/messages/device_info_message.py
    • Updated profile version to 21.171.00.
    • Added 'from future import annotations' import.
    • Updated type hints from 'Optional' to '| None'.
    • Reformatted method signatures and field definitions for consistency.
    • Added new sub-fields for device_type (ble_device_type, local_device_type).
    • Added battery_level field.
  • fit_tool/profile/messages/device_settings_message.py
    • Updated profile version to 21.171.00.
    • Added 'from future import annotations' import.
    • Updated type hints from 'Optional' to '| None'.
    • Reformatted method signatures and field definitions for consistency.
  • fit_tool/profile/messages/dive_alarm_message.py
    • Updated profile version to 21.171.00.
    • Added 'from future import annotations' import.
    • Updated type hints from 'Optional' to '| None'.
    • Reformatted method signatures and field definitions for consistency.
    • Added new fields: id, popup_enabled, trigger_on_descent, trigger_on_ascent, repeating, speed.
  • fit_tool/profile/messages/dive_apnea_alarm_message.py
    • New file generated for FIT SDK Profile 21.171.00.
  • fit_tool/profile/messages/dive_gas_message.py
    • Updated profile version to 21.171.00.
    • Added 'from future import annotations' import.
    • Updated type hints from 'Optional' to '| None'.
    • Reformatted method signatures and field definitions for consistency.
    • Added new field: mode.
  • fit_tool/profile/messages/dive_settings_message.py
    • Updated profile version to 21.171.00.
    • Added 'from future import annotations' import.
    • Updated type hints from 'Optional' to '| None'.
    • Reformatted method signatures and field definitions for consistency.
    • Added new sub-fields for heart_rate_source (heart_rate_antplus_device_type, heart_rate_local_device_type).
    • Added new fields: travel_gas, ccr_low_setpoint_switch_mode, ccr_low_setpoint, ccr_low_setpoint_depth, ccr_high_setpoint_switch_mode, ccr_high_setpoint, ccr_high_setpoint_depth, gas_consumption_display, up_key_enabled, dive_sounds, last_stop_multiple, no_fly_time_mode.
  • fit_tool/profile/messages/dive_summary_message.py
    • Updated profile version to 21.171.00.
    • Added 'from future import annotations' import.
    • Updated type hints from 'Optional' to '| None'.
    • Reformatted method signatures and field definitions for consistency.
    • Added new fields: avg_pressure_sac, avg_volume_sac, avg_rmv, descent_time, ascent_time, avg_ascent_rate, avg_descent_rate, max_ascent_rate, max_descent_rate, hang_time.
  • fit_tool/profile/messages/event_message.py
    • Updated profile version to 21.171.00.
    • Added 'from future import annotations' import.
    • Updated type hints from 'Optional' to '| None'.
    • Reformatted method signatures and field definitions for consistency.
    • Added new sub-fields for data (dive_alert, auto_activity_detect_duration).
    • Added new fields: activity_type, start_timestamp, radar_threat_avg_approach_speed, radar_threat_max_approach_speed.
Ignored Files
  • Ignored by pattern: .github/workflows/** (2)
    • .github/workflows/ci.yml
    • .github/workflows/release.yml
Activity
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request upgrades the Garmin FIT SDK profile version, which involves extensive changes across the codebase. Many files, especially the auto-generated message definitions, have been updated to reflect the new SDK version. The manual changes primarily focus on improving code style, readability, and robustness by adopting modern Python features and safer coding practices. I've found one potential issue in fit_tool/data_message.py where a method could lead to an unhandled exception, and I've provided a suggestion to fix it. Overall, this is a solid upgrade with good improvements.

)

def get_developer_field_by_name(self, name: str) -> DeveloperField | None:
return next(iter([x for x in self.developer_fields if x.name == name]))
Copy link
Contributor

Choose a reason for hiding this comment

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

high

The implementation of this method is inconsistent with similar methods in this class and can lead to an unhandled StopIteration exception if the developer field is not found. The type hint suggests that None should be returned in that case.

To fix this and improve efficiency, you can use a generator expression with a default value for next().

Suggested change
return next(iter([x for x in self.developer_fields if x.name == name]))
return next((x for x in self.developer_fields if x.name == name), None)

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.

1 participant