Retry setup when vehicle base data is incomplete - #394
Open
ML19821 wants to merge 1 commit into
Open
Conversation
get_stored_overview() in pyporscheconnectapi catches PorscheExceptionError internally and returns normally, so a rate limited API leaves vehicle.data without the base data it would have merged in - including "name". Entity setup indexes vehicle.data["name"] directly, so this raised KeyError in every platform. Home Assistant does not retry platform setup after that, which turned a transient API hiccup into a permanent outage until someone noticed and reloaded the entry manually. Detect the incomplete data in the coordinator and fail the refresh instead. During setup async_config_entry_first_refresh() converts UpdateFailed into ConfigEntryNotReady, so Home Assistant retries with backoff and recovers on its own once the API responds again. Verified against a live installation: with the base data missing the config entry now goes to setup_retry with the reason "Incomplete data for vehicle(s) <vin>, will retry" instead of raising KeyError in sensor, binary_sensor, device_tracker, lock and image.
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.
Fixes #393.
get_stored_overview()inpyporscheconnectapicatchesPorscheExceptionErrorinternally and returns normally, so a rate limited API leavesvehicle.datawithout the base data it would have merged in — includingname. No exception reaches the coordinator, so the refresh counts as successful, and entity setup then raisesKeyError: 'name'in every platform. Home Assistant does not retry platform setup after that, so the integration ends up with aloadedconfig entry and zero entities until someone reloads it by hand.This detects the incomplete data in the coordinator and fails the refresh instead. During setup
async_config_entry_first_refresh()convertsUpdateFailedintoConfigEntryNotReady, so Home Assistant retries with backoff and the integration recovers on its own once the API responds again.self.vehiclesis reset so the retry refetches, rather than falling into theelsebranch below, which would never callget_picture_locations()again.Why not a fallback for
vehicle.data["name"]That was my first instinct, but
sensor.pybuildsunique_idfrom the same value. A fallback would mint different unique IDs whenever the data is incomplete and leave duplicate entities behind once the API recovers. Not creating entities from incomplete data at all avoids the problem instead of trading it for a subtler one.Testing
Isolated tests of the guard (complete data, missing base data, two vehicles with one incomplete, both incomplete, empty vehicle list, empty-string name) all behave as intended.
End-to-end on a live installation, simulating the swallowed failure with
vehicle.data.pop("name", None)after the overview call:KeyError: 'name'insensor,binary_sensor,device_tracker,lockandimage; config entryloaded, no entities, no recoverysetup_retry, reasonIncomplete data for vehicle(s) <vin>, will retry, automatic retriesWith the simulation removed and normal API responses, all entities come back unchanged — no change to unique IDs or entity IDs.
Note
Arguably
get_stored_overview()should let the exception propagate rather than swallow it; the coordinator already handlesPorscheExceptionErrorcorrectly. That is the more complete fix but touchespyporscheconnectapi, so it is not part of this PR.