2 from datetime
import datetime
14 Create an event based on an event type. Per default is BaseEventType used. 15 Object members are dynamically created from the base event type and send to 16 client when evebt is triggered (see example code in source) 18 Arguments to constructor are: 20 server: The InternalSession object to use for query and event triggering 22 source: The emiting source for the node, either an objectId, NodeId or a Node 24 etype: The event type, either an objectId, a NodeId or a Node object 27 def __init__(self, isession, etype=None, source=ua.ObjectIds.Server):
29 etype = event_objects.BaseEvent()
31 self.
logger = logging.getLogger(__name__)
36 if isinstance(etype, event_objects.BaseEvent):
38 elif isinstance(etype, Node):
46 self.
event = events.get_event_obj_from_type_node(node)
48 if isinstance(source, Node):
51 source = Node(isession, source)
53 source = Node(isession,
ua.NodeId(source))
55 if self.event.SourceNode:
56 if source.nodeid != self.event.SourceNode:
58 "Source NodeId: '%s' and event SourceNode: '%s' are not the same. Using '%s' as SourceNode",
59 str(source.nodeid), str(self.event.SourceNode), str(self.event.SourceNode))
60 source = Node(self.
isession, self.event.SourceNode)
62 self.event.SourceNode = source.nodeid
63 self.event.SourceName = source.get_browse_name().Name
65 source.set_event_notifier([ua.EventNotifier.SubscribeToEvents, ua.EventNotifier.HistoryRead])
69 ref.ReferenceTypeId =
ua.NodeId(ua.ObjectIds.GeneratesEvent)
70 ref.SourceNodeId = source.nodeid
71 ref.TargetNodeClass = ua.NodeClass.ObjectType
72 ref.TargetNodeId = self.event.EventType
74 results = self.isession.add_references(refs)
78 return "EventGenerator(Type:{0}, Source:{1}, Time:{2}, Message: {3})".format(self.event.EventType,
79 self.event.SourceNode,
84 def trigger(self, time=None, message=None):
86 Trigger the event. This will send a notification to all subscribed clients 88 self.event.EventId =
ua.Variant(uuid.uuid4().hex, ua.VariantType.ByteString)
90 self.event.Time = time
92 self.event.Time = datetime.utcnow()
93 self.event.ReceiveTime = datetime.utcnow()
95 self.event.LocalTime = datetime.utcnow()
98 elif not self.event.Message:
100 self.isession.subscription_service.trigger_event(self.
event)
def trigger(self, time=None, message=None)
def __init__(self, isession, etype=None, source=ua.ObjectIds.Server)