Skip to content

Wrap awscrt types out of public MQTT signatures (#101)#105

Merged
eman merged 1 commit into
mainfrom
pr-101-awscrt-wrap
Jul 6, 2026
Merged

Wrap awscrt types out of public MQTT signatures (#101)#105
eman merged 1 commit into
mainfrom
pr-101-awscrt-wrap

Conversation

@eman

@eman eman commented Jul 6, 2026

Copy link
Copy Markdown
Owner

Summary

Removes awscrt SDK types from the library's public/semi-public MQTT signatures so awscrt stays an internal implementation detail.

Changes

  • New src/nwp500/mqtt/types.py defining:
    • QoS (IntEnum, values match the MQTT wire protocol / awscrt.mqtt.QoS)
    • MqttConnectionHandle alias for the internal connection object
    • to_awscrt_qos / from_awscrt_qos translators — the single boundary that touches awscrt.mqtt.QoS
  • QoS now replaces awscrt.mqtt.QoS on publish/subscribe of NavienMqttClient, MqttConnection, MqttSubscriptionManager, on MqttCommandQueue.enqueue, and the QueuedCommand dataclass. Translation to/from awscrt happens only at the connection-layer call sites.
  • awscrt.mqtt.Connection handles are typed behind MqttConnectionHandle; connection-interrupted callback error params are typed Exception (matching the existing ConnectionInterruptedEvent.error type).
  • NavienMqttClient.publish wraps otherwise-uncaught AwsCrtError in MqttPublishError so awscrt exceptions no longer propagate out of the public boundary.
  • QoS exported from nwp500 and nwp500.mqtt.
  • Tests updated to use the library QoS enum.

No awscrt types appear in public/exported signatures, behavior is unchanged, and awscrt remains internal.

Validation

  • scripts/lint.py (ruff + pyright): passed
  • mypy src/nwp500: no issues in 50 files
  • pytest: 611 passed

Closes #101

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR removes awscrt SDK types from the library’s public/semi-public MQTT-facing type hints by introducing library-owned MQTT transport types (QoS, MqttConnectionHandle) and translating to/from awscrt only at connection-layer call sites. It also prevents AwsCrtError from leaking out of NavienMqttClient.publish() by wrapping unexpected CRT publish errors in MqttPublishError, keeping awscrt as an internal implementation detail.

Changes:

  • Added nwp500.mqtt.types with a library-owned QoS IntEnum, a MqttConnectionHandle alias, and QoS translation helpers.
  • Updated MQTT client/connection/subscription/queue/public exports (and tests) to use QoS instead of awscrt.mqtt.QoS, translating only at the boundary.
  • Wrapped otherwise-uncaught AwsCrtError in NavienMqttClient.publish() as MqttPublishError to prevent SDK exceptions from escaping the public API.

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/nwp500/mqtt/types.py Introduces library-owned MQTT types (QoS, MqttConnectionHandle) and translation functions as the boundary to awscrt.
src/nwp500/mqtt/connection.py Replaces awscrt QoS/Connection type hints with library types and translates QoS at publish/subscribe call sites.
src/nwp500/mqtt/subscriptions.py Stores/accepts library QoS for subscriptions and translates QoS when calling the underlying connection.
src/nwp500/mqtt/client.py Updates public MQTT method signatures to QoS and wraps unexpected AwsCrtError in MqttPublishError at the public boundary.
src/nwp500/mqtt/command_queue.py Updates queued command enqueue signature to accept library QoS.
src/nwp500/mqtt/utils.py Updates QueuedCommand.qos type annotation to library QoS.
src/nwp500/mqtt/__init__.py Re-exports QoS from nwp500.mqtt.
src/nwp500/__init__.py Re-exports QoS at top-level nwp500.QoS.
tests/test_protocol_correctness.py Updates tests to use library QoS instead of awscrt.mqtt.QoS.
tests/test_mqtt_reliability.py Updates tests to use library QoS for subscribe calls.
tests/test_command_queue.py Updates tests to use library QoS in QueuedCommand construction.
CHANGELOG.rst Documents the public API change and the migration from awscrt.mqtt.QoS to nwp500.QoS.

Introduce a library-owned QoS IntEnum and MqttConnectionHandle alias in
nwp500/mqtt/types.py, translating to/from awscrt.mqtt.QoS only at the
connection-layer boundary. Replace awscrt.mqtt.QoS and awscrt.mqtt.Connection
type references across NavienMqttClient, MqttConnection,
MqttSubscriptionManager, MqttCommandQueue and QueuedCommand. Wrap otherwise
uncaught AwsCrtError in MqttPublishError at the public publish() boundary so
awscrt exceptions no longer leak. Export QoS from nwp500 and nwp500.mqtt.
Update tests to use the library QoS enum.
@eman
eman force-pushed the pr-101-awscrt-wrap branch from 771b218 to 1a9e821 Compare July 6, 2026 17:23
@eman
eman merged commit d13f264 into main Jul 6, 2026
7 checks passed
@eman
eman deleted the pr-101-awscrt-wrap branch July 6, 2026 17:25
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.

Wrap awscrt types (QoS/Connection/AwsCrtError) out of public signatures

2 participants