Skip to content

Commit 17cdb45

Browse files
authored
fix: decode PassengerSeatBelt as BuckleStatus enum, not a bool (#37)
* fix: decode PassengerSeatBelt as BuckleStatus enum, not a bool 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. * chore: bump to 0.11.1 (patch), not 0.12.0 - bugfix to previously-broken field
1 parent 423e101 commit 17cdb45

4 files changed

Lines changed: 19 additions & 8 deletions

File tree

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ requires = ["setuptools>=77.0"]
44

55
[project]
66
name = "teslemetry_stream"
7-
version = "0.11.0"
7+
version = "0.11.1"
88
license = "Apache-2.0"
99
description = "Teslemetry Streaming API library for Python"
1010
readme = "README.md"

teslemetry_stream/const.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,7 @@ def upper_options(self) -> list[str]:
597597

598598
# Unused
599599
BuckleStatus = TeslemetryEnum(
600-
"BuckleStatus", ["Unknown", "Unlatched", "Latched", "Faulted"]
600+
"BuckleStatus", ["Unknown", "Unlatched", "Latched", "Faulted", "SNA"]
601601
)
602602

603603
CarType = TeslemetryEnum(

teslemetry_stream/vehicle.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
from .const import (
1414
BMSState,
15+
BuckleStatus,
1516
CabinOverheatProtectionModeState,
1617
CableType,
1718
CarType,
@@ -1301,10 +1302,14 @@ def listen_DriveRail(
13011302
def listen_DriverSeatBelt(
13021303
self, callback: Callable[[bool | None], None]
13031304
) -> Callable[[], None]:
1304-
"""Listen for Driver Seat Belt."""
1305+
"""Listen for Driver Seat Belt.
1306+
1307+
True only when the driver seat is occupied and its belt is undone -
1308+
this is the safety-warning condition, not raw belt state.
1309+
"""
13051310
self._enable_field(Signal.DRIVER_SEAT_BELT)
13061311
return self.stream.async_add_listener(
1307-
make_bool(Signal.DRIVER_SEAT_BELT, callback), # BuckleStatus?
1312+
make_bool(Signal.DRIVER_SEAT_BELT, callback),
13081313
{"vin": self.vin, "data": {Signal.DRIVER_SEAT_BELT: None}},
13091314
)
13101315

@@ -1946,12 +1951,18 @@ def listen_PairedPhoneKeyAndKeyFobQty(
19461951
)
19471952

19481953
def listen_PassengerSeatBelt(
1949-
self, callback: Callable[[bool | None], None]
1954+
self, callback: Callable[[str | None], None]
19501955
) -> Callable[[], None]:
1951-
"""Listen for Passenger Seat Belt."""
1956+
"""Listen for Passenger Seat Belt.
1957+
1958+
Despite the name, this reports the 2nd row centre belt, not the
1959+
front passenger belt.
1960+
"""
19521961
self._enable_field(Signal.PASSENGER_SEAT_BELT)
19531962
return self.stream.async_add_listener(
1954-
make_bool(Signal.PASSENGER_SEAT_BELT, callback),
1963+
lambda x: callback(
1964+
BuckleStatus.get(x["data"][Signal.PASSENGER_SEAT_BELT])
1965+
),
19551966
{"vin": self.vin, "data": {Signal.PASSENGER_SEAT_BELT: None}},
19561967
)
19571968

uv.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)