Commit 9d26178f authored by Olivier's avatar Olivier Committed by oroulet

fix typing of SubscriptionHandler

parent 55726fbf
...@@ -81,35 +81,41 @@ class StatusChangeNotificationHandler(Protocol): ...@@ -81,35 +81,41 @@ class StatusChangeNotificationHandler(Protocol):
... ...
SubscriptionHandler = Union[DataChangeNotificationHandler, EventNotificationHandler, StatusChangeNotificationHandler] class DataChangeNotificationHandlerAsync(Protocol):
""" async def datachange_notification(self, node: Node, val: Any, data: DataChangeNotif) -> None:
Protocol class representing subscription handlers to receive events from server.
"""
class SubHandler:
"""
Subscription Handler. To receive events from server for a subscription
This class is just a sample class. Whatever class having these methods can be used
"""
def datachange_notification(self, node: Node, val: Any, data: DataChangeNotif) -> None:
""" """
called for every datachange notification from server called for every datachange notification from server
""" """
pass ...
def event_notification(self, event: ua.EventNotificationList) -> None:
class EventNotificationHandlerAsync(Protocol):
async def event_notification(self, event: ua.EventNotificationList) -> None:
""" """
called for every event notification from server called for every event notification from server
""" """
pass ...
def status_change_notification(self, status: ua.StatusChangeNotification) -> None:
class StatusChangeNotificationHandlerAsync(Protocol):
async def status_change_notification(self, status: ua.StatusChangeNotification) -> None:
""" """
called for every status change notification from server called for every status change notification from server
""" """
pass ...
SubscriptionHandler = Union[
DataChangeNotificationHandler,
EventNotificationHandler,
StatusChangeNotificationHandler,
DataChangeNotificationHandlerAsync,
EventNotificationHandlerAsync,
StatusChangeNotificationHandlerAsync,
]
"""
Protocol class representing subscription handlers to receive events from server.
"""
class Subscription: class Subscription:
......
...@@ -7,7 +7,6 @@ from datetime import timedelta ...@@ -7,7 +7,6 @@ from datetime import timedelta
from datetime import timezone from datetime import timezone
from asyncua import ua from asyncua import ua
from asyncua.common import subscription
from asyncua.common.subscription import Subscription, SubscriptionHandler from asyncua.common.subscription import Subscription, SubscriptionHandler
from ..common.utils import Buffer from ..common.utils import Buffer
...@@ -217,7 +216,7 @@ class HistoryDict(HistoryStorageInterface): ...@@ -217,7 +216,7 @@ class HistoryDict(HistoryStorageInterface):
pass pass
class SubHandler(subscription.SubHandler): class SubHandler:
def __init__(self, storage: HistoryStorageInterface): def __init__(self, storage: HistoryStorageInterface):
self.storage = storage self.storage = storage
......
...@@ -322,7 +322,7 @@ class Client: ...@@ -322,7 +322,7 @@ class Client:
def load_enums(self) -> Dict[str, Type]: # type: ignore[empty-body] def load_enums(self) -> Dict[str, Type]: # type: ignore[empty-body]
pass pass
def create_subscription(self, period: Union[ua.CreateSubscriptionParameters, float], handler: subscription.SubHandler, publishing: bool = True) -> "Subscription": def create_subscription(self, period: Union[ua.CreateSubscriptionParameters, float], handler: subscription.SubscriptionHandler, publishing: bool = True) -> "Subscription":
coro = self.aio_obj.create_subscription(period, _SubHandler(self.tloop, handler), publishing) coro = self.aio_obj.create_subscription(period, _SubHandler(self.tloop, handler), publishing)
aio_sub = self.tloop.post(coro) aio_sub = self.tloop.post(coro)
return Subscription(self.tloop, aio_sub) return Subscription(self.tloop, aio_sub)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment