Skip to content

fix: decode PassengerSeatBelt as BuckleStatus enum, not a bool - #37

Merged
Bre77 merged 2 commits into
mainfrom
fm/pytstream-seatbelt-enum-and-docs
Aug 22, 2026
Merged

fix: decode PassengerSeatBelt as BuckleStatus enum, not a bool#37
Bre77 merged 2 commits into
mainfrom
fm/pytstream-seatbelt-enum-and-docs

Conversation

@Bre77

@Bre77 Bre77 commented Aug 22, 2026

Copy link
Copy Markdown
Member

Intent

  • listen_PassengerSeatBelt was typed Callable[[bool | None], None] and wrapped make_bool, but the wire value is the BuckleStatus enum (Unknown/Unlatched/Latched/Faulted/SNA). make_bool's string handling is just data == "true", which none of those values ever match, so every consumer received a permanently-false boolean with no way to recover the real state.
    • Fixed by decoding through BuckleStatus.get, following the existing lookup-map pattern already used by listen_DetailedChargeState.
    • Breaking: the callback type changes from bool | None to str | None. Bumped to 0.11.1 (patch): the field never returned a usable value, so this is a bugfix to broken behavior rather than a change to a working contract, and we only just bumped to 0.11.0 nine days ago. Regenerated uv.lock to match.
    • Added the missing SNA option to BuckleStatus in const.py.
  • Corrected both seat belt docstrings against a live telemetry session:
    • PassengerSeatBelt reports the 2nd row centre belt, not the front passenger belt.
    • DriverSeatBelt is true only when the driver seat is occupied and its belt is undone (the safety-warning condition), not raw belt state.
    • Removed the stale # BuckleStatus? comment - it sat on the driver listener (a plain bool) instead of the passenger one it was actually asking about.
  • Swept the rest of vehicle.py's make_bool call sites for other enum-valued fields wrapped the same way; none of the other Signal names match a defined TeslemetryEnum, so this looks like the only instance of the defect.

make_bool's string handling only ever recognizes the literal "true",
so wrapping the BuckleStatus-valued PassengerSeatBelt signal in
make_bool silently turned every real state (Unlatched/Latched/
Faulted/SNA) into a permanent false. Decode it via BuckleStatus.get,
matching the lookup-map pattern already used by
listen_DetailedChargeState. This is a breaking change: the callback
type changes from bool to str.

Also corrected both seat belt docstrings against live telemetry:
PassengerSeatBelt reports the 2nd row centre belt, not the front
passenger; DriverSeatBelt is true only when the driver seat is
occupied and its belt is undone (the safety-warning condition), not
raw belt state. Removed the stale "# BuckleStatus?" comment, which
sat on the driver listener (a plain bool) instead of the passenger
one.

Swept the rest of vehicle.py's make_bool call sites for other
enum-valued fields wrapped this way; none of the other Signal names
match a defined TeslemetryEnum, so this appears to be the only
instance of the defect.

Bumped to 0.12.0 (minor, matching this project's pre-1.0 convention
for breaking changes - see the prefer_typed removal in 0.11.0) and
regenerated uv.lock.
@Bre77 Bre77 added the fm Opened by a Firstmate crewmate label Aug 22, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ead8897811

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

# Unused
BuckleStatus = TeslemetryEnum(
"BuckleStatus", ["Unknown", "Unlatched", "Latched", "Faulted"]
"BuckleStatus", ["Unknown", "Unlatched", "Latched", "Faulted", "SNA"]

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Recognize the wire's BuckleStatusFault value

When PassengerSeatBelt reports its fault state, the protobuf wire value is BuckleStatusFault, but this options list contains Faulted. The newly used BuckleStatus.get() therefore strips the prefix to Fault, fails the membership check, and invokes the callback with None, conflating a real buckle fault with an unrecognized or absent value; use Fault here.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Rejecting this suggestion: the wire value is BuckleStatusFaulted, not BuckleStatusFault. Verified against three independent authoritative sources: Tesla's upstream fleet-telemetry proto (protos/vehicle_data.proto:417), our tesla-protocol mirror (proto/telemetry/vehicle_data.proto:424), and api's schema (src/schema/fields.ts:2085) — all three define the enum member as BuckleStatusFaulted. Applying this change would break the fault case that currently works correctly. Keeping Faulted as-is.

@Bre77
Bre77 merged commit 17cdb45 into main Aug 22, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fm Opened by a Firstmate crewmate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant