Repository navigation
BYD: Gast-Accounts (geteiltes Fahrzeug) unterstützen - #4359
Open
seaspotter wants to merge 3 commits into
Open
seaspotter wants to merge 3 commits into
seaspotter wants to merge 3 commits into
Conversation
There was a problem hiding this comment.
Hey - I've found 3 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="packages/modules/vehicles/byd/api.py" line_range="345" />
<code_context>
+ raise
+ except BydApiError as second:
+ if second.code == (GUEST_NOT_DECLARED_CODE if guest else NOT_A_GUEST_CODE):
+ _user_type_settled.add((*key, endpoint))
+ raise first from None
+ _guest_vins[key] = not guest
</code_context>
<issue_to_address>
**Changed access keeps failing**
When sharing permissions change after both user types were rejected and the endpoint was marked settled, `_user_type_settled` remains set, so `_post_vehicle_json` skips the alternate `userType` on later requests and the vehicle's SoC stays unavailable until the process restarts.
Clear or expire the settled marker when sharing permissions change so later requests can retry the alternate `userType`.
Also at `packages/modules/vehicles/byd/api.py:335`, `packages/modules/vehicles/byd/api.py:346`.
</issue_to_address>
### Comment 2
<location path="packages/modules/vehicles/byd/api.py" line_range="335" />
<code_context>
+ raise
+ except BydApiError as first:
+ wrong_user_type = NOT_A_GUEST_CODE if guest else GUEST_NOT_DECLARED_CODE
+ if first.code != wrong_user_type or (*key, endpoint) in _user_type_settled:
+ raise
+ retry_inner = {**inner, "random": secrets.token_hex(16).upper(),
</code_context>
<issue_to_address>
**Unsupported requests get misclassified as guest**
When an owner’s realtime endpoint returns `1001` because that endpoint is unsupported, and the retry returns an error other than the opposite-type code, `_post_vehicle_json` treats any `1001` as “guest not declared,” although `_post_token_json` also classifies `1001` as an unsupported-endpoint response. It retries with the opposite user type and can cache that guess from an unrelated retry error, so later requests use the wrong account type and callers see misleading or repeated failures.
Only infer and cache account type when the response is known to represent a user-type mismatch; otherwise preserve the original error without changing the cache.
</issue_to_address>
### Comment 3
<location path="packages/modules/vehicles/byd/api_test.py" line_range="178" />
<code_context>
+
+ @staticmethod
+ def _user_types(post_mock):
+ return [call.args[4] for call in post_mock.call_args_list]
+
+ def test_owner_is_asked_without_user_type_once(self, monkeypatch):
</code_context>
<issue_to_address>
**New BYD tests crash**
When the new `TestPostVehicleJson` tests reach `_user_types`, `TestPostVehicleJson` calls `_user_types`, whose `call.args[4]` raises `NameError` because `call` is not imported; the tests fail instead of checking the recorded user types.
Import `call` from `unittest.mock`.
</issue_to_address>
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.
Seit dem 12.11.2026 beantwortet die BYD-Cloud die Echtzeit-Abfragen von Accounts, mit denen das Fahrzeug nur geteilt ist ("Familie und Freunde"), mit Code 1001. Das passiert, wenn die Anfrage kein signiertes
userType: "1"enthält. In openWB steht dann "SoC kann nicht ausgelesen werden … Code 1001".Das Verhalten und die Lösung stammen aus pyBYD: jkaberg/pyBYD#81 (betroffen laut jkaberg/hass-byd-vehicle#213 u. a. geteilte Accounts).
Änderungen:
Summary by Sourcery
Support BYD shared-vehicle accounts in real-time data retrieval.
New Features:
Bug Fixes:
Enhancements:
Tests: