Skip to content

Add is_legacy_gateway to detect a Backup Gateway 1 from site_info - #235

Merged
Bre77 merged 2 commits into
mainfrom
fm/gw1-legacy-lib
Nov 26, 2026
Merged

Bre77 merged 2 commits into
mainfrom
fm/gw1-legacy-lib

Conversation

@Bre77

@Bre77 Bre77 commented Nov 26, 2026 •

Copy link
Copy Markdown
Member

Adds is_legacy_gateway(site_info) to tesla_fleet_api.tesla.powerwall, which says whether a site's gateway is an early Tesla Backup Gateway 1 that needs PowerwallClient.legacy_gateway (the full gateway password login) instead of the default last-5-characters login. It takes the body of the cloud site_info() response and matches the Gateway 1 part number 1118431- against components.gateways[].part_number, or against the site id (the gateway DIN) when no listed gateway has a part number; a body that is not a mapping or has neither raises InvalidResponse. This is the detection home-assistant/core#194397 does inside the Teslemetry integration; once this is released, a later Home Assistant change can switch that PR's detection to this helper.

@gitar-bot gitar-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Gitar has auto-approved this PR (configure)

@gitar-bot gitar-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Gitar has auto-approved this PR (configure)

@gitar-bot

gitar-bot Bot commented Nov 26, 2026

Copy link
Copy Markdown
Code Review ✅ Approved 🟡 Medium risk 1 closed / 1 findings

Adding public gateway detection from site_info could misclassify gateway models, leading callers to select a login method that fails.

Adds is_legacy_gateway(site_info) to tesla_fleet_api.tesla.powerwall to detect early Backup Gateway 1 units by matching part number 1118431- in components.gateways[].part_number, falling back to the site id when no gateways are listed. A resolved finding now ensures gateway entries without a string part_number are handled correctly rather than silently returning False. No open issues remain.

✅ 1 closed
✅ Edge Case: Gateway entries without a string part_number silently return False

📄 tesla_fleet_api/tesla/powerwall/client.py:1784-1797
When components.gateways is a non-empty list, part_numbers comes only from _lookup(gateway, "part_number"). If an entry has no part_number, has null, or isn't a mapping, it turns into None and gets dropped by the isinstance(part_number, str) filter. The function then returns False without checking the site id and without raising. A Gateway 1 site with a sparse gateway entry would be told to use the default last-5-characters login, which those units reject. The repo rules say an unknown shape should raise InvalidResponse rather than fall back to a default. A fix is to fall back to id when no listed gateway has a string part_number, and to raise InvalidResponse if id is missing too. A test for this case would help.

Verification

Rules No rules evaluated

Functional validation Not enabled

Set up

Auto-approval Approved

For more verification details, comment gitar display:verbose.

Options

Auto-apply is off → Gitar will not commit updates to this branch.
Display: compact → Showing compact verification results.

Comment with these commands to change the behavior for this request:

Auto-apply Compact
gitar auto-apply:on         
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Gitar

@Bre77
Bre77 merged commit 1095414 into main Nov 26, 2026
7 checks passed
@Bre77
Bre77 deleted the fm/gw1-legacy-lib branch November 26, 2026 00:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant