OPC UA Event object. This is class in inherited by the common event objects such as BaseEvent, other auto standard events and custom events Events are used to trigger events on server side and are sent to clients for every events from server Developper Warning: On serve
| 7 | |
| 8 | |
| 9 | class Event(object): |
| 10 | """ |
| 11 | OPC UA Event object. |
| 12 | This is class in inherited by the common event objects such as BaseEvent, |
| 13 | other auto standard events and custom events |
| 14 | Events are used to trigger events on server side and are |
| 15 | sent to clients for every events from server |
| 16 | |
| 17 | Developper Warning: |
| 18 | On server side the data type of attributes should be known, thus |
| 19 | add properties using the add_property method!!! |
| 20 | """ |
| 21 | |
| 22 | def __init__(self, emitting_node=ua.ObjectIds.Server): |
| 23 | self.server_handle = None |
| 24 | self.select_clauses = None |
| 25 | self.event_fields = None |
| 26 | self.data_types = {} |
| 27 | if isinstance(emitting_node, ua.NodeId): |
| 28 | self.emitting_node = emitting_node |
| 29 | else: |
| 30 | self.emitting_node = ua.NodeId(emitting_node) |
| 31 | # save current attributes |
| 32 | self.internal_properties = list(self.__dict__.keys())[:] + ["internal_properties"] |
| 33 | |
| 34 | def __str__(self): |
| 35 | return "{0}({1})".format( |
| 36 | self.__class__.__name__, |
| 37 | [str(k) + ":" + str(v) for k, v in self.__dict__.items() if k not in self.internal_properties]) |
| 38 | __repr__ = __str__ |
| 39 | |
| 40 | def add_property(self, name, val, datatype): |
| 41 | """ |
| 42 | Add a property to event and tore its data type |
| 43 | """ |
| 44 | setattr(self, name, val) |
| 45 | self.data_types[name] = datatype |
| 46 | |
| 47 | def get_event_props_as_fields_dict(self): |
| 48 | """ |
| 49 | convert all properties of the Event class to a dict of variants |
| 50 | """ |
| 51 | field_vars = {} |
| 52 | for key, value in vars(self).items(): |
| 53 | if not key.startswith("__") and key not in self.internal_properties: |
| 54 | field_vars[key] = ua.Variant(value, self.data_types[key]) |
| 55 | return field_vars |
| 56 | |
| 57 | @staticmethod |
| 58 | def from_field_dict(fields): |
| 59 | """ |
| 60 | Create an Event object from a dict of name and variants |
| 61 | """ |
| 62 | ev = Event() |
| 63 | for k, v in fields.items(): |
| 64 | ev.add_property(k, v.Value, v.VariantType) |
| 65 | return ev |
| 66 |
no outgoing calls
no test coverage detected