feat: add firmware_compare/firmware_at_least helper#44
Merged
Conversation
Ported from Home Assistant core PR #175745, which found that comparing Tesla firmware strings lexicographically (e.g. vehicle.firmware >= "2024.44.25") misorders week-based versions such as "2025.10" sorting below "2025.9", wrongly denying streaming entities to vehicles on newer firmware. firmware_compare(a, b) -> int compares dotted numeric components pairwise (returns 1/-1/0), right-padding shorter versions with zeros and treating unparseable strings (e.g. "Unknown") as sorting behind any parseable version. firmware_at_least(firmware, minimum) -> bool is a thin wrapper matching the HA helper's exact call signature for a drop-in replacement. Implemented as a native tuple comparison rather than adding an AwesomeVersion dependency, consistent with this library's narrow, purpose-built dependency list.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Intent / What
vehicle.firmware >= "2024.44.25"-style lexicographic comparisons that misorder week-based firmware ("2025.10" < "2025.9"as strings), wrongly denying streaming entities to vehicles on newer firmware.tesla_fleet_api/util.py:firmware_compare(a, b) -> int(1/-1/0) as the primary helper, withfirmware_at_least(firmware, minimum) -> boolas a thin wrapper (firmware_compare(...) >= 0) so the 16 HA call sites stay a clean drop-in. Both re-exported from the top-level package (from tesla_fleet_api import firmware_at_least).AwesomeVersion(already a core dependency there); this library's dependency list is narrow and purpose-built (aiohttp, aiofiles, aiolimiter, cryptography, protobuf, bleak — no general-purpose version-parsing lib), so a small native implementation is the better fit for a client library. Behavior matches the HA helper on every case exercised by its own tests and by every real threshold in the PR (2024.44.25,2024.26,2025.2.6, "Unknown" handling, equality, partial versions). One documented divergence:AwesomeVersionhas a quirk where a version with an explicit trailing zero component (e.g."2024.26.0") compares as neither greater, less, nor equal to"2024.26"(its__eq__is string-identity, not section-identity) — this native implementation instead correctly treats them as equal via zero-padding. No real Tesla firmware/threshold pair in the codebase hits this edge case.tests/test_firmware_at_least.py): the lexicographic bug case (2025.10vs2025.9), equality, partial-version comparisons, zero-padding, unparseable/"Unknown"firmware, and the real thresholds from the HA PR (2024.44.25,2024.26).Release/publish process (load-bearing for the HA follow-up)
No release-please or automated version bump. This repo ships by:
Bump version to X.Y.Zcommit onmainthat updatesversioninpyproject.tomland__version__intesla_fleet_api/__init__.py.vX.Y.Zgit tag..github/workflows/python-publish.ymlruns on every push, but the build-and-publish-to-PyPI job (and the GitHub Release creation) is gated ongithub.refstarting withrefs/tags/— merging this PR tomainalone does not publish anything. Someone (a maintainer) needs to cut a version-bump commit and push a tag afterward forfirmware_at_least/firmware_compareto become importable from an installedtesla-fleet-apirelease. Recorded inAGENTS.mdunder "Release Process" for future reference.Testing / validation
uv run pytest tests -q— 56 passed, 8 subtests passeduv run ruff check tesla_fleet_api tests— all checks passeduv run ruff format --checkon new/changed files — clean (pre-existing formatting drift in unrelated files left untouched)uv run pyright tesla_fleet_api— 0 errors, 0 warnings