Skip to content

fix(config-flow): re-pair already-bound devices instead of dead-ending (Closes #75)#76

Open
eldios wants to merge 1 commit into
aavdberg:devfrom
eldios:fix/issue-75-repair-loop
Open

fix(config-flow): re-pair already-bound devices instead of dead-ending (Closes #75)#76
eldios wants to merge 1 commit into
aavdberg:devfrom
eldios:fix/issue-75-repair-loop

Conversation

@eldios

@eldios eldios commented Jun 4, 2026

Copy link
Copy Markdown

Summary

Fixes the "This device is already initialized with a secret" setup loop (#75). A fountain previously bound — by the PetKit app or an earlier Home Assistant install whose secret was lost — reported as already initialised and the flow hard-aborted, telling users to factory reset; the reset frequently didn't clear the binding, leaving setup stuck.

The firmware accepts a fresh CMD 73 init without a factory reset, so when a device reports as already initialised the flow now shows a "Device Already Paired" menu:

  • Re-pair now — registers a fresh secret, overwriting the existing pairing.
  • Cancel — aborts, leaving the device untouched.

Re-pair failures abort with an actionable message instead of looping.

Also fixes a latent byte-order bug: async_check_initialized read the device id little-endian while build_init_payload writes big-endian, byte-swapping a non-zero id on re-init. Extracted parse_device_id (big-endian) so the id round-trips, with a regression test. Adds a Troubleshooting section to the README and en/nl/uk translations.

Test plan

Tested on a real Petkit CTW3_100 that was already paired with the PetKit app: setup previously dead-ended on the "already initialized" abort. With this change, the "Device Already Paired" menu appeared, Re-pair now registered a fresh secret and the device paired successfully — entities populate and controls work. The Cancel option aborted cleanly, leaving the device untouched. Automated suite (pytest) passes 101/101 including the new parse_device_id round-trip test; ruff check and ruff format --check are clean.

Closes aavdberg#75)

A fountain that already holds a pairing secret (bound by the PetKit app or a
prior HA setup) hit a hard abort that a factory reset often failed to clear,
leaving setup stuck in a loop.

The firmware accepts a fresh CMD 73 init without a reset (confirmed on a
CTW3_100), so when a device reports as already initialised the config flow now
shows a "Device Already Paired" menu with two choices:

- Re-pair now — register a fresh secret, overwriting the existing pairing.
- Cancel — abort the flow, leaving the device untouched.

Re-pair failures abort with an actionable message instead of looping.

Also fix a latent byte-order bug: async_check_initialized read the device id
little-endian while build_init_payload writes big-endian, which would
byte-swap a non-zero id on re-init. Extract parse_device_id (big-endian) so
the id round-trips, with a regression test.

Adds a Troubleshooting section to the README and translations (en/nl/uk).
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