Skip to content

Encrypted device write support with persistent BLE connection (AC180P and others) - #235

Draft
defire04 wants to merge 1 commit into
Patrick762:mainfrom
defire04:feature-encrypted-writes-and-persistent-ble-connection
Draft

Encrypted device write support with persistent BLE connection (AC180P and others)#235
defire04 wants to merge 1 commit into
Patrick762:mainfrom
defire04:feature-encrypted-writes-and-persistent-ble-connection

Conversation

@defire04

Copy link
Copy Markdown

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 DeviceConnection introduced 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__.py

Creates a shared DeviceConnection and write_pending event on setup, stores them in hass.data, passes them to the coordinator, and disconnects cleanly on unload.

coordinator.py

Accepts connection and write_pending. Passes connection to DeviceReader and sets keep_alive_seconds = polling_interval // 2 so the BLE session stays alive briefly after each read cycle. Skips the read cycle entirely while a write is in progress.

switch.py / select.py

  • Removed the block that disabled controls on encrypted devices
  • Write commands now use the shared DeviceConnection via DeviceWriter — no per-write reconnect
  • Optimistic UI update applied immediately on toggle, before the write completes
  • write_pending guard prevents the coordinator from overwriting the optimistic state during the write

const.py

Added DATA_CONNECTION key.

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:

@defire04 defire04 changed the title feature: encrypted device write support with persistent BLE connection Encrypted device write support with persistent BLE connection (AC180P and others) Mar 22, 2026
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