Add Bodytone DU30-B1D8 Fitness Bike#67
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds a GATT-based fallback to FTMS discovery so devices that advertise the FTMS service but omit machine type service data can still be identified.
Changes:
- Adds
get_machine_type_from_gattto infer machine type from FTMS data characteristics. - Uses the new helper as a fallback during
discover_ftms_devices. - Exports the helper from the properties package and imports it into the client package.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
src/pyftms/client/properties/machine_type.py |
Adds GATT characteristic-based machine type detection. |
src/pyftms/client/properties/__init__.py |
Re-exports the new GATT detection helper. |
src/pyftms/client/__init__.py |
Adds discovery fallback logic that connects to devices lacking machine type service data. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| except (BleakError, NotFitnessMachineError, OSError): | ||
| _LOGGER.debug( | ||
| "Could not determine machine type for '%s' " | ||
| "via GATT fallback.", | ||
| dev.address, | ||
| ) | ||
| continue |
| except NotFitnessMachineError: | ||
| continue | ||
| # The device advertises the FTMS service UUID but does | ||
| # not include machine type in its service data (e.g. | ||
| # Bodytone DU30). Fall back to GATT characteristic | ||
| # inspection by briefly connecting to the device. | ||
| try: |
| try: | ||
| async with BleakClient( | ||
| dev, services=[FTMS_UUID] | ||
| ) as cli: |
| # advertise the FTMS UUID in service_uuids but provide no service data, so | ||
| # they would be silently dropped. We therefore scan for all BLE devices | ||
| # and filter manually. | ||
| async with BleakScanner(**kwargs) as scanner: |
|
Discovery result: |
A D-Bus disconnect event can fire before self._cli is assigned during connection setup (bleak_retry_connector registers the disconnect callback before establish_connection returns). This causes an AttributeError when _on_disconnect calls del self._cli on a fresh IndoorBike instance. Fix: check with hasattr before deleting _cli.
|
Hi @netsoft-ruidias, thank you for the Bodytone DU30-B1D8 work and for sharing the successful discovery output. I ported the GATT data-characteristic machine type detection idea from #67 into my pyftms fork on top of the UUID-only advertisement fallback and post-connect type correction work I already had there. See #70. There is also a drop-in HACS repo for the hassio-ftms fork, using the pyftms fork. The fork now exposes a reusable Would you mind trying the latest fork build with your Bodytone bike when you have a chance? The tag is |
This pull request improves the ability of the FTMS device discovery process to correctly identify machine types, especially for devices that do not advertise their type in service data. The main enhancement is a fallback mechanism that inspects GATT characteristics if the machine type cannot be determined from advertisement data. Additionally, the new utility function for GATT-based type detection has been added and exported for broader use.
Enhancements to FTMS device discovery:
discover_ftms_devicesto determine machine type by connecting to the device and inspecting its GATT characteristics when service data is insufficient. This increases compatibility with devices like the Bodytone DU30 that do not include machine type in their advertisements.New utility for machine type detection:
get_machine_type_from_gatt, an async function that determines the fitness machine type by checking for known FTMS data characteristics on a connected device.get_machine_type_from_gattin bothsrc/pyftms/client/properties/__init__.pyandsrc/pyftms/client/__init__.pyfor use elsewhere in the codebase. [1] [2]Dependency and import updates:
BleakClient,BleakError, and the new utility function, ensuring all necessary components are available for the new fallback logic. [1] [2]