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.
Files changed (50) hide show
  1. opensmi/server/__init__.py +45 -0
  2. opensmi/server/_server.py +454 -0
  3. opensmi/server/access_control.py +257 -0
  4. opensmi/server/base_callable.py +137 -0
  5. opensmi/server/base_feasibility_check.py +18 -0
  6. opensmi/server/base_machine.py +90 -0
  7. opensmi/server/base_machinery_item.py +447 -0
  8. opensmi/server/base_method.py +57 -0
  9. opensmi/server/base_precondition_check.py +20 -0
  10. opensmi/server/base_skill.py +299 -0
  11. opensmi/server/base_startup_skill.py +111 -0
  12. opensmi/server/common.py +93 -0
  13. opensmi/server/config.py +124 -0
  14. opensmi/server/interfaces.py +280 -0
  15. opensmi/server/lock.py +347 -0
  16. opensmi/server/mixins/__init__.py +22 -0
  17. opensmi/server/mixins/lockable_mixin.py +37 -0
  18. opensmi/server/mixins/notification_mixins.py +78 -0
  19. opensmi/server/mixins/parent_mixin.py +79 -0
  20. opensmi/server/mixins/requirements_mixin.py +77 -0
  21. opensmi/server/mixins/skill_logic_mixins.py +470 -0
  22. opensmi/server/mixins/spatial_object_mixin.py +88 -0
  23. opensmi/server/mixins/ua_object_container_mixins.py +131 -0
  24. opensmi/server/mixins/ua_variable_container_mixins.py +294 -0
  25. opensmi/server/nodesets/Opc.Ua.Di.NodeSet2.xml +5719 -0
  26. opensmi/server/nodesets/Opc.Ua.Machinery.NodeSet2.xml +1713 -0
  27. opensmi/server/nodesets/Opc.Ua.RSL.NodeSet2.xml +601 -0
  28. opensmi/server/nodesets/Opc.Ua.SmartFactory.MachineSet.NodeSet2.xml +2886 -0
  29. opensmi/server/nodesets/Opc.Ua.SmartFactory.SkillSet.NodeSet2.xml +856 -0
  30. opensmi/server/nodesets/__init__.py +26 -0
  31. opensmi/server/nodesets/di.py +74 -0
  32. opensmi/server/nodesets/machinery.py +36 -0
  33. opensmi/server/nodesets/rsl.py +31 -0
  34. opensmi/server/nodesets/smart_factory_machine_set.py +52 -0
  35. opensmi/server/nodesets/smart_factory_skill_set.py +32 -0
  36. opensmi/server/notification.py +112 -0
  37. opensmi/server/protocols.py +165 -0
  38. opensmi/server/resource.py +104 -0
  39. opensmi/server/spatial_object.py +328 -0
  40. opensmi/server/ua_fsm.py +261 -0
  41. opensmi/server/ua_object.py +212 -0
  42. opensmi/server/ua_object_containers.py +181 -0
  43. opensmi/server/ua_variable.py +450 -0
  44. opensmi/server/ua_variable_containers.py +331 -0
  45. opensmi/server/user.py +154 -0
  46. opensmi_server-0.1.dist-info/METADATA +239 -0
  47. opensmi_server-0.1.dist-info/RECORD +50 -0
  48. opensmi_server-0.1.dist-info/WHEEL +5 -0
  49. opensmi_server-0.1.dist-info/licenses/LICENSES/MIT.txt +18 -0
  50. opensmi_server-0.1.dist-info/top_level.txt +1 -0
