OPC UA Connector Schemas#
OPC UA Connector Schemas
This module provides Pydantic models to define and validate configuration schemas for OPC UA devices within OpenFactory.
Key Models:#
OPCUAServerConfig: Configuration for the OPC UA server, including the endpoint URI and optional default subscription parameters.
OPCUASubscriptionConfig: Optional subscription parameters (publishing interval, queue size, sampling interval). Can be defined at the server level or overridden per variable. If not provided at the server level, default values are applied (publishing_interval=100 ms, queue_size=1, sampling_interval=0 ms).
OPCUAVariableConfig: Configuration for a single variable. Contains node_id or browse_path to identify the OPC UA node and a tag used by OpenFactory to label data. Variables may also declare an access_level (ro or rw) describing how OpenFactory is allowed to interact with the node. Optional overrides for queue size and sampling interval can be provided.
OPCUAEventConfig: Configuration for an event source. Contains node_id or browse_path identifying the OPC UA node that emits events. Events do not use tags or subscription overrides.
OPCUAMethodConfig: Configuration for a method source. Each entry references an OPC UA node (node_id or browse_path) from which all available OPC UA methods will be discovered at runtime. Methods are not individually declared in the schema; instead, the node acts as a method container.
OPCUAConnectorSchema: Wrapper schema that encapsulates the server configuration along with variables, events, and method sources. During initialization, all variables, events, and methods are normalized into their respective config models. Server-level subscription defaults are applied to variables where necessary.
Validation Features:#
Validates node_id format and parses it into namespace_index, identifier_type, and identifier fields.
Enforces that exactly one of node_id or browse_path is provided for variables, events, and methods.
Normalizes variables into OPCUAVariableConfig, applying server-level subscription defaults when not overridden. If the server subscription is omitted, default values are applied.
Ensures uniqueness of node_id and browse_path within variables, within events, and within methods.
Prevents local name conflicts between variables, events, and methods.
Forbids unknown fields to ensure strict schema conformance.
YAML Example:#
# ---------------------------------------------------------
# Example 1: Server subscription omitted → defaults applied
# ---------------------------------------------------------
type: opcua
server:
uri: opc.tcp://127.0.0.1:4840/freeopcua/server/
# subscription omitted → defaults will be used:
# publishing_interval: 100
# queue_size: 1
# sampling_interval: 0
variables:
temp:
node_id: ns=3;i=1050
tag: Temperature
deadband: 0.1
hum:
browse_path: 0:Root/0:Objects/2:Sensors/2:Humidity
tag: Humidity
events:
iolinkmaster:
node_id: ns=6;i=43
methods:
tempSensor:
browse_path: 0:Root/0:Objects/2:Sensors/2:TemperatureSensor
humiSensor:
node_id: ns=5;i=12
# ---------------------------------------------------------
# Example 2: Server subscription explicitly provided
# ---------------------------------------------------------
type: opcua
server:
uri: opc.tcp://127.0.0.1:4840/freeopcua/server/
subscription:
publishing_interval: 200
queue_size: 10
sampling_interval: 25
variables:
temp:
node_id: ns=3;i=1050
tag: Temperature
queue_size: 5 # overrides server subscription
sampling_interval: 50 # overrides server subscription
setpoint:
node_id: ns=2;i=10
tag: Setpoint
access_level: rw # read-write variable
See also
The runtime class of the OPCUAConnectorSchema schema is openfactory.connectors.opcua.opcua_connector.OPCUAConnector.
- class openfactory.schemas.connectors.opcua.OPCUAConnectorSchema(**data)[source]#
Bases:
BaseModelOPC UA Connector schema wrapping the server configuration.
During initialization, all variables are normalized into OPCUAVariableConfig instances, inheriting server-level subscription defaults where no overrides are given.
The type field is a discriminator for Pydantic to select this schema.
See also
The runtime class of the class OPCUAConnectorSchema schema is
openfactory.connectors.opcua.opcua_connector.OPCUAConnector.- events: Dict[str, OPCUAEventConfig] | None#
- methods: Dict[str, OPCUAMethodConfig] | None#
- model_config: ClassVar[ConfigDict] = {'extra': 'forbid'}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- model_post_init(_OPCUAConnectorSchema__context)[source]#
Normalize all server variables with subscription defaults and enforce unique keys.
- Return type:
- server: OPCUAServerConfig#
- variables: Dict[str, OPCUAVariableConfig] | None#
- class openfactory.schemas.connectors.opcua.OPCUAEventConfig(**data)[source]#
Bases:
OPCUANodeConfigConfiguration for an OPC UA event source.
- class openfactory.schemas.connectors.opcua.OPCUAMethodConfig(**data)[source]#
Bases:
OPCUANodeConfigConfiguration for an OPC UA method source.
- class openfactory.schemas.connectors.opcua.OPCUANodeConfig(**data)[source]#
Bases:
BaseModelBase class for configs that can have node_id or path to identify an OPC UA node.
- model_config: ClassVar[ConfigDict] = {'extra': 'forbid', 'frozen': True}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- model_dump(*args, **kwargs)[source]#
- !!! abstract “Usage Documentation”
[model_dump](../concepts/serialization.md#python-mode)
Generate a dictionary representation of the model, optionally specifying which fields to include or exclude.
- Parameters:
mode – The mode in which to_python should run. If mode is ‘json’, the output will only contain JSON serializable types. If mode is ‘python’, the output may contain non-JSON-serializable Python objects.
include – A set of fields to include in the output.
exclude – A set of fields to exclude from the output.
context – Additional context to pass to the serializer.
by_alias – Whether to use the field’s alias in the dictionary key if defined.
exclude_unset – Whether to exclude fields that have not been explicitly set.
exclude_defaults – Whether to exclude fields that are set to their default value.
exclude_none – Whether to exclude fields that have a value of None.
exclude_computed_fields – Whether to exclude computed fields. While this can be useful for round-tripping, it is usually recommended to use the dedicated round_trip parameter instead.
round_trip – If True, dumped values should be valid as input for non-idempotent types such as Json[T].
warnings – How to handle serialization errors. False/”none” ignores them, True/”warn” logs errors, “error” raises a [PydanticSerializationError][pydantic_core.PydanticSerializationError].
fallback – A function to call when an unknown value is encountered. If not provided, a [PydanticSerializationError][pydantic_core.PydanticSerializationError] error is raised.
serialize_as_any – Whether to serialize fields with duck-typing serialization behavior.
- Returns:
A dictionary representation of the model.
- class openfactory.schemas.connectors.opcua.OPCUAServerConfig(**data)[source]#
Bases:
BaseModelOPC UA Server configuration with variables.
- model_config: ClassVar[ConfigDict] = {'extra': 'forbid'}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- subscription: OPCUASubscriptionConfig | None#
- class openfactory.schemas.connectors.opcua.OPCUASubscriptionConfig(**data)[source]#
Bases:
BaseModelOptional subscription parameters for server or individual variables.
- class openfactory.schemas.connectors.opcua.OPCUAVariableConfig(**data)[source]#
Bases:
OPCUANodeConfigConfiguration for a single OPC UA variable.