|
9 | 9 | from concurrent.futures import ThreadPoolExecutor
|
10 | 10 | from datetime import datetime
|
11 | 11 | from functools import partial
|
12 |
| -from typing import TYPE_CHECKING |
| 12 | +from typing import TYPE_CHECKING, Optional |
13 | 13 |
|
14 | 14 | if TYPE_CHECKING:
|
15 | 15 | from typing import Callable, Dict, List, Union, Tuple, Generator
|
16 | 16 | from asyncua.ua.uaprotocol_auto import (
|
17 | 17 | ObjectAttributes, DataTypeAttributes, ReferenceTypeAttributes,
|
18 | 18 | VariableTypeAttributes, VariableAttributes, ObjectTypeAttributes
|
19 | 19 | )
|
20 |
| - __TYPE_ATTRIBUTES = Union[ |
| 20 | + __TYPE_ATTRIBUTES = Union[ |
21 | 21 | DataTypeAttributes,
|
22 | 22 | ReferenceTypeAttributes,
|
23 | 23 | VariableTypeAttributes,
|
@@ -759,6 +759,10 @@ def read_attribute_value(self, nodeid: ua.NodeId, attr: ua.AttributeIds) -> ua.D
|
759 | 759 | dv = ua.DataValue(StatusCode_=ua.StatusCode(ua.StatusCodes.BadAttributeIdInvalid))
|
760 | 760 | return dv
|
761 | 761 | attval = node.attributes[attr]
|
| 762 | + if attr == ua.AttributeIds.DataTypeDefinition and not _datatypedefinition_is_valid(attval.value): |
| 763 | + # DataTypeDefinition should be a subtype of DataTypeDefinition |
| 764 | + dv = ua.DataValue(StatusCode_=ua.StatusCode(ua.StatusCodes.BadAttributeIdInvalid)) |
| 765 | + return dv |
762 | 766 | if attval.value_callback:
|
763 | 767 | return attval.value_callback()
|
764 | 768 | return attval.value
|
@@ -834,3 +838,15 @@ def delete_datachange_callback(self, handle: int):
|
834 | 838 | def add_method_callback(self, methodid: ua.NodeId, callback: Callable):
|
835 | 839 | node = self._nodes[methodid]
|
836 | 840 | node.call = callback
|
| 841 | + |
| 842 | + |
| 843 | +def _datatypedefinition_is_valid(val: Optional[ua.DataValue]) -> bool: |
| 844 | + # Check if DataValue contains SubType of DataTypeDefinition |
| 845 | + if val.Value is None: |
| 846 | + # Retain statuscode if set |
| 847 | + return val.StatusCode is not None |
| 848 | + if val.Value.VariantType != ua.VariantType.ExtensionObject: |
| 849 | + return False |
| 850 | + if issubclass(type(val.Value.Value), ua.DataTypeDefinition): |
| 851 | + return True |
| 852 | + return False |
0 commit comments