Skip to content

Refresh BLE client before cover commands - #13

Closed
reydelleon wants to merge 1 commit into
bkanuka:mainfrom
reydelleon:bug/3-refresh-ble-client
Closed

Refresh BLE client before cover commands#13
reydelleon wants to merge 1 commit into
bkanuka:mainfrom
reydelleon:bug/3-refresh-ble-client

Conversation

@reydelleon

Copy link
Copy Markdown

Issue(s): Closes #3

Context

After a Run-Chicken door disconnects, RunChickenDevice can establish a replacement BleakClient, but the cover entity continues using the client captured during entity initialization. Commands sent through that stale client have no current GATT service cache and fail with BleakCharacteristicNotFoundError for the write characteristic.

Changes in this PR

Before each open or close command, the cover entity ensures the device has an active connection and updates its controller to use the device's current client. This keeps command writes aligned with the client managed by RunChickenDevice after reconnects.

Highlights

  • custom_components/run_chicken/cover.py: Refresh the BLE connection and controller client before open and close writes.

Validation outcomes

  • Passed: Python bytecode compilation for the changed module.
  • Passed: git diff --check.
  • Passed: Applied the same patch to a Home Assistant 2026.4.2 installation using an ESPHome Bluetooth proxy; the integration loaded successfully after restart.
  • Not run locally: Ruff is not installed in the local environment; repository CI will run lint and formatting checks.
  • Not discovered: The repository does not contain an automated test suite for cover command behavior.

@reydelleon

Copy link
Copy Markdown
Author

I tested this with my own T50 door, which was having the same issue reported on #13 and it works without issues.

@J-Prince

Copy link
Copy Markdown

@reydelleon Thank you for this fix, it happened once or twice that the power was lost on the Bluetooth proxy, and when power came back, connection would not work, and I would get the "Characteristic 00000000-8e22-4541-9d4c-21edae82ed19 was not found!" error until I rebooted HA. It was hard to know if I had a reliable connection or not with the door looking at entity/device statuses because everything seemed to be OK.

Looking forward to new features for this integration, such as battery %/voltage! 🙏

@bkanuka

bkanuka commented Jun 19, 2026

Copy link
Copy Markdown
Owner

Thank you so much! Sorry real job got busy and pays better than chickens. I will get this merged ASAP.

bkanuka added a commit that referenced this pull request Jun 20, 2026
The door occasionally drops its BLE connection. Until HA was restarted this
left it unusable in three ways, because nothing reconnected:

- Commands failed with "characteristic ... was not found": the cover's
  controller kept writing through the client captured at setup while
  RunChickenDevice had built a replacement. Reconnect and repoint the
  controller at the live client before each command (the fix from #13).
- Push updates (door-state changes the door reports on its own) stopped:
  GATT notifications only arrive over a live connection, and after a drop
  nothing re-established it or re-subscribed.

Add active reconnection: RunChickenDevice takes a disconnect callback that
fires on an unexpected drop; __init__ wires it to a coordinator refresh,
which reconnects, re-subscribes notifications, and re-reads state. The
notification callback is stored and re-subscribed on every reconnect.

Lifecycle: async_disconnect() marks an expected disconnect and tears down
the link on unload (suppressing reconnect), and the advertisement callback
registration is now released via entry.async_on_unload.
@bkanuka

bkanuka commented Jun 20, 2026

Copy link
Copy Markdown
Owner

Closing because I seriously refactored things while incorporating this, so it doesn't make sense to merge , but thanks for finding the bug and the fix!

@bkanuka bkanuka closed this Jun 20, 2026
@reydelleon

Copy link
Copy Markdown
Author

No worries @bkanuka. The end goal was to have things working well abd it seems that's the case now. Thanks for including the change.

@reydelleon
reydelleon deleted the bug/3-refresh-ble-client branch June 20, 2026 22:43
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.

Error controlling door

3 participants