Skip to content

homie: type the Device injection point with MqttDeviceTransport - #19

Merged
dcj merged 1 commit into
mainfrom
feat/device-transport-type
Aug 2, 2026
Merged

dcj merged 1 commit into
mainfrom
feat/device-transport-type

Conversation

@dcj

@dcj dcj commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

Follow-up to #14, on top of #12's MqttTransport base. Types the Device bring-your-own-transport injection point with a narrow structural Protocol, mirroring the owned/injected split #12 did for Controller, so a downstream consumer injecting its own client type-checks and "the SDK never starts or stops a client it did not build" is enforced by the types rather than a convention.

Why this matters now (not just polish)

ebus-mqtt-client PR #9 (draft) ships py.typed, gated on ebus-sdk releasing the transport Protocol widening. That gate now covers two injection points: Controller(mqttc=) (fixed by #12, merged) and Device(mqttc=) (added in #14, still typed Optional[MqttClient]). Once py.typed ships, any injection point still typed Optional[MqttClient] breaks with [arg-type]. This PR widens the Device side, so a 0.16.0 release with #12 + this fully unblocks ebus-mqtt-client #9.

What it does

  • transport.py: MqttDeviceTransport(MqttTransport) adds is_connected() + is_running (the members the device publish path reads); omits start / stop / publish_and_flush, which are owned-only. Re-exported from ebus_sdk. (Data member is_running means isinstance, not issubclass.)
  • Device.mqttc is retyped Optional[MqttDeviceTransport]; the SDK-built client is kept on a separate Device._owned_client (concrete MqttClient), and every owned-only call (start / stop / publish_and_flush, plus Property.start_mqtt_client) routes through it. get_mqtt_client() returns the transport type.

Tests / CI

+4 tests (the MqttDeviceTransport protocol + the _owned_client handle), 527 total. Grep-verified that no owned-only call still routes through the narrowed mqttc. ruff check + ruff format --check clean; the 3.10-3.13 matrix runs on this PR.

CHANGELOG [Unreleased] gets the MqttDeviceTransport entry.

🤖 Generated with Claude Code

Follow-up to #14, on top of #12's MqttTransport base. Adds a Device-side
structural type and mirrors #12's owned/injected client split onto Device, so
"the SDK never starts or stops a client it did not build" is enforced by the
types rather than a convention.

- transport.py: MqttDeviceTransport(MqttTransport) adds is_connected + is_running
  (the members the device publish path reads); omits start/stop/publish_and_flush,
  which are owned-only. Exported from ebus_sdk.
- Device.mqttc is retyped Optional[MqttDeviceTransport]; the SDK-built client is
  kept on a separate Device._owned_client (concrete MqttClient), and every
  owned-only call (start/stop/publish_and_flush, incl. Property.start_mqtt_client)
  routes through it. get_mqtt_client() returns the transport type.

+4 tests (MqttDeviceTransport protocol + the _owned_client handle). Full suite
and ruff green.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@dcj
dcj merged commit 7518c7a into main Aug 2, 2026
5 checks passed
@dcj
dcj deleted the feat/device-transport-type branch August 2, 2026 22:37
dcj added a commit that referenced this pull request Aug 2, 2026
… typing)

Bumps __version__ to 0.16.0 and promotes the [Unreleased] CHANGELOG to
[0.16.0]. Carries the bring-your-own-transport work accumulated since 0.15.0:
the Device(mqttc=) producer seam (#14) with the will/refresh_tree wiring
contract (#13), and the transport Protocol typing (MqttTransport /
MqttControllerTransport #12, MqttDeviceTransport #19). README gains the BYO
section with a neutral note on the shared-connection will limit.

This is the ebus-sdk release the ebus-mqtt-client py.typed marker
(electrification-bus/ebus-mqtt-client#9) is gated on.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
dcj added a commit that referenced this pull request Aug 2, 2026
… typing) (#21)

Bumps __version__ to 0.16.0 and promotes the [Unreleased] CHANGELOG to
[0.16.0]. Carries the bring-your-own-transport work accumulated since 0.15.0:
the Device(mqttc=) producer seam (#14) with the will/refresh_tree wiring
contract (#13), and the transport Protocol typing (MqttTransport /
MqttControllerTransport #12, MqttDeviceTransport #19). README gains the BYO
section with a neutral note on the shared-connection will limit.

This is the ebus-sdk release the ebus-mqtt-client py.typed marker
(electrification-bus/ebus-mqtt-client#9) is gated on.

Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
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