Documentation Index
Fetch the complete documentation index at: https://mintlify.com/nokia/moler/llms.txt
Use this file to discover all available pages before exploring further.
Overview
ConnectionObserver is the abstract base class for every object that watches a connection for data. Both Command and Event extend this class. An observer is started, runs in the background parsing incoming data, and eventually completes (with a result or exception) or is cancelled.
ConnectionObserver is an abstract class. You must subclass it and implement data_received(data, recv_time) to use it.Constructor
The connection from which data will be received. If
None, a connection must be assigned before calling start(). The observer subscribes to incoming data on this connection.The runner that manages background execution. If
None, the runner is resolved in order from: the connection’s runner, then the global default runner.Lifecycle methods
start
Timeout in seconds. If provided, overrides the observer’s current
timeout attribute. Must be a positive value.self, allowing chained calls.
Raises:
WrongUsage— if the observer is already done.NoConnectionProvided— if no connection is set.ConnectionObserverTimeout— iftimeoutis not a positive value.
await_done
Maximum seconds to wait. If
None, uses the observer’s configured timeout.ConnectionObserverNotStarted— ifstart()has not been called.- Any exception passed to
set_exception().
cancel
True if the cancel was applied, False if the observer was already done or already cancelled.
State query methods
done
True when the observer has finished — either with a result, an exception, or via cancellation.
running
True if the observer is currently executing (started but not yet done).
cancelled
True if the observer was cancelled.
Result methods
result
- The stored exception, if
set_exception()was called. NoResultSinceCancelCalled— if the observer was cancelled.ResultNotAvailableYet— if the observer is not yet done.
set_result
data_received() once parsing is complete.
The value to store as the final result.
ResultAlreadySet if the observer is already done.
set_exception
result() after this will re-raise the stored exception.
The exception representing the failure.
exception
Access the stored exception directly via the _exception attribute (not a public method), or let result() raise it.
Callback methods
add_done_callback
ConnectionObserver does not expose add_done_callback as a named public method. Completion notification is handled by the runner and through subclassing on_timeout().
Abstract method to implement
data_received
set_result() when done.
Strings received from the device.
Timestamp of when the data was read from the connection.
Override for custom behavior
on_timeout
timeout. The default implementation logs the timeout. Override this method to perform custom cleanup or logging.
on_inactivity
life_status.inactivity_timeout seconds. The default implementation does nothing. Override to handle connection silence.
Other public methods
extend_timeout
timedelta seconds.
Seconds to add to the current timeout.
is_command
False for base ConnectionObserver. Overridden to return True by Command.
get_long_desc / get_short_desc
"Observer '<module>.<classname>(id:...)'" by default. Override in subclasses to provide more informative descriptions.
get_unraised_exceptions
result(). Useful in test teardown.
If
True, clears the exceptions from the internal list after returning them.Key attributes
| Attribute | Type | Description |
|---|---|---|
connection | AbstractMolerConnection | Connection being observed. |
runner | ConnectionObserverRunner | Manages background execution. |
timeout | float | Timeout in seconds (settable property). |
start_time | float | Monotonic time at which start() was called. |
terminating_timeout | float | Additional time allowed after the main timeout for graceful shutdown. |
life_status | ConnectionObserverLifeStatus | Internal lifecycle state container. |
logger | logging.Logger | Logger scoped to moler.connection.<name>. |
device_logger | logging.Logger | Logger scoped to moler.<name>. |