Encrypted device write support with persistent BLE connection (AC180P and others) - #235
Draft
defire04 wants to merge 1 commit into
Draft
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Warning
Draft PR — depends on two library PRs that must be merged and released before this can be merged (see Notes below).
Problem
Controls (switches and selects) on encrypted devices were silently disabled. Even on unencrypted devices, every toggle opened a fresh BLE connection — taking 5–14 seconds per write.
This PR wires up the
DeviceConnectionintroduced in the library (bluetti-bt-lib) so the integration shares a single persistent BLE session between the polling coordinator and the entity writer.What changed
__init__.pyCreates a shared
DeviceConnectionandwrite_pendingevent on setup, stores them inhass.data, passes them to the coordinator, and disconnects cleanly on unload.coordinator.pyAccepts
connectionandwrite_pending. PassesconnectiontoDeviceReaderand setskeep_alive_seconds = polling_interval // 2so the BLE session stays alive briefly after each read cycle. Skips the read cycle entirely while a write is in progress.switch.py/select.pyDeviceConnectionviaDeviceWriter— no per-write reconnectwrite_pendingguard prevents the coordinator from overwriting the optimistic state during the writeconst.pyAdded
DATA_CONNECTIONkey.Tested on
Bluetti AC180P via ESPHome BLE proxy
AC output, DC output, Power Lifting, Charging Mode — all confirmed working
A test branch (using local library copies before the PRs land) is available here:
defire04/hassio-bluetti-bt @ test-encrypted-writes-and-persistent-ble-connection
Notes
This PR depends on two bluetti-bt-lib PRs — it cannot be merged until both land and a new library version is published: