async def data_type_to_variant_type(dtype_node): """ Given a Node datatype, find out the variant type to encode data. This is not exactly straightforward... """ base = await get_base_data_type(dtype_node) if base.nodeid.Identifier != 29: return ua.VariantType(base.nodeid.Identifier) # we have an enumeration, value is a Int32 return ua.VariantType.Int32
def _is_expected_variant_type(self, value, attval, node): vtype = attval.value.Value.VariantType if vtype == ua.VariantType.Null: # Node had a null value, many nodes are initialized with that value # we should check what the real type is dtype = node.attributes[ua.AttributeIds.DataType].value.Value.Value if dtype.NamespaceIndex == 0 and dtype.Identifier <= 25: vtype = ua.VariantType(dtype.Identifier) else: # FIXME: should find the correct variant type given data type but # this is a bit complicaed so trusting the first write return True if value.Value.VariantType == vtype: return True _logger.critical( "Write refused: Variant: %s with type %s does not have expected type: %s", value.Value, value.Value.VariantType, attval.value.Value.VariantType) return False
def _is_expected_variant_type(self, value: ua.DataValue, attval: AttributeValue, node: NodeData) -> bool: vtype = attval.value.Value.VariantType # FIXME Type hinting reveals that it is possible that Value (Optional) is None which would raise an exception if vtype == ua.VariantType.Null: # Node had a null value, many nodes are initialized with that value # we should check what the real type is dtype = node.attributes[ua.AttributeIds.DataType].value.Value.Value if dtype.NamespaceIndex == 0 and dtype.Identifier <= 25: vtype = ua.VariantType(dtype.Identifier) else: # FIXME: should find the correct variant type given data type but # this is a bit complicaed so trusting the first write return True if value.Value.VariantType == vtype: return True _logger.critical( "Write refused: Variant: %s with type %s does not have expected type: %s", value.Value, value.Value.VariantType, attval.value.Value.VariantType) return False