API reference¶
Auto-generated reference for the public surface of bleak_esphome — the four
names exported from the top-level package. For how these pieces fit together,
see the architecture overview; for task-oriented examples,
see usage.
Everything documented here is re-exported from bleak_esphome directly (the
one exception, async_set_unavailable, is reached through
client_data.bluetooth_device), so the import you write in application code
is, for example:
from bleak_esphome import APIConnectionManager, ESPHomeDeviceConfig
High-level entry point¶
APIConnectionManager is the standalone, Home-Assistant-free way to drive a
Bluetooth proxy: hand it a device config, await start(), and it owns the
APIClient, reconnect logic, and scanner registration for you.
- class bleak_esphome.APIConnectionManager(config)¶
Manager for the API connection to an ESPHome device.
- Parameters:
config (ESPHomeDeviceConfig)
- async start()¶
Start the API connection and wait for the first successful connect.
Constructs the
APIClientandReconnectLogicon first call so no event loop work happens at__init__time. Returns once_on_connecthas fired (scanner registered,disconnect_callbackscaptured). Ifstop()is called before the first connect completes, the awaiting task is unblocked withESPHomeStartAbortedrather than a bareCancelledErrorso it does not surface as a spurious cancellation inTaskGrouporasyncio.timeoutcontexts.Call once per manager instance; a second call raises
RuntimeErrorto prevent leaking the priorAPIClient/ReconnectLogic(and its background reconnect task) by overwriting them.- Raises:
ESPHomeStartAborted – if
stop()is called before the first successful connect.RuntimeError – if
start()has already been called.
- Return type:
None
- async stop()¶
Stop the API connection.
- Return type:
None
- class bleak_esphome.ESPHomeDeviceConfig¶
Configuration for an ESPHome device.
- exception bleak_esphome.ESPHomeStartAborted¶
Raised when
APIConnectionManager.start()is aborted bystop().
Low-level escape hatch¶
connect_scanner is for advanced callers that manage their own APIClient
lifecycle. It wires an aioesphomeapi.APIClient to an ESPHomeScanner +
ESPHomeClient and returns the assembled ESPHomeClientData, but leaves the
four caller responsibilities (scanner setup, marking the device unavailable
on disconnect, disconnect callbacks, manager registration) up to you — read
the docstring carefully before reaching for it.
- bleak_esphome.connect_scanner(cli, device_info, available)¶
Connect scanner.
The caller is responsible for:
Calling ESPHomeClientData.scanner.async_setup()
Registering the scanner with the HA Bluetooth manager and also un-registering it when the ESP is disconnected.
Calling ESPHomeClientData.bluetooth_device.async_set_unavailable() when the ESP is disconnected, before firing the callbacks, so the connector’s can_connect gate closes and slot waiters fail fast.
Calling ESPHomeClientData.disconnect_callbacks when the ESP is disconnected.
The caller may choose to override ESPHomeClientData.disconnect_callbacks with its own set. If it does so, it must do so before calling ESPHomeClientData.scanner.async_setup().
- Parameters:
cli (APIClient)
device_info (DeviceInfo)
available (bool)
- Return type:
ESPHomeClientData
async_set_unavailable lives on the ESPHomeBluetoothDevice returned in
client_data.bluetooth_device; it is not a top-level export.
Mark the proxy unavailable and fail pending slot waiters.
Failing fast lets a parked waiter retry against another proxy instead of sitting out its full timeout. The latch clears on the next slot report;
availableis not restored by that, so a reusing caller must set it back toTrueon reconnect, which disarms the fail fast immediately. The free count stays zero until the first slot report. Unanswered-connect streaks are dropped with the rest of the dead session’s state. This method never raises, so teardown paths can call it without guards.- Return type:
None