Skip to content

Improve config flow UX: collapsed advanced section, server-list region picker, clearer username hint#227

Open
fredrik-lindseth wants to merge 2 commits intoJezza34000:mainfrom
fredrik-lindseth:feat/config-flow-d1
Open

Improve config flow UX: collapsed advanced section, server-list region picker, clearer username hint#227
fredrik-lindseth wants to merge 2 commits intoJezza34000:mainfrom
fredrik-lindseth:feat/config-flow-d1

Conversation

@fredrik-lindseth
Copy link
Copy Markdown
Contributor

@fredrik-lindseth fredrik-lindseth commented May 4, 2026

📝 Proposed Change / Description

Three small UX cleanups to the initial account-login form, plus one related setup-failure fix.

  • Move region/timezone into a collapsed Advanced section (defaults from HA config). Removes the chicken-and-egg where the user had to fail login before getting access to the region picker.
  • Replace the 200+ country dropdown with a 5-entry list of PetKit's actual gateways (Europe, International, Asia, Russia, China). Live list fetched from passport.petkt.com/v1/regionservers; falls back to the country dropdown if the call fails. China is added manually because pypetkitapi reaches it via a separate code path.
  • Rename Username/Id to Username and switch the helper text on hass.config.country (CN gets phone/PetKit-ID hint, others get email hint).
  • In __init__.py: when login succeeds but no devices are returned (typical for a secondary account that has not yet accepted the Family Management invite), raise ConfigEntryNotReady with a clear message instead of silently configuring zero entities.

Storage format unchanged: section data is flattened back to top-level CONF_REGION/CONF_TIME_ZONE in entry.data. Only translations/en.json updated; other languages will fall back to English on the new keys until Weblate syncs.

Fixes: #---


🔖 Type of change

  • ✨ New feature (non-breaking change which adds functionality)

🐾 Affected devices

  • 🌐 All devices (config flow is shared)

🧪 How has this been tested?

  • Tested locally with a real PetKit device
  • Tested with Home Assistant version: 2026.4.4

Device(s) tested on: Eversweet Max 2 (CTW3)

Verified: initial form renders with collapsed Advanced; expanding shows 5 server options with Europe auto-selected for HA-NO; failed login preserves user input; existing entries continue to load after upgrade. Family Management ConfigEntryNotReady path was not exercised live (no test account without Family Management).


✅ Checklist

  • Code follows project style: pre-commit run -a hooks and all checks pass
  • No new linting/type errors introduced
  • Documentation updated (if needed)
  • Branch is up-to-date with main

📸 Screenshots

Initial form (collapsed Advanced):

after-d1-initial

Advanced expanded (5 server options, Europe pre-selected for HA-NO):

after-d1-advanced

Failed login preserves the username field:

after-d1-failed-login

⚠️ Breaking Changes

  • No breaking changes.

Three changes that surface together because they all touch the initial
account-login form:

1. Region and timezone now sit inside a collapsed "Advanced" section
   instead of appearing only after a failed first attempt. Defaults
   come from Home Assistant configuration; users only expand the
   section if they need to override.

2. The 200+ country dropdown is replaced with a short list of the
   actual PetKit regional gateways (Europe, International, Asia,
   Russia, China). The list is fetched live from
   passport.petkt.com/v1/regionservers and grouped by gateway. If
   the call fails the legacy country dropdown is shown as fallback.
   The China gateway is added manually since pypetkitapi reaches it
   via a separate code path that is not in the regionservers
   response.

3. The username field is renamed from "Username/Id" to "Username",
   and the helper text now switches based on the user's HA country
   (CN gets phone/PetKit-ID hint, everyone else gets the email
   hint). This removes the "or id if you are a Chinese user"
   line that confused most users.

Plus one related fix in __init__.py: when login succeeds but PetKit
returns no devices (typical when the secondary account has not yet
accepted the Family Management invitation in the mobile app), raise
ConfigEntryNotReady with a message that explains the next step
instead of silently configuring an integration with zero entities.
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented May 4, 2026

@Jezza34000
Copy link
Copy Markdown
Owner

Hi @fredrik-lindseth
The idea of ​​adding this advanced section is excellent.
I just tested it and the user experience is very clear.

However, I have just one comment regarding the architecture:

  • The _fetch_petkit_servers function doesn't belong in the integration, it's for interacting with the API, and this function should be in the pypetkitapi.
    In pypetkitapi, there's already the _get_base_url function, which doesn't return exactly what you need, but it can easily be modified for this purpose.

Could you modify the library and your pull request accordingly to maintain the architecture?
Thank you

@Jezza34000 Jezza34000 mentioned this pull request May 6, 2026
24 tasks
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.

2 participants