Skip to content

homie: expose the bring-your-own-transport wiring contract (will, resync) - #17

Merged
dcj merged 1 commit into
mainfrom
fix/byo-transport-wiring-contract
Aug 2, 2026
Merged

dcj merged 1 commit into
mainfrom
fix/byo-transport-wiring-contract

Conversation

@dcj

@dcj dcj commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

Exposes the bring-your-own-transport wiring contract so an injected MQTT client can achieve the Homie behavior the SDK cannot install on a client it is merely handed, and fixes the Controller-side reconnect gap. Part of #13.

Background

An injected client bypasses MqttClient.from_config (connect_broker / _connect_broker return early when self.mqttc is already set), which is the only place the SDK wires on_connect, on_disconnect, and the LWT. So an injected client loses its last will, its whole-tree reconnect republish, and (tree-rooted Controller) its reconnect bookkeeping reset.

What this does

Pure refactor + additive public API. No owned-client path changes behavior.

  • Device.will() returns the root's $state=lost LWT descriptor, factored out of connect_broker (which now passes lwt=self.will(); identical value on the owned path). A BYO caller sets this on their client before connecting, since the will rides the CONNECT packet and cannot be added afterward.
  • Device.refresh_tree() docstring documents it as the on-connect republish hook a BYO caller invokes from their own handler.
  • Controller.resync() is the tree-rooted discovery reset, extracted from _on_connect (which now delegates to it). A BYO tree-rooted caller calls it on reconnect so the tree re-walks. Closes the Controller-side gap now.

Scope

Tests

+6 (will() x3, resync() x3), 506 total pass. ruff check and ruff format --check clean; CI covers 3.10-3.13 via #16.

🤖 Generated with Claude Code

…ync) (#13)

An injected MQTT client bypasses MqttClient.from_config, the only place the
SDK wires on_connect, on_disconnect, and the LWT, so an injected client loses
the will, the reconnect republish, and (tree-rooted Controller) the reconnect
bookkeeping reset. The will rides the CONNECT packet and the SDK's on_connect
is registered only on a client it constructs, so the SDK cannot install these
on a client it is handed: the caller must wire them. Expose the pieces:

- Device.will(): the root's $state=lost descriptor, factored out of
  connect_broker (which now uses it; owned-path value unchanged).
- Device.refresh_tree(): documented as the on-connect republish hook.
- Controller.resync(): the tree-rooted discovery reset, extracted from
  _on_connect (which now delegates); closes the Controller-side gap.

Pure refactor + additive public API; no owned-client behavior change. The
Device pieces are consumed when Device gains an injection point (#14).

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@dcj
dcj merged commit 6b5aa0c into main Aug 2, 2026
1 check passed
@dcj
dcj deleted the fix/byo-transport-wiring-contract branch August 2, 2026 21:29
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