-
-
Notifications
You must be signed in to change notification settings - Fork 16
Fix missing contracts issue for multiple accounts on single ID #400
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -119,25 +119,38 @@ async def _build_bp_number_to_contract( | |
| ) -> tuple[dict[str, list[int]], dict[str, str]]: | ||
| bp_number_to_contract: dict[str, set[int]] = defaultdict(set) | ||
| contract_labels: dict[str, str] = {} | ||
|
|
||
| user_profile = None | ||
| bp_numbers = set() | ||
|
Comment on lines
+123
to
+124
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 1. bp_numbers needs type annotation The new bp_numbers = set() introduces an untyped empty collection, which typically fails mypy strict (it becomes set[Any] / requires an explicit annotation). This can break strict type-checking for the config flow code path. Agent Prompt
|
||
|
|
||
| try: | ||
| user_profile = await client.get_masa_contact_account_user_profile() | ||
| if user_profile and user_profile.accounts: | ||
| bp_numbers.update( | ||
| normalized_bp | ||
| for account in user_profile.accounts | ||
| if (normalized_bp := _normalize_bp_number(account.account_number)) is not None | ||
| ) | ||
| except Exception as err: # noqa: BLE001 | ||
| _LOGGER.debug("Failed to fetch user profile for shared accounts: %s", err) | ||
| return {}, {} | ||
|
|
||
| if not user_profile: | ||
| # Fallback: If masa API failed or returned empty accounts, try get_customer | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a bit problematic, since I expect to use MASA API for Is this your case? Let's discuss it |
||
| if not bp_numbers: | ||
| try: | ||
| customer = await client.get_customer() | ||
| if customer and customer.bp_number: | ||
| normalized_bp = _normalize_bp_number(customer.bp_number) | ||
| if normalized_bp: | ||
| bp_numbers.add(normalized_bp) | ||
| except Exception as err: | ||
| _LOGGER.debug("Fallback to get_customer failed: %s", err) | ||
|
Comment on lines
+145
to
+146
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 2. Broad except lacks ble001 A new except Exception as err: was added without # noqa: BLE001 or a narrower exception type, which will trigger Ruff’s BLE001 rule. This will cause linting/CI failures under the project’s formatting/style requirements. Agent Prompt
|
||
|
|
||
| if not bp_numbers: | ||
| return {}, {} | ||
|
|
||
| bp_numbers = { | ||
| normalized_bp | ||
| for account in user_profile.accounts or [] | ||
| if (normalized_bp := _normalize_bp_number(account.account_number)) is not None | ||
| } | ||
|
|
||
| for bp_number in bp_numbers: | ||
| try: | ||
| contracts: list[Contract] = await client.get_contracts(bp_number) | ||
| contracts = await client.get_contracts(bp_number) | ||
| except Exception as err: # noqa: BLE001 | ||
| _LOGGER.debug("Failed to fetch contracts for bp %s: %s", bp_number, err) | ||
| continue | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
3. Whitespace-only blank line
🐞 Bug⚙ MaintainabilityAgent Prompt
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools