feat: optional client argument to IdasenDesk#492
Open
pedropombeiro wants to merge 2 commits into
Open
Conversation
Add an optional `client: BleakClient | None = None` parameter to `IdasenDesk.__init__`. When provided, the supplied client is used as-is instead of letting the constructor create its own; otherwise the existing behavior is preserved. This is useful for downstream wrappers that manage their own BLE connection lifecycle (e.g. via `bleak-retry-connector`'s `establish_connection()`), and removes the need to subclass `IdasenDesk` purely to swap out the underlying client. When `client` is provided, `disconnected_callback` is ignored: the caller is expected to configure that on the client they pass in. This is documented in the docstring.
newAM
requested changes
May 27, 2026
Owner
newAM
left a comment
There was a problem hiding this comment.
Looks good to me, just a minor formatting change. Do you need a release for this when merged? Do you have any other planned changes?
Comment on lines
+10
to
+14
| - Added an optional ``client`` argument to ``IdasenDesk.__init__`` for | ||
| injecting a pre-configured ``BleakClient``. Useful for downstream | ||
| wrappers that manage their own connection lifecycle (e.g. via | ||
| ``bleak-retry-connector``). When provided, ``disconnected_callback`` | ||
| is ignored. |
Owner
There was a problem hiding this comment.
These should be single backticks for markdown.
Contributor
Author
There was a problem hiding this comment.
Fixed the backticks. @newAM sorry for missing this required change in the first PR. Yes, I'd need a new release with this change, there should be no more changes needed.
CHANGELOG.md is markdown; double-backtick reST inline-literal syntax renders as literal backticks rather than inline code.
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.
Summary
Add an optional
client: BleakClient | None = Noneparameter toIdasenDesk.__init__. When provided, the supplied client is used as-is instead of letting the constructor create its own; otherwise the existing behavior is preserved.Why
Downstream wrappers that manage their own BLE connection lifecycle currently have to subclass
IdasenDesk(or reach into_client) to swap out the underlyingBleakClient. The most common case is usingbleak-retry-connector'sestablish_connection(), which returns a pre-connected client with caching and retry logic — useful for connections through Bluetooth proxies.Letting
IdasenDeskaccept a pre-configured client removes the need for subclassing and makes the relationship explicit rather than fragile.This was requested by
abmantis/idasen-ha, which is the Home Assistant helper library that wraps this package.Changes
In
IdasenDesk.__init__:client: Optional[BleakClient] = NoneargumentclientisNone, the existing branch runs — a freshBleakClientis created with the supplieddisconnected_callbackclientis provided, it is stored asself._clientas-is;disconnected_callbackis ignored on the assumption that the caller has already configured it on the client they pass in (documented in the docstring)self._macis still derived from themacargument so logging is unchangedNo other code paths are modified.
Tests
test_init_creates_default_client— withoutclient, aBleakClientis createdtest_init_uses_injected_client— whenclientis provided, the same instance is stored onself._clienttest_init_ignores_disconnected_callback_when_client_provided—disconnected_callbackis silently ignored whenclientis providedAll existing tests continue to pass.
Local CI checks:
Notes
client