@@ -0,0 +1,294 @@
1
+ # SPDX-FileCopyrightText: 2026 OpenSMI Contributors
2
+ #
3
+ # SPDX-License-Identifier: MIT
4
+
5
+ """Generic mixins for providing an `UaObject` with `Attributes`, `Monitoring`, `ParameterSet` and `FinalResultData`."""
6
+
7
+ from abc import abstractmethod
8
+ from collections.abc import AsyncGenerator, Mapping
9
+ from typing import Any, Generic, cast
10
+
11
+ import structlog
12
+ from asyncua import ua
13
+ from opensmi.core.errors import ValidationError
14
+ from opensmi.core.lifecycle_mixin import lifecycle
15
+ from opensmi.core.meta import resolve_generic_arguments
16
+ from opensmi.core.mixin_helpers import get_logger
17
+ from typing_extensions import TypeVar, deprecated
18
+
19
+ from opensmi.server.ua_variable import UaVariable
20
+ from opensmi.server.ua_variable_containers import (
21
+ Attributes,
22
+ FinalResultData,
23
+ Identification,
24
+ MachineryComponentIdentification,
25
+ Monitoring,
26
+ ParameterSet,
27
+ init_container,
28
+ )
29
+
30
+ _LOGGER = structlog.get_logger("opensmi." + __name__)
31
+
32
+ AttributesType = TypeVar("AttributesType", bound="Attributes")
33
+ """Attributes type for the `UaObject`. Defaults to base `Attributes` type."""
34
+ MonitoringType = TypeVar("MonitoringType", bound="Monitoring")
35
+ """Monitoring type for the `UaObject`. Defaults to base `Monitoring` type."""
36
+ ParameterSetType = TypeVar("ParameterSetType", bound="ParameterSet")
37
+ """ParameterSet type for the `UaObject`. Defaults to base `ParameterSet` type."""
38
+ FinalResultDataType = TypeVar("FinalResultDataType", bound="FinalResultData")
39
+ """FinalResultData type for the `UaObject`. Defaults to base `FinalResultData` type."""
40
+ IdentificationType = TypeVar("IdentificationType", bound="Identification")
41
+ """Identification type for the `UaObject`. Defaults to base `Identification` type."""
42
+
43
+
44
+ def _type_or_default(cls: type, *, default: type) -> type:
45
+ """Return type checked type of ``cls`` or ``default`` if cls is ``NoneType``.
46
+
47
+ :raises TypeError: if ``cls`` is no subclass of ``default``.
48
+ """
49
+ type_ = default if cls is type(None) else cls
50
+ if not issubclass(type_, default):
51
+ msg = f"{type_.__name__} must inherit from {default.__name__}"
52
+ raise TypeError(msg)
53
+ return type_
54
+
55
+
56
+ class AttributesMixin(Generic[AttributesType]):
57
+ """Mixin for `UaObject` with attributes."""
58
+
59
+ __attributes: AttributesType | None = None
60
+
61
+ @lifecycle
62
+ async def lifecycle_attributes(self) -> AsyncGenerator[None]:
63
+ """Initialize the attributes `UaVariableContainer`."""
64
+ await init_container(parent=self, container=self.attributes, exist_ok=True)
65
+ yield
66
+ # no shutdown
67
+
68
+ @property
69
+ def attributes(self) -> AttributesType:
70
+ """Return the attributes `UaVariableContainer`. Read-only property."""
71
+ if self.__attributes is None:
72
+ type_ = getattr(self, "_attributes_type", Attributes)
73
+ self.__attributes = cast(AttributesType, type_())
74
+ get_logger(self, _LOGGER).debug("Instantiated Container", type=type_)
75
+ return self.__attributes
76
+
77
+ def __init_subclass__(cls, **kwargs) -> None:
78
+ """Extract type for attributes."""
79
+ super().__init_subclass__(**kwargs)
80
+
81
+ result: tuple[type, ...] | None = resolve_generic_arguments(cls, AttributesMixin)
82
+ if result is None or any(isinstance(x, TypeVar) for x in result): # skip still-generic classes
83
+ return
84
+
85
+ cls._attributes_type = _type_or_default(result[0], default=Attributes)
86
+
87
+
88
+ class MonitoringMixin(Generic[MonitoringType]):
89
+ """Mixin for `UaObject` with monitoring."""
90
+
91
+ __monitoring: MonitoringType | None = None
92
+
93
+ @lifecycle
94
+ async def lifecycle_monitoring(self) -> AsyncGenerator[None]:
95
+ """Initialize the monitoring `UaVariableContainer`."""
96
+ await init_container(parent=self, container=self.monitoring, exist_ok=True)
97
+ yield
98
+ # no shutdown
99
+
100
+ @property
101
+ def monitoring(self) -> MonitoringType:
102
+ """Return the monitoring `UaVariableContainer` . Read-only property."""
103
+ if self.__monitoring is None:
104
+ type_ = getattr(self, "_monitoring_type", Monitoring)
105
+ self.__monitoring = cast(MonitoringType, type_())
106
+ get_logger(self, _LOGGER).debug("Instantiated Container", type=type_)
107
+ return self.__monitoring
108
+
109
+ @deprecated("Please use the typed .monitoring.<name>.read() or untyped monitoring.read_all() instead")
110
+ async def read_monitoring(self) -> Mapping[str, Any]:
111
+ """Read all monitoring values and returns them as a dictionary.
112
+
113
+ Keys are the display name of OPC UA nodes, values the corresponding values.
114
+ """
115
+ return await self.monitoring.read_all()
116
+
117
+ def __init_subclass__(cls, **kwargs) -> None:
118
+ """Extract type for monitoring."""
119
+ super().__init_subclass__(**kwargs)
120
+
121
+ result: tuple[type, ...] | None = resolve_generic_arguments(cls, MonitoringMixin)
122
+ if result is None or any(isinstance(x, TypeVar) for x in result): # skip still-generic classes
123
+ return
124
+
125
+ cls._monitoring_type = _type_or_default(result[0], default=Monitoring)
126
+
127
+
128
+ class ParameterSetMixin(Generic[ParameterSetType]):
129
+ """Mixin for `UaObject` with parameters."""
130
+
131
+ __parameter_set: ParameterSetType | None = None
132
+
133
+ @lifecycle
134
+ async def lifecycle_parameter_set(self) -> AsyncGenerator[None]:
135
+ """Initialize the monitoring `UaVariableContainer`."""
136
+ await init_container(parent=self, container=self.parameter_set, exist_ok=True)
137
+ yield
138
+ # no shutdown
139
+
140
+ @property
141
+ def parameter_set(self) -> ParameterSetType:
142
+ """Return the parameter set `UaVariableContainer` . Read-only property."""
143
+ if self.__parameter_set is None:
144
+ type_ = getattr(self, "_parameter_set_type", ParameterSet)
145
+ self.__parameter_set = cast(ParameterSetType, type_())
146
+ get_logger(self, _LOGGER).debug("Instantiated Container", type=type_)
147
+ return self.__parameter_set
148
+
149
+ @deprecated("Please use the typed .parameter_set.<name>.read() instead")
150
+ async def read_parameter(self, name: str) -> Any:
151
+ """Read the value of the parameter with the given name."""
152
+ return await self.parameter_set[name].read()
153
+
154
+ @deprecated("Please use the typed .parameter_set.<name>.read() or untyped parameter_set.read_all() instead")
155
+ async def read_parameters(self) -> Mapping[str, Any]:
156
+ """Read all parameters and return them as a dictionary.
157
+
158
+ Keys are the display name of OPC UA nodes, values the corresponding values.
159
+ """
160
+ return await self.parameter_set.read_all()
161
+
162
+ @deprecated(
163
+ "Please use the typed .parameter_set.<name>.write(<value>) instead or untyped parameter_set.write_all()"
164
+ )
165
+ async def write_parameters(self, parameters: Mapping[str, Any]) -> None:
166
+ """Write the parameters of according to given dictionary.
167
+
168
+ Keys of the dictionary are matched to the browse name of the OPC UA node.
169
+ Values of the dictionary are written to the matched OPC UA node.
170
+ """
171
+ await self.parameter_set.write_all(parameters)
172
+
173
+ @deprecated("Please use the typed .parameter_set.<name>.write(<value>) instead")
174
+ async def write_parameter(self, name: str, value: Any) -> None:
175
+ """Write given value to parameter with given name."""
176
+ await self.parameter_set[name].write(value)
177
+
178
+ def __init_subclass__(cls, **kwargs) -> None:
179
+ """Extract type for monitoring."""
180
+ super().__init_subclass__(**kwargs)
181
+
182
+ result: tuple[type, ...] | None = resolve_generic_arguments(cls, ParameterSetMixin)
183
+ if result is None or any(isinstance(x, TypeVar) for x in result): # skip still-generic classes
184
+ return
185
+
186
+ cls._parameter_set_type: type = _type_or_default(result[0], default=ParameterSet)
187
+
188
+
189
+ class FinalResultDataMixin(Generic[FinalResultDataType]):
190
+ """Mixin for `UaObject` with final result data."""
191
+
192
+ __final_result_data: FinalResultDataType | None = None
193
+
194
+ @lifecycle
195
+ async def lifecycle_final_result_data(self) -> AsyncGenerator[None]:
196
+ """Initialize the final result data `UaVariableContainer`."""
197
+ await init_container(parent=self, container=self.final_result_data, exist_ok=True)
198
+ yield
199
+ # no shutdown
200
+
201
+ @property
202
+ def final_result_data(self) -> FinalResultDataType:
203
+ """Return the final result data `UaVariableContainer` . Read-only property."""
204
+ if self.__final_result_data is None:
205
+ type_ = getattr(self, "_final_result_data_type", FinalResultData)
206
+ self.__final_result_data = cast(FinalResultDataType, type_())
207
+ get_logger(self, _LOGGER).debug("Instantiated Container", type=type_)
208
+ return self.__final_result_data
209
+
210
+ @deprecated("Please use the typed .final_result_data.<name>.read() instead")
211
+ async def read_result(self, name: str) -> Any:
212
+ """Read the result of given variable name."""
213
+ return await self.final_result_data[name].read_optional()
214
+
215
+ @deprecated("Please use the typed .final_result_data.<name>.read() or untyped final_result_data.read_all() instead")
216
+ async def read_results(self) -> Mapping[str, Any]:
217
+ """Read all results and provide them as a mapping from result name to value."""
218
+ return await self.final_result_data.read_all()
219
+
220
+ def __init_subclass__(cls, **kwargs) -> None:
221
+ """Extract type for monitoring."""
222
+ super().__init_subclass__(**kwargs)
223
+
224
+ result: tuple[type, ...] | None = resolve_generic_arguments(cls, FinalResultDataMixin)
225
+ if result is None or any(isinstance(x, TypeVar) for x in result): # skip still-generic classes
226
+ return
227
+
228
+ cls._final_result_data_type = _type_or_default(result[0], default=FinalResultData)
229
+
230
+
231
+ class IdentificationMixin(Generic[IdentificationType]):
232
+ """Mixin for `UaObject` with final result data."""
233
+
234
+ __identification: IdentificationType | None = None
235
+
236
+ @abstractmethod
237
+ async def _write_identification(self) -> None:
238
+ pass
239
+ # TODO(CaHa): Decide on API before v5. either this hook or via config...
240
+
241
+ @lifecycle
242
+ async def lifecycle_identification(self) -> AsyncGenerator[None]:
243
+ """Initialize the identification `UaVariableContainer`."""
244
+ await init_container(parent=self, container=self.identification, exist_ok=True)
245
+
246
+ # setup optional, client writable variables
247
+ for variable_name in ["AssetId", "ComponentName"]:
248
+ variable = getattr(self.identification, variable_name, None)
249
+ if variable is None: # optional variables are allowed to be not exist
250
+ continue
251
+ assert isinstance(variable, UaVariable), f"'{variable_name}' of {self} is not a UaVariable!"
252
+ await variable.set_writable(True)
253
+
254
+ await self._write_identification()
255
+ yield
256
+ # no shutdown
257
+
258
+ @lifecycle(after=lifecycle_identification)
259
+ async def validate_identification(self) -> AsyncGenerator[None]:
260
+ """Check if mandatory identification variables have been set."""
261
+ for variable_name in ["SerialNumber", "ProductInstanceUri", "Manufacturer"]:
262
+ variable = getattr(self.identification, variable_name, None)
263
+ if variable is None: # optional variables are allowed to be not exist
264
+ continue
265
+ # but if they exist, they should be valid, non-empty variables
266
+ assert isinstance(variable, UaVariable), f"'{variable_name}' of {self} is not a UaVariable!"
267
+ value = await variable.read()
268
+ if isinstance(value, ua.LocalizedText):
269
+ value = value.Text
270
+ if value is None or value == "":
271
+ msg = f"{variable.full_name} must not be empty!"
272
+ raise ValidationError(msg)
273
+
274
+ yield
275
+ # no shutdown
276
+
277
+ @property
278
+ def identification(self) -> IdentificationType:
279
+ """Return the identification `UaVariableContainer` . Read-only property."""
280
+ if self.__identification is None:
281
+ type_ = getattr(self, "_identification_type", MachineryComponentIdentification)
282
+ self.__identification = cast(IdentificationType, type_())
283
+ get_logger(self, _LOGGER).debug("Instantiated Container", type=type_)
284
+ return self.__identification
285
+
286
+ def __init_subclass__(cls, **kwargs) -> None:
287
+ """Extract type for identification."""
288
+ super().__init_subclass__(**kwargs)
289
+
290
+ result: tuple[type, ...] | None = resolve_generic_arguments(cls, IdentificationMixin)
291
+ if result is None or any(isinstance(x, TypeVar) for x in result): # skip still-generic classes
292
+ return
293
+
294
+ cls._identification_type = _type_or_default(result[0], default=Identification)