Skip to content

Update Python version and enhance TrainingStatus handling - #60

Open
michaelw wants to merge 4 commits into
dudanov:mainfrom
michaelw:mw/kickr-core-v2
Open

michaelw wants to merge 4 commits into
dudanov:mainfrom
michaelw:mw/kickr-core-v2

Conversation

@michaelw

Copy link
Copy Markdown

Update Python version requirements to support 3.14.
Implement handling for unknown and reserved values in TrainingStatusFlags and TrainingStatusCode with appropriate logging.

Address repeated disconnect callbacks to prevent errors.

@michaelw

michaelw commented Mar 24, 2026 •

Copy link
Copy Markdown
Author

Also fixes #57 (and adds tests for this case).

@piyopiyolee

Copy link
Copy Markdown

Tested this on a BGYM DD05 walking pad (BLE module FitShow FS-BT-F5, fw V1.0.5beta) through an ESPHome BT proxy. It's the same class of problem: the treadmill sends Training Status with reserved flag bits 0x46 and a reserved status code 83 (0x53), sometimes followed by a text payload. On pyftms 0.4.10 / 0.4.15 main, TrainingStatusFlags(0x46) raises ValueError ... invalid value 70 and the hassio-ftms config entry fails to set up.

With this branch, TrainingStatusModel._deserialize(b"\x46\x53") returns flags=2, code=RESERVED_83 and no longer raises. 👍

One small issue: the pseudo-member returned by TrainingStatusFlags._missing_ has no _name_, so repr(status.flags), status.flags.name and repr(status) raise AttributeError: 'TrainingStatusFlags' object has no attribute '_name_' (Python 3.13). Any debug log that formats the model would hit this. Adding

        obj._value_ = masked
        obj._name_ = None

fixes it (repr -> <TrainingStatusFlags: 2>, name -> None, EXTENDED_STRING in flags still works).

I've been running an equivalent workaround on the DD05 since 2026-11-14 (mask to & 0x03, skip unparsable notifications). Speed, incline and controls all work normally. It would be great to get this merged and released so hassio-ftms can bump the pin (see dudanov/hassio-ftms#52).

@michaelw

Copy link
Copy Markdown
Author

Thanks @piyopiyolee for testing this on your DD05 and spotting the missing _name_ initialization.

I reproduced the formatting failure on Python 3.13 and 3.14. Your suggested _name_ = None fixes it while preserving flag membership and reserved-bit information. The prepared update adds regression coverage for flag names, representations, model logging, and the reported 0x46 / 0x53 header.

Updated PR #60 and published:

I reviewed your workaround notes as well. The parser changes here and the dynamic sensor options in dudanov/hassio-ftms#52 cover the reported reserved values. Could you share a sanitized raw notification that still requires skipping, especially one carrying text? That would help us add a precise regression test for any remaining case.

@piyopiyolee

Copy link
Copy Markdown

Thanks @michaelw for the fix and the new tests! I ran debug captures on the BGYM DD05 tonight: two sessions started from the treadmill's physical remote and one started from Home Assistant. In every session the Training Status notifications decoded cleanly as PRE_WORKOUT (14), then MANUAL_MODE (13), then IDLE (1) on both pause and stop. None of them carried a text string, and nothing needed to be skipped. So I can't provide a text-carrying sample from this device; the skip in my local workaround was purely defensive. Happy to test FTMS v0.24.6+mw.10 on the DD05 if that helps.

@piyopiyolee

Copy link
Copy Markdown

Correction to my comment above: I missed this in my earlier test. Digging further into the logs, the DD05 does send a text-carrying Training Status, just not in notifications. It shows up in the initial read when the connection is set up, every time: 02 53 2D 55 70 64 61 74 65 5F 31 2E 30 (the text decodes as "S-Update_1.0" / "-Update_1.0"). That read fails with "83 is not a valid TrainingStatusCode" in my local build, which is why I added the skip. One caveat: my local patch masks the first byte with & 0x03 before logging, so the original flags byte may differ from what's shown. All later Training Status notifications (PRE_WORKOUT, MANUAL_MODE, IDLE) carried no text. Happy to test FTMS v0.24.6+mw.10 against this.

This branch has not been deployed

No deployments
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