Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 22 additions & 9 deletions custom_components/iec/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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] = {}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Action required

3. Whitespace-only blank line 🐞 Bug ⚙ Maintainability

A whitespace-only blank line was introduced inside _build_bp_number_to_contract(), which Ruff will
flag as a pycodestyle whitespace violation and fail the CI lint job.
Agent Prompt
### Issue description
A whitespace-only blank line was added inside `_build_bp_number_to_contract()` (line contains only indentation). Ruff/pycodestyle flags this and CI will fail.

### Issue Context
CI runs `python3 -m ruff check .` and `.ruff.toml` enables pycodestyle `W` rules.

### Fix Focus Areas
- custom_components/iec/config_flow.py[119-125]
- .ruff.toml[5-27]
- .github/workflows/lint.yml[11-30]

### Proposed fix
Delete the indentation on the blank line (make it a truly empty line) or remove the blank line entirely.

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

user_profile = None
bp_numbers = set()
Comment on lines +123 to +124

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Action required

1. bp_numbers needs type annotation 📘 Rule violation ≡ Correctness

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
## Issue description
`bp_numbers` is initialized as an empty set without a type annotation (`bp_numbers = set()`), which is commonly rejected by mypy in strict mode.

## Issue Context
This code runs in the config flow helper `_build_bp_number_to_contract()` and should pass strict type checking.

## Fix Focus Areas
- custom_components/iec/config_flow.py[123-124]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


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

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The 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 shared-accounts logic (even for multiple accounts).

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Action required

2. Broad except lacks ble001 📘 Rule violation ⚙ Maintainability

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
## Issue description
The fallback block introduces `except Exception as err:` without `# noqa: BLE001` (or narrowing to specific exceptions), which is a Ruff BLE001 violation.

## Issue Context
Other broad exception handlers in this function use `# noqa: BLE001`, indicating the repo enforces this Ruff rule.

## Fix Focus Areas
- custom_components/iec/config_flow.py[145-146]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


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
Expand Down
Loading