Commit f377e699 authored by brubbel's avatar brubbel Committed by oroulet

fix: Setting LocalizedText.Text attribute does not update Encoding

See https://github.com/FreeOpcUa/python-opcua/issues/755
This fixes inconsistent Encoding types when performing
y=variant_to_binary(x) -> x2=variant_from_binary(y) on
auto-generated attributes in the standard address space.
parent f36bef06
......@@ -508,14 +508,24 @@ class LocalizedText(FrozenClass):
def __init__(self, text=None):
self.Encoding = 0
if text is not None and not isinstance(text, str):
raise ValueError(f"A LocalizedText object takes a string as argument, not a {text}, {type(text)}")
self.Text = text
if self.Text:
self.Encoding |= (1 << 1)
self._text = None
if text:
self.Text = text
self.Locale = None
self._freeze = True
@property
def Text(self):
return self._text
@Text.setter
def Text(self, text):
if not isinstance(text, str):
raise ValueError("A LocalizedText object takes a string as argument, not a {}, {}".format(type(text), text))
self._text = text
if self._text:
self.Encoding |= (1 << 1)
def to_string(self):
# FIXME: use local
if self.Text is None:
......
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