Skip to content

ECNClient

Part of Client & lifecycle in the Python API reference.

Related guidance: concepts/lifecycle, getting-started/preflight, how-to/cleanup.

Runnable examples: preflight.py.

from picogrid_ecn_client import ECNClient

Manage one explicitly configured MQTT v5 ECN connection.

class ECNClient: ...

Source · client.py

Use ECNClient with async with to manage its asynchronous lifecycle.

Create a client without connecting or installing subscriptions.

def __init__(config: ECNConfig) -> None
NameTypeDefaultDescription
configECNConfigFrozen connection and operation configuration.

Source · client.py

Return the frozen configuration supplied at construction.

config: ECNConfig

Source · client.py

Return the stable typed entity interface.

entities: Entities

Source · client.py

Return the stable typed location interface.

locations: Locations

Source · client.py

Return the stable typed task interface.

tasks: Tasks

Source · client.py

Return the ECN-relative clock diagnostic interface.

clock: Clock

Source · client.py

Return whether MQTT and every still-required subscription are ready.

is_ready: bool

Source · client.py

Return a secret-safe snapshot of the current connection state.

status: ConnectionStatus

Source · client.py

Wait for strict readiness within one caller-supplied deadline.

async def wait_until_ready(*, timeout: float) -> ConnectionStatus
NameTypeDefaultDescription
timeoutfloatPositive finite maximum wait in seconds.
TypeDescription
ConnectionStatusThe first strictly ready connection snapshot.
ExceptionDescription
AuthenticationErrorIf credentials are unavailable or rejected.
AuthorizationErrorIf connection or required-subscription access is denied.
ConfigurationErrorIf unchanged local configuration is invalid.
ConnectionErrorIf recovery becomes terminal for another connection reason.
NotReadyErrorIf the client has not started or is closing/closed.
ProtocolErrorIf recovery terminates on a protocol violation.
ResourceLimitErrorIf the broker rejects a required resource.
TimeoutErrorIf the caller’s deadline expires first.
ValidationErrorIf timeout is not positive and finite.

Source · client.py

Return a capacity-one latest-value stream of redacted connection status.

def connection_events() -> EventStream[ConnectionStatus]
ExceptionDescription
NotReadyErrorIf client closing has begun or the client is closed.

Source · client.py

Wake credential-blocked recovery after an atomic credential repair.

def notify_credentials_changed() -> None

Source · client.py

Wake scheduled transient recovery or revive transient retry exhaustion.

def request_retry() -> None

Source · client.py

Connect to MQTT v5 and wait for readiness.

async def start() -> None
ExceptionDescription
AuthenticationErrorIf authentication material or broker authentication is rejected.
AuthorizationErrorIf the broker rejects connection authorization.
ConfigurationErrorIf local MQTT or TLS verification configuration is invalid.
ConnectionErrorIf MQTT readiness fails or times out.
NotReadyErrorIf the client is closing or already closed.
ProtocolErrorIf MQTT readiness terminates on a protocol violation.
ResourceLimitErrorIf the broker rejects a required connection resource.

Source · client.py

Run read-only checks and caller-requested subscription probes.

async def preflight(
*,
subscription_probes: Collection[SubscriptionProbe] = (),
) -> PreflightReport
NameTypeDefaultDescription
subscription_probesCollection[SubscriptionProbe]()Exact bounded subscription probes to request.
TypeDescription
PreflightReportA secret-safe report of the completed checks.
ExceptionDescription
TimeoutErrorIf closing the probe transport exceeds the configured shutdown timeout. Check failures are reported in the returned report rather than raised.

Source · client.py

Close the client and remove owned resources.

async def close() -> None
ExceptionDescription
ConnectionErrorIf a component fails during cleanup.
TimeoutErrorIf cleanup exceeds the shutdown timeout in seconds.

Source · client.py

Start the client and return it after readiness.

async def __aenter__() -> ECNClient
TypeDescription
ECNClientThis client, ready for entity, location, and task work.
ExceptionDescription
AuthenticationErrorIf authentication material or broker authentication is rejected.
AuthorizationErrorIf the broker rejects connection authorization.
ConfigurationErrorIf local MQTT or TLS verification configuration is invalid.
ConnectionErrorIf MQTT readiness fails or times out.
NotReadyErrorIf the client is closing or already closed.
ProtocolErrorIf MQTT readiness terminates on a protocol violation.
ResourceLimitErrorIf the broker rejects a required connection resource.

Source · client.py

Close the client when leaving the asynchronous context.

async def __aexit__(
exc_type: type[BaseException] | None,
exc_value: BaseException | None,
traceback: TracebackType | None,
) -> None
NameTypeDefaultDescription
exc_typetype[BaseException] | NoneType of the propagated exception, or None.
exc_valueBaseException | NonePropagated exception instance, or None.
tracebackTracebackType | NoneTraceback for the propagated exception, or None.
ExceptionDescription
ConnectionErrorIf a component fails during cleanup.
TimeoutErrorIf cleanup exceeds the shutdown timeout in seconds.

Source · client.py

Version 0.2.0 · branch main