OpenSMI-Server 0.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- opensmi/server/__init__.py +45 -0
- opensmi/server/_server.py +454 -0
- opensmi/server/access_control.py +257 -0
- opensmi/server/base_callable.py +137 -0
- opensmi/server/base_feasibility_check.py +18 -0
- opensmi/server/base_machine.py +90 -0
- opensmi/server/base_machinery_item.py +447 -0
- opensmi/server/base_method.py +57 -0
- opensmi/server/base_precondition_check.py +20 -0
- opensmi/server/base_skill.py +299 -0
- opensmi/server/base_startup_skill.py +111 -0
- opensmi/server/common.py +93 -0
- opensmi/server/config.py +124 -0
- opensmi/server/interfaces.py +280 -0
- opensmi/server/lock.py +347 -0
- opensmi/server/mixins/__init__.py +22 -0
- opensmi/server/mixins/lockable_mixin.py +37 -0
- opensmi/server/mixins/notification_mixins.py +78 -0
- opensmi/server/mixins/parent_mixin.py +79 -0
- opensmi/server/mixins/requirements_mixin.py +77 -0
- opensmi/server/mixins/skill_logic_mixins.py +470 -0
- opensmi/server/mixins/spatial_object_mixin.py +88 -0
- opensmi/server/mixins/ua_object_container_mixins.py +131 -0
- opensmi/server/mixins/ua_variable_container_mixins.py +294 -0
- opensmi/server/nodesets/Opc.Ua.Di.NodeSet2.xml +5719 -0
- opensmi/server/nodesets/Opc.Ua.Machinery.NodeSet2.xml +1713 -0
- opensmi/server/nodesets/Opc.Ua.RSL.NodeSet2.xml +601 -0
- opensmi/server/nodesets/Opc.Ua.SmartFactory.MachineSet.NodeSet2.xml +2886 -0
- opensmi/server/nodesets/Opc.Ua.SmartFactory.SkillSet.NodeSet2.xml +856 -0
- opensmi/server/nodesets/__init__.py +26 -0
- opensmi/server/nodesets/di.py +74 -0
- opensmi/server/nodesets/machinery.py +36 -0
- opensmi/server/nodesets/rsl.py +31 -0
- opensmi/server/nodesets/smart_factory_machine_set.py +52 -0
- opensmi/server/nodesets/smart_factory_skill_set.py +32 -0
- opensmi/server/notification.py +112 -0
- opensmi/server/protocols.py +165 -0
- opensmi/server/resource.py +104 -0
- opensmi/server/spatial_object.py +328 -0
- opensmi/server/ua_fsm.py +261 -0
- opensmi/server/ua_object.py +212 -0
- opensmi/server/ua_object_containers.py +181 -0
- opensmi/server/ua_variable.py +450 -0
- opensmi/server/ua_variable_containers.py +331 -0
- opensmi/server/user.py +154 -0
- opensmi_server-0.1.dist-info/METADATA +239 -0
- opensmi_server-0.1.dist-info/RECORD +50 -0
- opensmi_server-0.1.dist-info/WHEEL +5 -0
- opensmi_server-0.1.dist-info/licenses/LICENSES/MIT.txt +18 -0
- opensmi_server-0.1.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: 2026 OpenSMI Contributors
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: MIT
|
|
4
|
+
|
|
5
|
+
# !!! autogenerated code, do not change manually !!!
|
|
6
|
+
# generated on 2026-09-10 09:07:07.521942+02:00
|
|
7
|
+
|
|
8
|
+
"""Autogenerated OPC UA node identifiers."""
|
|
9
|
+
|
|
10
|
+
from typing import Final
|
|
11
|
+
|
|
12
|
+
from opensmi.core.protocols import NamespaceProvider
|
|
13
|
+
|
|
14
|
+
from .di import DiNodeIds as DiNodeIds
|
|
15
|
+
from .machinery import MachineryNodeIds as MachineryNodeIds
|
|
16
|
+
from .rsl import RSLNodeIds as RSLNodeIds
|
|
17
|
+
from .smart_factory_machine_set import SmartFactoryMachineSetNodeIds as SmartFactoryMachineSetNodeIds
|
|
18
|
+
from .smart_factory_skill_set import SmartFactorySkillSetNodeIds as SmartFactorySkillSetNodeIds
|
|
19
|
+
|
|
20
|
+
NODE_SETS: Final[dict[str, type[NamespaceProvider]]] = {
|
|
21
|
+
"http://opcfoundation.org/UA/DI/": DiNodeIds,
|
|
22
|
+
"http://opcfoundation.org/UA/Machinery/": MachineryNodeIds,
|
|
23
|
+
"http://opcfoundation.org/UA/RSL/": RSLNodeIds,
|
|
24
|
+
"http://smartfactory.de/UA/MachineSet": SmartFactoryMachineSetNodeIds,
|
|
25
|
+
"http://smartfactory.de/UA/SkillSet": SmartFactorySkillSetNodeIds,
|
|
26
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: 2026 OpenSMI Contributors
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: MIT
|
|
4
|
+
|
|
5
|
+
# !!! autogenerated code, do not change manually !!!
|
|
6
|
+
# generated on 2026-09-10 09:07:06.625370+02:00
|
|
7
|
+
|
|
8
|
+
"""Node identifiers from the OPC UA 'Di' nodeset. Auto-generated."""
|
|
9
|
+
|
|
10
|
+
from typing import ClassVar, final
|
|
11
|
+
|
|
12
|
+
from asyncua import ua
|
|
13
|
+
from opensmi.core.frozen import FrozenMeta
|
|
14
|
+
from opensmi.core.ua import NodeIdDefinition
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
@final
|
|
18
|
+
class DiNodeIds(metaclass=FrozenMeta):
|
|
19
|
+
"""Node identifiers from the OPC UA 'Di' nodeset. Auto-generated."""
|
|
20
|
+
|
|
21
|
+
FILE_NAME: ClassVar[str] = "Opc.Ua.Di.NodeSet2.xml"
|
|
22
|
+
URI: ClassVar[str] = "http://opcfoundation.org/UA/DI/"
|
|
23
|
+
VERSION: ClassVar[str] = "1.04.0"
|
|
24
|
+
REQUIRED_URIS: ClassVar[tuple[str, ...]] = ()
|
|
25
|
+
|
|
26
|
+
BaseLifetimeIndicationType = NodeIdDefinition(URI, ua.Int32(473))
|
|
27
|
+
BlockType = NodeIdDefinition(URI, ua.Int32(1003))
|
|
28
|
+
CachedLoadingType = NodeIdDefinition(URI, ua.Int32(171))
|
|
29
|
+
CheckFunctionAlarmType = NodeIdDefinition(URI, ua.Int32(15441))
|
|
30
|
+
ComponentType = NodeIdDefinition(URI, ua.Int32(15063))
|
|
31
|
+
ConfigurableObjectType = NodeIdDefinition(URI, ua.Int32(1004))
|
|
32
|
+
ConfirmationStateMachineType = NodeIdDefinition(URI, ua.Int32(307))
|
|
33
|
+
ConnectionPointType = NodeIdDefinition(URI, ua.Int32(6308))
|
|
34
|
+
DeviceHealthDiagnosticAlarmType = NodeIdDefinition(URI, ua.Int32(15143))
|
|
35
|
+
DeviceHealthEnumeration = NodeIdDefinition(URI, ua.Int32(6244))
|
|
36
|
+
DeviceType = NodeIdDefinition(URI, ua.Int32(1002))
|
|
37
|
+
DiameterIndicationType = NodeIdDefinition(URI, ua.Int32(478))
|
|
38
|
+
DirectLoadingType = NodeIdDefinition(URI, ua.Int32(153))
|
|
39
|
+
FailureAlarmType = NodeIdDefinition(URI, ua.Int32(15292))
|
|
40
|
+
FetchResultDataType = NodeIdDefinition(URI, ua.Int32(6522))
|
|
41
|
+
FileSystemLoadingType = NodeIdDefinition(URI, ua.Int32(192))
|
|
42
|
+
FunctionalGroupType = NodeIdDefinition(URI, ua.Int32(1005))
|
|
43
|
+
IDeviceHealthType = NodeIdDefinition(URI, ua.Int32(15051))
|
|
44
|
+
IOperationCounterType = NodeIdDefinition(URI, ua.Int32(480))
|
|
45
|
+
ISupportInfoType = NodeIdDefinition(URI, ua.Int32(15054))
|
|
46
|
+
ITagNameplateType = NodeIdDefinition(URI, ua.Int32(15048))
|
|
47
|
+
IVendorNameplateType = NodeIdDefinition(URI, ua.Int32(15035))
|
|
48
|
+
InstallationStateMachineType = NodeIdDefinition(URI, ua.Int32(249))
|
|
49
|
+
LengthIndicationType = NodeIdDefinition(URI, ua.Int32(477))
|
|
50
|
+
LifetimeVariableType = NodeIdDefinition(URI, ua.Int32(468))
|
|
51
|
+
LockingServicesType = NodeIdDefinition(URI, ua.Int32(6388))
|
|
52
|
+
MaintenanceRequiredAlarmType = NodeIdDefinition(URI, ua.Int32(15739))
|
|
53
|
+
NetworkType = NodeIdDefinition(URI, ua.Int32(6247))
|
|
54
|
+
NumberOfPartsIndicationType = NodeIdDefinition(URI, ua.Int32(475))
|
|
55
|
+
NumberOfUsagesIndicationType = NodeIdDefinition(URI, ua.Int32(476))
|
|
56
|
+
OffSpecAlarmType = NodeIdDefinition(URI, ua.Int32(15590))
|
|
57
|
+
PackageLoadingType = NodeIdDefinition(URI, ua.Int32(137))
|
|
58
|
+
ParameterResultDataType = NodeIdDefinition(URI, ua.Int32(6525))
|
|
59
|
+
PowerCycleStateMachineType = NodeIdDefinition(URI, ua.Int32(285))
|
|
60
|
+
PrepareForUpdateStateMachineType = NodeIdDefinition(URI, ua.Int32(213))
|
|
61
|
+
ProtocolType = NodeIdDefinition(URI, ua.Int32(1006))
|
|
62
|
+
SoftwareLoadingType = NodeIdDefinition(URI, ua.Int32(135))
|
|
63
|
+
SoftwareType = NodeIdDefinition(URI, ua.Int32(15106))
|
|
64
|
+
SoftwareUpdateType = NodeIdDefinition(URI, ua.Int32(1))
|
|
65
|
+
SoftwareVersionFileType = NodeIdDefinition(URI, ua.Int32(331))
|
|
66
|
+
SoftwareVersionType = NodeIdDefinition(URI, ua.Int32(212))
|
|
67
|
+
SubstanceVolumeIndicationType = NodeIdDefinition(URI, ua.Int32(479))
|
|
68
|
+
TimeIndicationType = NodeIdDefinition(URI, ua.Int32(474))
|
|
69
|
+
TopologyElementType = NodeIdDefinition(URI, ua.Int32(1001))
|
|
70
|
+
TransferResultDataDataType = NodeIdDefinition(URI, ua.Int32(15889))
|
|
71
|
+
TransferResultErrorDataType = NodeIdDefinition(URI, ua.Int32(15888))
|
|
72
|
+
TransferServicesType = NodeIdDefinition(URI, ua.Int32(6526))
|
|
73
|
+
UIElementType = NodeIdDefinition(URI, ua.Int32(6246))
|
|
74
|
+
UpdateBehavior = NodeIdDefinition(URI, ua.Int32(333))
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: 2026 OpenSMI Contributors
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: MIT
|
|
4
|
+
|
|
5
|
+
# !!! autogenerated code, do not change manually !!!
|
|
6
|
+
# generated on 2026-09-10 09:07:06.919671+02:00
|
|
7
|
+
|
|
8
|
+
"""Node identifiers from the OPC UA 'Machinery' nodeset. Auto-generated."""
|
|
9
|
+
|
|
10
|
+
from typing import ClassVar, final
|
|
11
|
+
|
|
12
|
+
from asyncua import ua
|
|
13
|
+
from opensmi.core.frozen import FrozenMeta
|
|
14
|
+
from opensmi.core.ua import NodeIdDefinition
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
@final
|
|
18
|
+
class MachineryNodeIds(metaclass=FrozenMeta):
|
|
19
|
+
"""Node identifiers from the OPC UA 'Machinery' nodeset. Auto-generated."""
|
|
20
|
+
|
|
21
|
+
FILE_NAME: ClassVar[str] = "Opc.Ua.Machinery.NodeSet2.xml"
|
|
22
|
+
URI: ClassVar[str] = "http://opcfoundation.org/UA/Machinery/"
|
|
23
|
+
VERSION: ClassVar[str] = "1.03.0"
|
|
24
|
+
REQUIRED_URIS: ClassVar[tuple[str, ...]] = ("http://opcfoundation.org/UA/DI/",)
|
|
25
|
+
|
|
26
|
+
IMachineTagNameplateType = NodeIdDefinition(URI, ua.Int32(1011))
|
|
27
|
+
IMachineVendorNameplateType = NodeIdDefinition(URI, ua.Int32(1010))
|
|
28
|
+
IMachineryItemVendorNameplateType = NodeIdDefinition(URI, ua.Int32(1003))
|
|
29
|
+
MachineComponentsType = NodeIdDefinition(URI, ua.Int32(1006))
|
|
30
|
+
MachineIdentificationType = NodeIdDefinition(URI, ua.Int32(1012))
|
|
31
|
+
MachineryComponentIdentificationType = NodeIdDefinition(URI, ua.Int32(1005))
|
|
32
|
+
MachineryItemIdentificationType = NodeIdDefinition(URI, ua.Int32(1004))
|
|
33
|
+
MachineryItemState_StateMachineType = NodeIdDefinition(URI, ua.Int32(1002))
|
|
34
|
+
MachineryLifetimeCounterType = NodeIdDefinition(URI, ua.Int32(1015))
|
|
35
|
+
MachineryOperationCounterType = NodeIdDefinition(URI, ua.Int32(1009))
|
|
36
|
+
MachineryOperationModeStateMachineType = NodeIdDefinition(URI, ua.Int32(1008))
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: 2026 OpenSMI Contributors
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: MIT
|
|
4
|
+
|
|
5
|
+
# !!! autogenerated code, do not change manually !!!
|
|
6
|
+
# generated on 2026-09-10 09:07:07.182737+02:00
|
|
7
|
+
|
|
8
|
+
"""Node identifiers from the OPC UA 'RSL' nodeset. Auto-generated."""
|
|
9
|
+
|
|
10
|
+
from typing import ClassVar, final
|
|
11
|
+
|
|
12
|
+
from asyncua import ua
|
|
13
|
+
from opensmi.core.frozen import FrozenMeta
|
|
14
|
+
from opensmi.core.ua import NodeIdDefinition
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
@final
|
|
18
|
+
class RSLNodeIds(metaclass=FrozenMeta):
|
|
19
|
+
"""Node identifiers from the OPC UA 'RSL' nodeset. Auto-generated."""
|
|
20
|
+
|
|
21
|
+
FILE_NAME: ClassVar[str] = "Opc.Ua.RSL.NodeSet2.xml"
|
|
22
|
+
URI: ClassVar[str] = "http://opcfoundation.org/UA/RSL/"
|
|
23
|
+
VERSION: ClassVar[str] = "1.00.0"
|
|
24
|
+
REQUIRED_URIS: ClassVar[tuple[str, ...]] = ()
|
|
25
|
+
|
|
26
|
+
CartesianFrameAngleOrientationType = NodeIdDefinition(URI, ua.Int32(2004))
|
|
27
|
+
RelativeValueType = NodeIdDefinition(URI, ua.Int32(2002))
|
|
28
|
+
RpyOrientationType = NodeIdDefinition(URI, ua.Int32(2005))
|
|
29
|
+
SpatialLocationType = NodeIdDefinition(URI, ua.Int32(2003))
|
|
30
|
+
SpatialObjectType = NodeIdDefinition(URI, ua.Int32(1002))
|
|
31
|
+
SpatialObjectsListType = NodeIdDefinition(URI, ua.Int32(1003))
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: 2026 OpenSMI Contributors
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: MIT
|
|
4
|
+
|
|
5
|
+
# !!! autogenerated code, do not change manually !!!
|
|
6
|
+
# generated on 2026-09-10 09:07:07.337553+02:00
|
|
7
|
+
|
|
8
|
+
"""Node identifiers from the OPC UA 'SmartFactoryMachineSet' nodeset. Auto-generated."""
|
|
9
|
+
|
|
10
|
+
from typing import ClassVar, final
|
|
11
|
+
|
|
12
|
+
from asyncua import ua
|
|
13
|
+
from opensmi.core.frozen import FrozenMeta
|
|
14
|
+
from opensmi.core.ua import NodeIdDefinition
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
@final
|
|
18
|
+
class SmartFactoryMachineSetNodeIds(metaclass=FrozenMeta):
|
|
19
|
+
"""Node identifiers from the OPC UA 'SmartFactoryMachineSet' nodeset. Auto-generated."""
|
|
20
|
+
|
|
21
|
+
FILE_NAME: ClassVar[str] = "Opc.Ua.SmartFactory.MachineSet.NodeSet2.xml"
|
|
22
|
+
URI: ClassVar[str] = "http://smartfactory.de/UA/MachineSet"
|
|
23
|
+
VERSION: ClassVar[str] = "1.00"
|
|
24
|
+
REQUIRED_URIS: ClassVar[tuple[str, ...]] = (
|
|
25
|
+
"http://opcfoundation.org/UA/DI/",
|
|
26
|
+
"http://opcfoundation.org/UA/RSL/",
|
|
27
|
+
"http://opcfoundation.org/UA/Machinery/",
|
|
28
|
+
"http://smartfactory.de/UA/SkillSet",
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
AlertType = NodeIdDefinition(URI, ua.Int32(1001))
|
|
32
|
+
AssetType = NodeIdDefinition(URI, ua.Int32(1002))
|
|
33
|
+
CartesianWorkspace = NodeIdDefinition(URI, ua.Int32(3003))
|
|
34
|
+
CartesianWorkspaceType = NodeIdDefinition(URI, ua.Int32(2001))
|
|
35
|
+
ComponentType = NodeIdDefinition(URI, ua.Int32(1008))
|
|
36
|
+
ContinuousSkillType = NodeIdDefinition(URI, ua.Int32(1016))
|
|
37
|
+
CylindricalWorkspace = NodeIdDefinition(URI, ua.Int32(3004))
|
|
38
|
+
CylindricalWorkspaceType = NodeIdDefinition(URI, ua.Int32(2002))
|
|
39
|
+
FiniteSkillType = NodeIdDefinition(URI, ua.Int32(1015))
|
|
40
|
+
MachineType = NodeIdDefinition(URI, ua.Int32(1009))
|
|
41
|
+
MachineryItemType = NodeIdDefinition(URI, ua.Int32(1007))
|
|
42
|
+
MonitoringType = NodeIdDefinition(URI, ua.Int32(1006))
|
|
43
|
+
NotificationType = NodeIdDefinition(URI, ua.Int32(1003))
|
|
44
|
+
ResourceItemIdentificationType = NodeIdDefinition(URI, ua.Int32(1004))
|
|
45
|
+
ResourceType = NodeIdDefinition(URI, ua.Int32(1011))
|
|
46
|
+
ResourcesType = NodeIdDefinition(URI, ua.Int32(1005))
|
|
47
|
+
SkillElementType = NodeIdDefinition(URI, ua.Int32(1013))
|
|
48
|
+
SkillStateMachineType = NodeIdDefinition(URI, ua.Int32(1014))
|
|
49
|
+
UserType = NodeIdDefinition(URI, ua.Int32(1023))
|
|
50
|
+
UsersType = NodeIdDefinition(URI, ua.Int32(1024))
|
|
51
|
+
Workspace = NodeIdDefinition(URI, ua.Int32(3000))
|
|
52
|
+
WorkspaceType = NodeIdDefinition(URI, ua.Int32(2000))
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: 2026 OpenSMI Contributors
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: MIT
|
|
4
|
+
|
|
5
|
+
# !!! autogenerated code, do not change manually !!!
|
|
6
|
+
# generated on 2026-09-10 09:07:07.434938+02:00
|
|
7
|
+
|
|
8
|
+
"""Node identifiers from the OPC UA 'SmartFactorySkillSet' nodeset. Auto-generated."""
|
|
9
|
+
|
|
10
|
+
from typing import ClassVar, final
|
|
11
|
+
|
|
12
|
+
from asyncua import ua
|
|
13
|
+
from opensmi.core.frozen import FrozenMeta
|
|
14
|
+
from opensmi.core.ua import NodeIdDefinition
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
@final
|
|
18
|
+
class SmartFactorySkillSetNodeIds(metaclass=FrozenMeta):
|
|
19
|
+
"""Node identifiers from the OPC UA 'SmartFactorySkillSet' nodeset. Auto-generated."""
|
|
20
|
+
|
|
21
|
+
FILE_NAME: ClassVar[str] = "Opc.Ua.SmartFactory.SkillSet.NodeSet2.xml"
|
|
22
|
+
URI: ClassVar[str] = "http://smartfactory.de/UA/SkillSet"
|
|
23
|
+
VERSION: ClassVar[str] = "1.00"
|
|
24
|
+
REQUIRED_URIS: ClassVar[tuple[str, ...]] = ("http://opcfoundation.org/UA/DI/",)
|
|
25
|
+
|
|
26
|
+
BaseMethodType = NodeIdDefinition(URI, ua.Int32(1004))
|
|
27
|
+
BaseSkillElementType = NodeIdDefinition(URI, ua.Int32(1000))
|
|
28
|
+
BaseSkillType = NodeIdDefinition(URI, ua.Int32(1001))
|
|
29
|
+
CurrencyItemType = NodeIdDefinition(URI, ua.Int32(2000))
|
|
30
|
+
IMetricsType = NodeIdDefinition(URI, ua.Int32(1003))
|
|
31
|
+
MethodSetType = NodeIdDefinition(URI, ua.Int32(1005))
|
|
32
|
+
SkillSetType = NodeIdDefinition(URI, ua.Int32(1002))
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: 2026 OpenSMI Contributors
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: MIT
|
|
4
|
+
|
|
5
|
+
"""Interface and implementation for OPC UA based logging.
|
|
6
|
+
|
|
7
|
+
- There is always at least one actual OPC UA logger for the machine (`BaseMachine`).
|
|
8
|
+
- Skills (`BaseSkill`) and Methods (`BaseMethod`) never have their own logger and forward them to their parent.
|
|
9
|
+
- Components (`BaseMachineryItem`) can optionally have their own or forward them to their parent.
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
from collections.abc import AsyncGenerator
|
|
13
|
+
|
|
14
|
+
from asyncua import ua
|
|
15
|
+
from asyncua.server.event_generator import EventGenerator
|
|
16
|
+
from opensmi.core.lifecycle_mixin import lifecycle
|
|
17
|
+
from typing_extensions import override
|
|
18
|
+
|
|
19
|
+
from opensmi.server.base_machinery_item import BaseMachineryItem
|
|
20
|
+
from opensmi.server.interfaces import AbstractUaLogger, AbstractUaObject
|
|
21
|
+
from opensmi.server.mixins.parent_mixin import ParentMixin
|
|
22
|
+
from opensmi.server.nodesets import SmartFactoryMachineSetNodeIds
|
|
23
|
+
from opensmi.server.ua_object import UaObject, UaObjectDefinition
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class Notification(UaObject, ParentMixin[BaseMachineryItem], AbstractUaLogger):
|
|
27
|
+
"""Implementation of the OPC UA Logging interface for `BaseMachine` and optionally `BaseMachineryItem`."""
|
|
28
|
+
|
|
29
|
+
_ua_info_event_gen: EventGenerator
|
|
30
|
+
_ua_alarm_event_gen: EventGenerator
|
|
31
|
+
|
|
32
|
+
def __init__(self) -> None:
|
|
33
|
+
"""*Cooperative* constructor."""
|
|
34
|
+
super().__init__(name="Notification")
|
|
35
|
+
|
|
36
|
+
@override
|
|
37
|
+
async def _get_definition(self) -> UaObjectDefinition:
|
|
38
|
+
return UaObjectDefinition(
|
|
39
|
+
object_type=SmartFactoryMachineSetNodeIds.NotificationType,
|
|
40
|
+
namespace_uri=SmartFactoryMachineSetNodeIds,
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
@lifecycle
|
|
44
|
+
async def lifecycle_notification(self) -> AsyncGenerator[None]:
|
|
45
|
+
# setup event generators
|
|
46
|
+
self._ua_info_event_gen = await self.server.ua_server.get_event_generator(
|
|
47
|
+
etype=ua.object_ids.ObjectIds.BaseEventType,
|
|
48
|
+
emitting_node=self.ua_node.nodeid, # type: ignore
|
|
49
|
+
)
|
|
50
|
+
self._ua_alarm_event_gen = await self.server.ua_server.get_event_generator(
|
|
51
|
+
etype=self.server.ua_get_node_id(SmartFactoryMachineSetNodeIds.AlertType),
|
|
52
|
+
emitting_node=self.ua_node.nodeid, # type: ignore
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
# TODO(CaHa): Fix/Implement? event historizing
|
|
56
|
+
# await self.server.ua_server.historize_node_event(self.ua_node, count=1000)
|
|
57
|
+
|
|
58
|
+
yield
|
|
59
|
+
# no shutdown
|
|
60
|
+
|
|
61
|
+
async def _generate_info_event(
|
|
62
|
+
self, *, msg: str, severity: int = 0, source: AbstractUaObject | None = None
|
|
63
|
+
) -> None:
|
|
64
|
+
self.logger.debug("Generating info event", msg=msg, severity=severity, source=source)
|
|
65
|
+
|
|
66
|
+
# TODO(CaHa): Not properly supported in asyncua
|
|
67
|
+
# if source is None:
|
|
68
|
+
# self._ua_info_event_gen.event.SourceNode = self.parent.ua_node.nodeid
|
|
69
|
+
# self._ua_info_event_gen.event.SourceName = self.parent.name
|
|
70
|
+
# else:
|
|
71
|
+
# self._ua_info_event_gen.event.SourceNode = source.ua_node.nodeid
|
|
72
|
+
# self._ua_info_event_gen.event.SourceName = source.name
|
|
73
|
+
|
|
74
|
+
self._ua_info_event_gen.event.Severity = severity
|
|
75
|
+
self._ua_info_event_gen.event.Message = ua.LocalizedText(msg)
|
|
76
|
+
await self._ua_info_event_gen.trigger()
|
|
77
|
+
|
|
78
|
+
async def _generate_alert_event(
|
|
79
|
+
self, *, msg: str, severity: int = 0, code: str = "", source: AbstractUaObject | None = None
|
|
80
|
+
) -> None:
|
|
81
|
+
self.logger.debug("Generating alert event", msg=msg, severity=severity, code=code, source=source)
|
|
82
|
+
|
|
83
|
+
# TODO(CaHa): Not properly supported in asyncua
|
|
84
|
+
# if source is None:
|
|
85
|
+
# self._ua_alarm_event_gen.event.SourceNode = self.parent.ua_node.nodeid
|
|
86
|
+
# self._ua_alarm_event_gen.event.SourceName = self.parent.name
|
|
87
|
+
# else:
|
|
88
|
+
# self._ua_alarm_event_gen.event.SourceNode = source.ua_node.nodeid
|
|
89
|
+
# self._ua_alarm_event_gen.event.SourceName = source.name
|
|
90
|
+
|
|
91
|
+
self._ua_alarm_event_gen.event.Severity = severity
|
|
92
|
+
# TODO(CaHa): remove "|||" in message work-around when no longer required (asyncua client problem)
|
|
93
|
+
self._ua_alarm_event_gen.event.Message = ua.LocalizedText(f"{msg}|||{code}")
|
|
94
|
+
self._ua_alarm_event_gen.event.ErrorCode = code
|
|
95
|
+
await self._ua_alarm_event_gen.trigger()
|
|
96
|
+
|
|
97
|
+
@override
|
|
98
|
+
async def ua_log_info(self, msg: str, *, severity: int = 0, source: AbstractUaObject | None = None) -> None:
|
|
99
|
+
self.logger.info("UA Log", msg=msg, severity=severity, source=source)
|
|
100
|
+
await self._generate_info_event(msg=msg, severity=severity, source=source)
|
|
101
|
+
|
|
102
|
+
@override
|
|
103
|
+
async def ua_log_warning(self, msg: str, *, severity: int = 555, source: AbstractUaObject | None = None) -> None:
|
|
104
|
+
self.logger.warning("UA Log", msg=msg, severity=severity, source=source)
|
|
105
|
+
await self._generate_info_event(msg=msg, severity=severity, source=source)
|
|
106
|
+
|
|
107
|
+
@override
|
|
108
|
+
async def ua_log_error(
|
|
109
|
+
self, msg: str, *, severity: int = 999, code: str = "", source: AbstractUaObject | None = None
|
|
110
|
+
) -> None:
|
|
111
|
+
self.logger.error("UA Log", msg=msg, severity=severity, code=code, source=source)
|
|
112
|
+
await self._generate_alert_event(msg=msg, severity=severity, code=code, source=source)
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: 2026 OpenSMI Contributors
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: MIT
|
|
4
|
+
|
|
5
|
+
from typing import TYPE_CHECKING, Protocol
|
|
6
|
+
|
|
7
|
+
from asyncua import ua
|
|
8
|
+
|
|
9
|
+
if TYPE_CHECKING:
|
|
10
|
+
import structlog
|
|
11
|
+
from asyncua.common.node import Node
|
|
12
|
+
from asyncua.crypto.permission_rules import UserRole
|
|
13
|
+
from asyncua.server.internal_session import SessionState
|
|
14
|
+
|
|
15
|
+
from opensmi.server.base_machine import BaseMachine
|
|
16
|
+
from opensmi.server.lock import Lock
|
|
17
|
+
from opensmi.server.ua_object import UaObject
|
|
18
|
+
from opensmi.server.ua_variable_containers import Monitoring
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class UserIdentity(Protocol):
|
|
22
|
+
"""Provides immutable user identity information."""
|
|
23
|
+
|
|
24
|
+
@property
|
|
25
|
+
def name(self) -> str:
|
|
26
|
+
"""Unique username."""
|
|
27
|
+
...
|
|
28
|
+
|
|
29
|
+
@property
|
|
30
|
+
def full_name(self) -> str:
|
|
31
|
+
"""Absolute username."""
|
|
32
|
+
...
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
class UserAuthentication(UserIdentity, Protocol):
|
|
36
|
+
"""Provides user authentication."""
|
|
37
|
+
|
|
38
|
+
def check_password(self, password: bytes | str | None) -> bool:
|
|
39
|
+
"""Return whether ``password`` authenticates the user."""
|
|
40
|
+
...
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
class UserAuthorization(UserIdentity, Protocol):
|
|
44
|
+
"""Represents a user's authorization state."""
|
|
45
|
+
|
|
46
|
+
@property
|
|
47
|
+
def current_access_level(self) -> int:
|
|
48
|
+
"""Current access level of the user.
|
|
49
|
+
|
|
50
|
+
Read/write. The value must be between 0 and ``maximum_access_level``.
|
|
51
|
+
"""
|
|
52
|
+
...
|
|
53
|
+
|
|
54
|
+
@current_access_level.setter
|
|
55
|
+
def current_access_level(self, access_level: int) -> None: ...
|
|
56
|
+
|
|
57
|
+
@property
|
|
58
|
+
def maximum_access_level(self) -> int:
|
|
59
|
+
"""Maximum access level the user may be assigned."""
|
|
60
|
+
...
|
|
61
|
+
|
|
62
|
+
@property
|
|
63
|
+
def priority(self) -> int:
|
|
64
|
+
"""Authorization priority.
|
|
65
|
+
|
|
66
|
+
Read-only. Higher values take precedence when resolving authorization conflicts.
|
|
67
|
+
"""
|
|
68
|
+
...
|
|
69
|
+
|
|
70
|
+
@property
|
|
71
|
+
def role(self) -> "UserRole":
|
|
72
|
+
"""The user's ``asyncua`` role.
|
|
73
|
+
|
|
74
|
+
Read-only. Always ``UserRole.User`` for normal users. Internal user uses ``UserRole.Admin``.
|
|
75
|
+
"""
|
|
76
|
+
...
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
class UserPresence(UserIdentity, Protocol):
|
|
80
|
+
"""Tracks whether the user currently has active sessions."""
|
|
81
|
+
|
|
82
|
+
@property
|
|
83
|
+
def present(self) -> bool:
|
|
84
|
+
"""Whether the user currently has at least one active session."""
|
|
85
|
+
...
|
|
86
|
+
|
|
87
|
+
@property
|
|
88
|
+
def sessions(self) -> set["SessionProtocol"]:
|
|
89
|
+
"""Active sessions (Read-only)."""
|
|
90
|
+
...
|
|
91
|
+
|
|
92
|
+
async def add_session(self, session: "SessionProtocol") -> None:
|
|
93
|
+
"""Register an active session for the user."""
|
|
94
|
+
...
|
|
95
|
+
|
|
96
|
+
async def remove_session(self, session: "SessionProtocol") -> None:
|
|
97
|
+
"""Unregister a previously added active session."""
|
|
98
|
+
...
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
class UserProtocol(UserAuthentication, UserAuthorization, UserPresence, Protocol):
|
|
102
|
+
"""Complete public ``User`` interface."""
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
class SessionProtocol(Protocol):
|
|
106
|
+
name: str
|
|
107
|
+
user: "UserProtocol" # This is different from normal asyncua, but correct in our case
|
|
108
|
+
state: "SessionState"
|
|
109
|
+
|
|
110
|
+
async def close_session(self, delete_subs: bool = True) -> None: ...
|
|
111
|
+
|
|
112
|
+
def is_activated(self) -> bool: ...
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
class Lockable(Protocol):
|
|
116
|
+
@property
|
|
117
|
+
def lock(self) -> "Lock": ...
|
|
118
|
+
|
|
119
|
+
def access_allowed(self, user: UserProtocol) -> bool: ...
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
class _HasLogger(Protocol):
|
|
123
|
+
@property
|
|
124
|
+
def logger(self) -> "structlog.stdlib.BoundLogger": ...
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
class _HasUaNode(Protocol):
|
|
128
|
+
@property
|
|
129
|
+
def ua_node(self) -> "Node": ...
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
class _HasMonitoring(Protocol):
|
|
133
|
+
@property
|
|
134
|
+
def monitoring(self) -> "Monitoring": ...
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
class _HasParent(Protocol):
|
|
138
|
+
@property
|
|
139
|
+
def parent(self) -> "UaObject": ...
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
class _HasRootParent(Protocol):
|
|
143
|
+
@property
|
|
144
|
+
def root_parent(self) -> "BaseMachine": ...
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
class _HasName(Protocol):
|
|
148
|
+
@property
|
|
149
|
+
def name(self) -> str: ...
|
|
150
|
+
|
|
151
|
+
@property
|
|
152
|
+
def full_name(self) -> str: ...
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
class UaObjectProtocol(Lockable, _HasLogger, _HasUaNode, _HasRootParent, _HasParent, _HasName, Protocol):
|
|
156
|
+
"""Full `UaObject` interface."""
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
class HasLocalizedText(Protocol):
|
|
160
|
+
"""Protocol for objects that provide an OPC UA localized text representation."""
|
|
161
|
+
|
|
162
|
+
@property
|
|
163
|
+
def localized_text(self) -> "ua.LocalizedText":
|
|
164
|
+
"""Return the OPC UA localized text representation."""
|
|
165
|
+
...
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: 2026 OpenSMI Contributors
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: MIT
|
|
4
|
+
|
|
5
|
+
"""Everything related to resources."""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
from collections.abc import AsyncGenerator
|
|
10
|
+
from dataclasses import dataclass
|
|
11
|
+
from typing import TYPE_CHECKING
|
|
12
|
+
|
|
13
|
+
from asyncua import ua
|
|
14
|
+
from opensmi.core.lifecycle_mixin import lifecycle
|
|
15
|
+
from typing_extensions import override
|
|
16
|
+
|
|
17
|
+
from opensmi.server.mixins.parent_mixin import ParentMixin
|
|
18
|
+
from opensmi.server.mixins.ua_variable_container_mixins import AttributesMixin, IdentificationMixin
|
|
19
|
+
from opensmi.server.nodesets import SmartFactoryMachineSetNodeIds
|
|
20
|
+
from opensmi.server.ua_object import UaObject, UaObjectDefinition
|
|
21
|
+
from opensmi.server.ua_variable import UaVariable
|
|
22
|
+
from opensmi.server.ua_variable_containers import Attributes, Identification
|
|
23
|
+
|
|
24
|
+
if TYPE_CHECKING:
|
|
25
|
+
from opensmi.server.ua_object_containers import Resources as Resources
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
@dataclass(frozen=True, kw_only=True, slots=True)
|
|
29
|
+
class ResourceDefinition:
|
|
30
|
+
"""Definition of a `Resource`. Will be used to set OPC UA variables of a resource."""
|
|
31
|
+
|
|
32
|
+
asset_id: str
|
|
33
|
+
component_name: str
|
|
34
|
+
resource_class: str
|
|
35
|
+
form: str = ""
|
|
36
|
+
color: str = ""
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
class ResourceAttributes(Attributes):
|
|
40
|
+
"""Base attributes for `Resource`."""
|
|
41
|
+
|
|
42
|
+
Color = UaVariable(initial_value="")
|
|
43
|
+
Form = UaVariable(initial_value="")
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
class ResourceIdentification(Identification):
|
|
47
|
+
"""Identification for `Resource`."""
|
|
48
|
+
|
|
49
|
+
AssetId: UaVariable[str]
|
|
50
|
+
"""Asset ID of this resource."""
|
|
51
|
+
ComponentName: UaVariable[ua.LocalizedText]
|
|
52
|
+
"""Human-readable (component) name of this resource."""
|
|
53
|
+
ResourceClass: UaVariable[str]
|
|
54
|
+
"""Type ('ResourceClass') of this resource, i.e. 'Cab', 'Trailer' etc."""
|
|
55
|
+
|
|
56
|
+
@override
|
|
57
|
+
async def _get_definition(self) -> UaObjectDefinition:
|
|
58
|
+
return UaObjectDefinition(
|
|
59
|
+
object_type=SmartFactoryMachineSetNodeIds.ResourceItemIdentificationType,
|
|
60
|
+
namespace_uri=SmartFactoryMachineSetNodeIds,
|
|
61
|
+
)
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
class Resource(
|
|
65
|
+
UaObject,
|
|
66
|
+
IdentificationMixin[ResourceIdentification],
|
|
67
|
+
ParentMixin["Resources"],
|
|
68
|
+
AttributesMixin[ResourceAttributes],
|
|
69
|
+
):
|
|
70
|
+
"""Base class for all resources."""
|
|
71
|
+
|
|
72
|
+
def __init__(self, *, definition: ResourceDefinition) -> None:
|
|
73
|
+
"""*Cooperative* constructor."""
|
|
74
|
+
assert definition is not None
|
|
75
|
+
assert len(definition.component_name) > 1, f"component_name {definition.component_name} is too short"
|
|
76
|
+
assert len(definition.resource_class) > 1, f"resource_class {definition.resource_class} is too short"
|
|
77
|
+
super().__init__(name=definition.component_name)
|
|
78
|
+
self._resource_class: str = definition.resource_class
|
|
79
|
+
self._definition = definition
|
|
80
|
+
|
|
81
|
+
@override
|
|
82
|
+
async def _get_definition(self) -> UaObjectDefinition:
|
|
83
|
+
return UaObjectDefinition(object_type=SmartFactoryMachineSetNodeIds.ResourceType)
|
|
84
|
+
|
|
85
|
+
@override
|
|
86
|
+
async def _write_identification(self) -> None:
|
|
87
|
+
await self.identification.AssetId.write(self._definition.asset_id)
|
|
88
|
+
await self.identification.ComponentName.write(ua.LocalizedText(self._definition.component_name, "en-US"))
|
|
89
|
+
await self.identification.ResourceClass.write(self._definition.resource_class)
|
|
90
|
+
|
|
91
|
+
@lifecycle(after=AttributesMixin.lifecycle_attributes)
|
|
92
|
+
async def lifecycle_resource(self) -> AsyncGenerator[None]:
|
|
93
|
+
"""Initialize the OPC UA variables based on the definition."""
|
|
94
|
+
await self.attributes.Color.write(self._definition.color)
|
|
95
|
+
await self.attributes.Form.write(self._definition.form)
|
|
96
|
+
|
|
97
|
+
del self._definition # no longer required
|
|
98
|
+
yield
|
|
99
|
+
# no shutdown
|
|
100
|
+
|
|
101
|
+
@property
|
|
102
|
+
def resource_class(self) -> str:
|
|
103
|
+
"""Return the class of the resource, i.e. 'Cab', 'Trailer' etc."""
|
|
104
|
+
return self._resource_class
|