class documentation

Centrally manages all OPC UA subscription needs.

It bundles subscriptions using only one subscription to an OPC UA server to stay within max. subscription limits of certain OPC UA servers.

Method __init__ Create a new instance.
Async Method clear_subscriptions Delete the OPC UA subscription and forget all registered handlers.
Async Method datachange_notification Handle OPC UA data change notifications callback.
Async Method event_notification Handle OPC UA event notifications callback.
Async Method init Create the subscription and start heartbeat monitoring.
Async Method shutdown Stop heartbeat monitoring and delete the OPC UA subscription.
Async Method status_change_notification Handle OPC UA status notifications callback.
Async Method subscribe_data_change Add given handler to receive data change notifications for given nodes.
Async Method subscribe_data_change_batch Subscribe many handlers to many nodes using as few server calls as possible.
Async Method subscribe_event Add given handler to receive event notifications for given node.
Async Method unsubscribe_data_change Remove handler for given nodes; removes server subscription once it has no handlers left.
Async Method unsubscribe_event Remove handler for events of given node; removes server subscription once it has no handlers left.
Instance Variable logger Undocumented
Property no_of_monitored_items Return the number of monitored nodes.
Method _attach_to_monitored Undocumented
Method _collect_wanted Undocumented
Async Method _create_data_items Batches node subscriptions respecting server's max items per call limit.
Async Method _create_subscription Undocumented
Async Method _delete_subscription Best-effort deletion of the server-side subscription; the maps are left untouched.
Method _find_event_item Undocumented
Async Method _heartbeat_loop Undocumented
Method _invalidate_subscription_handles Undocumented
Async Method _read_max_items_per_call Undocumented
Method _refresh_handles Take over the monitored item IDs asyncua currently knows.
Async Method _renew_data_change_subscriptions Undocumented
Async Method _renew_event_subscriptions Undocumented
Async Method _renew_subscriptions Undocumented
Method _require_subscription Return the OPC UA subscription or raise ConnectionError if there is none.
Async Method _subscribe_new_nodes Undocumented
Async Method _unsubscribe Undocumented
Instance Variable _data_subscription_map Maps a OPC UA node to a handle and a list of handlers for data change notifications.
Instance Variable _event_subscription_map Maps a OPC UA node to a handle and a list of handlers for event notifications.
Instance Variable _heartbeat_stale_after Undocumented
Instance Variable _heartbeat_task Undocumented
Instance Variable _last_heartbeat Undocumented
Instance Variable _max_items_per_call Undocumented
Instance Variable _publishing_interval_ms Undocumented
Instance Variable _ua_client Undocumented
Instance Variable _ua_subscription None before init, after shutdown and while renewing.
def __init__(self, *, ua_client: Client, publishing_interval_ms: float = 100, heartbeat_stale_after: float = 10.0, max_items_per_call: int | None = None):

Create a new instance.

Parameters
ua_client:ClientOPC UA client to use.
publishing_interval_ms:floatRequested publishing interval in milliseconds for OPC UA subscription. May be revised by the server.
heartbeat_stale_after:floatTime in seconds until any subscription should be received.
max_items_per_call:int | NoneMaximum number of OPC UA monitored items per call. If None, will be read from the servers MaxMonitoredItemsPerCall.
async def clear_subscriptions(self):

Delete the OPC UA subscription and forget all registered handlers.

async def datachange_notification(self, node: Node, val: Any, data: DataChangeNotif):

Handle OPC UA data change notifications callback.

async def event_notification(self, ua_event: UaEvent):

Handle OPC UA event notifications callback.

async def init(self):

Create the subscription and start heartbeat monitoring.

Must be called once before any subscribe_* method.

async def shutdown(self):

Stop heartbeat monitoring and delete the OPC UA subscription.

async def status_change_notification(self, status: ua.StatusChangeNotification):

Handle OPC UA status notifications callback.

async def subscribe_data_change(self, handler: UaDataChangeSubscriber, nodes: Node | NodeId | Iterable[Node | NodeId]) -> dict[Node, ua.StatusCode]:

Add given handler to receive data change notifications for given nodes.

Note: Any given handler can only be subscribed once to each node.

