Tesla entities unavailable when vehicle data response lacks drive_state
- 主要語言
- Python
- 星號
- 780
- 分支
- 127
- PR 合併指標
- 30 天內沒有已合併 PR
描述
### Is there an existing issue for this?
I searched existing open and closed issues and did not find a duplicate for `KeyError: 'drive_state'`.
### Version of the Tesla component
3.25.5
### Version of Home Assistant
2026.4.4
### teslajsonpy version
Installed package metadata reports `teslajsonpy 3.13.2`, but `teslajsonpy.__version__` reports `3.13.1`.
### Current behavior
All native Tesla Custom Integration entities for one vehicle became unavailable and stayed unavailable. TeslaMate-derived entities for the same vehicle continued to work.
The integration coordinator crashed on every poll because the Tesla vehicle data response did not include `drive_state`, while `teslajsonpy.controller` dereferenced `response["drive_state"]["shift_state"]` unguarded.
This happened while the vehicle was awake, plugged into a DC charger, and likely in/around service mode during charger experiments. It may be a Tesla partial-payload edge case rather than a normal parked/asleep response.
### Expected behavior
A vehicle data response without `drive_state` should not crash the coordinator or make all Tesla entities unavailable. The integration/library should tolerate missing `drive_state`, keep processing the rest of the payload, and only leave drive-state-dependent entities unavailable if needed.
### Relevant log
```text
2026-05-16 20:42:56.806 ERROR (MainThread) [custom_components.tesla_custom] Unexpected error fetching tesla_custom data
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 426, in _async_refresh
self.data = await self._async_update_data()
File "/config/custom_components/tesla_custom/__init__.py", line 466, in _async_update_data
data = await controller.update(
File "/usr/local/lib/python3.14/site-packages/teslajsonpy/controller.py", line 851, in update
result |= bool(await task)
File "/usr/local/lib/python3.14/site-packages/teslajsonpy/controller.py", line 666, in _get_and_process_car_data
!= response["drive_state"]["shift_state"]
~~~~~~~~^^^^^^^^^^^^^^^
KeyError: 'drive_state'
```
### Local hotfix that restored entities
I patched the installed `teslajsonpy/controller.py` locally to use:
```python
drive_state = response.get("drive_state") or {}
shift_state = drive_state.get("shift_state")
```
and to fall back to `time.time()` if the `drive_state` timestamp is absent. After restarting Home Assistant, the native Tesla entities recovered immediately.
### Additional notes
This is probably best fixed in `teslajsonpy`, but I am filing it here because the Home Assistant custom integration issue tracker points here and the user-visible failure is that all `tesla_custom` entities go unavailable.
貢獻指南
評估
這個 Issue 還沒有評估資料。