Repository navigation
Fix IndexError on out-of-range heater levels in Tesla Fleet - #178049
Conversation
Tesla can report a seat or steering wheel heat level higher than the options the select entity models. Indexing the option list with that raw level raised IndexError inside the coordinator update, so the entity stopped updating. Clamp the level into the modeled range instead, matching the fix already made in Teslemetry. Fixes home-assistant#178048
There was a problem hiding this comment.
Pull request overview
Prevents Tesla Fleet heater select entities from crashing on out-of-range levels.
Changes:
- Clamps seat and steering-wheel heater levels to valid options.
- Adds regression tests for both entity types.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
homeassistant/components/tesla_fleet/select.py |
Safely maps reported heater levels to modeled options. |
tests/components/tesla_fleet/test_select.py |
Tests upper out-of-range heater levels. |
| # Defensive clamp: Tesla could report a level outside the modeled | ||
| # range, so map it to the nearest known option rather than erroring. | ||
| if isinstance(value, int): | ||
| options = self._attr_options | ||
| self._attr_current_option = options[max(0, min(value, len(options) - 1))] |
There was a problem hiding this comment.
Okay so 2 things:
- Do we expect the value to not be an int? Or is this defensive?
- I think we should rewrite the comment, as it now reads like "it could happen", but according to your report it happens. AI really likes to be "save" and defensive, producing very verbose code as it tries to check everything, so I always try to cut down on that. So I think instead we should be more concrete, it can happen and we guard that
There was a problem hiding this comment.
@joostlek this is the identical fix ported from the Teslemetry integration. It was put up by @Bre77 and approved by yourself last month: #175815
I don't mind if it changes but perhaps this could be considered more holistically so that it is consistent across the code base? Perhaps better for @Bre77 to take over if you both agree?
There was a problem hiding this comment.
Everything I know is less certain here because this integration uses a different path. It is more possible to not be an int here (compared to Teslemetry), but I do know its value can be SNA or 4 so this fix should be right.
There was a problem hiding this comment.
SNA?
In any case, I think the comment should be updated to indicate that this happens, instead of sounding like something imaginary
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Proposed change
Tesla can report a seat or steering wheel heat level higher than the options the select entity models. Both select entities indexed their option list with that raw level, so a steering wheel level of 3 (three options modelled) raised
IndexErrorinside_async_update_attrs. That runs in the coordinator callback, so the update for that listener died:This clamps the reported level into the modelled range instead, guarded by
isinstance, so an unknown level maps to the nearest known option andNonestill maps to unknown. The seat heater got the same guard — it models four levels, so it is less exposed, but it fails the same way on any level >= 4.Teslemetry had the same defect and took the same fix in #175815; the two integrations now read the same.
Type of change
Additional information
Checklist
ruff format homeassistant tests)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest.requirements_all.txt.Updated by running
python3 -m script.gen_requirements_all.To help with the load of incoming pull requests: