class documentation

class UaVariable(UaObject, ParentMixin[UaObject], Generic[_VariableType]):

Constructor: UaVariable(initial_value, unit, range, minimum_access_level, ...)

View In Hierarchy

OPC UA Variable for use in ParameterSet, Monitoring, FinalResultData, etc.

Abstracts raw OPC UA/asyncua away and provides a simple, high-level interface.

Method __init__ Cooperative constructor for a new variable instance.
Async Method add_reference Add a reference to the given target UaObject, i.e. a Resource.
Method check_range Check whether the given value is within the range.
Method clone Clone the variable configuration. It must be initialized before using it.
Method initial_value.setter Undocumented
Async Method read Read current value from variable.
Async Method read_optional Read current value from variable. Might be None.
Async Method remove_reference Remove the existing reference to the given target UaObject.
Async Method reset Reset variable to initial value.
Async Method set_historize Set the variable to historize.
Async Method set_writable Set the variable to writable externally. Internally, a variable is always writable.
Async Method write Write given value to this variable.
Method write_check Check whether given value can be written to this variable.
Instance Variable optional_ok Undocumented
Instance Variable ua_node Undocumented
Property initial_value Initial value of the variable.
Method _extract_value Undocumented
Async Method _get_definition Undocumented
Async Method _init Undocumented
Method _repr_items Undocumented
Async Method _ua_add_reference Undocumented
Async Method _ua_create_node Undocumented
Instance Variable _historize Undocumented
Instance Variable _initial_value Undocumented
Instance Variable _initial_value_type Undocumented
Instance Variable _range Undocumented
Instance Variable _references Undocumented
Instance Variable _unit Undocumented
Instance Variable _variant_type Undocumented
Instance Variable _writable Undocumented
def __init__(self, initial_value: _VariableType | None, *, unit: Unit | str | int | ua.EUInformation | None = None, range: tuple[float | int, float | int] | ua.Range | None = None, minimum_access_level: int | None = None, writable: bool = False, historize: bool = False, bypass_lock: bool = False, variable_type: type[_VariableType] | None = None, optional_ok: bool = False, name: str | None = None, **kwargs):

Cooperative constructor for a new variable instance.

Parameters
initial_value:_VariableType | NoneThe initial value of the variable. This should not be None for both correct type hints and correctly guessed OPC UA data type of the corresponding OPC UA variable node.
unit:Unit | str | int | ua.EUInformation | NoneThe engineering unit of the variable. Can either be an Unit, an integer (= OPC UA ua.EUInformation.UnitId, e.g. 4410708), or a string (symbol = OPC UA display name, e.g. "cm"). If provided, the range range_ parameter is mandatory!
range:tuple[float | int, float | int] | ua.Range | NoneTuple containing the minimum and maximum values of the variable.
minimum_access_level:int | NoneMinimum access level required to write to the variable (externally via OPC UA).
writable:boolWhether the variable is writable externally or not. Always writable internally.
historize:boolWhether to keep a history of past values of this variable.
bypass_lock:boolWhether the variable can be written to without ownership of corresponding lock.
variable_type:type[_VariableType] | NoneThe Python type of the variable. Is only required if type cannot be determined from initial_value, i.e. when None is provided.
optional_ok:boolUndocumented
name:str | NoneUndocumented
**kwargsUndocumented
async def add_reference(self, target: UaObject):

Add a reference to the given target UaObject, i.e. a Resource.

Defines valid values for UaObject variable types.

def check_range(self, value: _VariableType | ua.Variant | None) -> bool:

Check whether the given value is within the range.

Returns
boolTrue if the given value is within the range (or there is no range specified), False otherwise.
def clone(self, *, name: str, writable: bool | None = None) -> UaVariable[_VariableType]:

Clone the variable configuration. It must be initialized before using it.

Parameters
name:strThe name of the variable.
writable:bool | NoneOverride writable configuration in clone if not None.
Returns
UaVariable[_VariableType]Undocumented
def initial_value(self, value: _VariableType | ua.Variant):

Undocumented

async def read(self) -> _VariableType:

Read current value from variable.

Raises
PyUaRuntimeErrorIf reading an UaObject based variable type would result in None due to Null Node ID.
async def read_optional(self) -> _VariableType | None:

Read current value from variable. Might be None.

async def remove_reference(self, target: UaObject):

Remove the existing reference to the given target UaObject.

async def reset(self):

Reset variable to initial value.

async def set_historize(self, historize: bool, *, period: timedelta = timedelta(days=7), count: int = 1000):

Set the variable to historize.

Parameters
historize:boolWhether the variable should be historized or not. The other parameters are ignored when False.
period:timedeltadata older than this will be deleted from the history. By default, keep the last 7 days.
count:intmax. number of value changes to keep in the history. 0 = no count limit
async def set_writable(self, writable: bool):

Set the variable to writable externally. Internally, a variable is always writable.

async def write(self, value: _VariableType | ua.Variant | None):

Write given value to this variable.

Note: None is only valid for a small set of variable types: str and UaObject based (internally OPC UA nodes)

Raises
OutOfRangeErrorif value is not within the range of the variable.
def write_check(self, value: _VariableType | ua.Variant | None):

Check whether given value can be written to this variable.

Raises
OutOfRangeErrorif value is not within the range of the variable.
optional_ok: bool =

Undocumented

ua_node =

Undocumented

@property
initial_value: _VariableType =

Initial value of the variable.

def _extract_value(self, value) -> _VariableType:

Undocumented

@override
async def _get_definition(self) -> UaObjectDefinition:

Undocumented

@lifecycle
async def _init(self) -> AsyncGenerator[None]:

Undocumented

@override
def _repr_items(self) -> Iterator[tuple[str, object]]:

Undocumented

async def _ua_add_reference(self, target: UaObject):

Undocumented

@override
async def _ua_create_node(self, ua_location: Node, *, instantiate_optional: bool, exist_ok: bool, remove_existing: bool):

Undocumented

_historize: bool =

Undocumented

_initial_value: ua.Variant =

Undocumented

_initial_value_type: type[_VariableType] =

Undocumented

_range: tuple[float | int, float | int] | None =

Undocumented

_references: set[UaObject] =

Undocumented

_unit: ua.EUInformation | None =

Undocumented

_variant_type =

Undocumented

_writable: bool =

Undocumented