Returns
dict[Node, ua.StatusCode]OPC UA error status codes for all failed subscriptions. Mapping of node to status code.
async def subscribe_data_change_batch(self, subscriptions: Iterable[tuple[UaDataChangeSubscriber, Node | NodeId | Iterable[Node | NodeId]]]) -> dict[Node, ua.StatusCode]:

Subscribe many handlers to many nodes using as few server calls as possible.

Parameters
subscriptions:Iterable[tuple[UaDataChangeSubscriber, Node | NodeId | Iterable[Node | NodeId]]]Pairs of (handler, nodes). A node may appear for several handlers.
Returns
dict[Node, ua.StatusCode]OPC UA error status codes for all failed subscriptions. Mapping of node to status code.
async def subscribe_event(self, handler: UaEventSubscriber, source_node: Node | NodeId, *, event_types: Sequence[NodeId] = ()):

Add given handler to receive event notifications for given node.

Parameters
handler:UaEventSubscriberUndocumented
source_node:Node | NodeIdUndocumented
event_types:Sequence[NodeId]Additional event types beside BaseEventType to subscribe.
async def unsubscribe_data_change(self, handler: UaDataChangeSubscriber, nodes: Node | NodeId | Iterable[Node | NodeId]):

Remove handler for given nodes; removes server subscription once it has no handlers left.

async def unsubscribe_event(self, handler: UaEventSubscriber, source_node: Node | NodeId):

Remove handler for events of given node; removes server subscription once it has no handlers left.

logger =

Undocumented

@property
no_of_monitored_items: int =

Return the number of monitored nodes.

def _attach_to_monitored(self, wanted: dict[NodeId, _Wanted]) -> list[Node]:

Undocumented

def _collect_wanted(self, subscriptions: Iterable[tuple[UaDataChangeSubscriber, Node | NodeId | Iterable[Node | NodeId]]]) -> dict[NodeId, _Wanted]:

Undocumented

async def _create_data_items(self, nodes: Sequence[Node]) -> list[int | ua.StatusCode]:

Batches node subscriptions respecting server's max items per call limit.

Returns
list[int | ua.StatusCode]List of handles of the subscription or status codes on failure.
async def _create_subscription(self):

Undocumented

async def _delete_subscription(self):

Best-effort deletion of the server-side subscription; the maps are left untouched.

def _find_event_item(self, handle: int) -> _MonitoredEventItem | None:

Undocumented

async def _heartbeat_loop(self) -> Never:

Undocumented

def _invalidate_subscription_handles(self):

Undocumented

async def _read_max_items_per_call(self):

Undocumented

def _refresh_handles(self):

Take over the monitored item IDs asyncua currently knows.

When the server lost the session, asyncua recreates the subscription on auto-reconnect and the server assigns new monitored item IDs.

async def _renew_data_change_subscriptions(self):

Undocumented

async def _renew_event_subscriptions(self):

Undocumented

async def _renew_subscriptions(self):

Undocumented

def _require_subscription(self) -> Subscription:

Return the OPC UA subscription or raise ConnectionError if there is none.

async def _subscribe_new_nodes(self, new_nodes: list[Node], wanted: dict[NodeId, _Wanted]) -> dict[Node, ua.StatusCode]:

Undocumented

async def _unsubscribe(self, *, handler: _HandlerType, node_id: NodeId, subscription_map: dict[NodeId, _MonitoredItem[_HandlerType]]):

Undocumented

_data_subscription_map: dict[NodeId, _MonitoredItem[UaDataChangeSubscriber]] =

Maps a OPC UA node to a handle and a list of handlers for data change notifications.

_event_subscription_map: dict[NodeId, _MonitoredEventItem] =

Maps a OPC UA node to a handle and a list of handlers for event notifications.

_heartbeat_stale_after =

Undocumented

_heartbeat_task: Task[Never] | None =

Undocumented

_last_heartbeat =

Undocumented

_max_items_per_call: int | None =

Undocumented

_publishing_interval_ms =

Undocumented

_ua_client: Client =

Undocumented

_ua_subscription: Subscription | None =

None before init, after shutdown and while renewing.