1"""Model builder module.
3Provides some helper methods for easier work with basyx sdk data model
9from pathlib
import Path
12from basyx.aas
import model
16_logger = logging.getLogger(__name__)
20 """Generate a unique identifier string by appending a UUID to the provided ID short.
22 :param id_short: provided ID short
23 :return: unique identifier
25 return f
"{id_short}_{str(uuid.uuid4()).replace('-', '_')}"
29 """Creates a submodel from a JSON file file.
31 :param id: ID of the submodel. If empty, the template's ID is used
35 sm_template_file = Path(json_file).resolve()
38 if not sm_template_file.exists():
39 raise FileNotFoundError(f
"Submodel template file not found: {sm_template_file}")
44 with Path.open(sm_template_file,
"r", encoding=
"utf-8")
as f:
45 submodel_data = json.load(f)
48 submodel = sdk_tools.convert_to_object(submodel_data)
51 if not isinstance(submodel, model.Submodel):
52 raise TypeError(
"Loaded template JSON structure is not a Submodel.")
54 except Exception
as e:
55 _logger.error(f
"Error loading submodel template: {e}")
62 id_short: str |
None, type: model.datatypes, value: Any, display_name: str =
"", description: str =
""
64 """Create a basic SubmodelElement of type Property."""
65 sme = model.Property(id_short=id_short, value_type=type, value=value)
68 description_text = {
"en": f
"{description}"}
69 sme.description = model.MultiLanguageTextType(description_text)
72 display_name_text = {
"en": f
"{display_name}"}
73 sme.display_name = model.MultiLanguageNameType(display_name_text)
79 id_short: str, value: list[model.SubmodelElement], display_name: str =
"", description: str =
""
80) -> model.SubmodelElementCollection:
81 """Create a basic SubmodelElement of type SubmodelElementCollection."""
82 sme = model.SubmodelElementCollection(id_short=id_short, value=value)
85 description_text = {
"en": f
"{description}"}
86 sme.description = model.MultiLanguageTextType(description_text)
89 display_name_text = {
"en": f
"{display_name}"}
90 sme.display_name = model.MultiLanguageNameType(display_name_text)
95def create_base_submodel(identifier: str, id_short: str, display_name: str =
"", description: str =
"") -> model.Submodel:
96 """Create a basic Submodel.
98 :param identifier: identifier of the Submodel
99 :param id_short: ID short of the Submodel
100 :param display_name: display name of the Submodel, defaults to ""
101 :param description: description of the Submodel, defaults to ""
102 :return: Submodel instance
104 sm = model.Submodel(identifier)
105 sm.id_short = id_short
108 description_text = {
"en": f
"{description}"}
109 sm.description = model.MultiLanguageTextType(description_text)
112 display_name_text = {
"en": f
"{display_name}"}
113 sm.display_name = model.MultiLanguageNameType(display_name_text)
119 identifier: str, id_short: str, global_asset_identifier: str, display_name: str =
"", description: str =
""
120) -> model.AssetAdministrationShell:
121 """Create a basic AAS.
123 :param identifier: identifier of the AAS
124 :param id_short: ID short of the AAS
125 :param global_asset_identifier: identifier of the global Asset
126 :param display_name: display name of the AAS, defaults to ""
127 :param description: description of the AAS, defaults to ""
128 :return: AssetAdministrationShell instance
130 if not global_asset_identifier:
131 global_asset_identifier = identifier
135 aas = model.AssetAdministrationShell(id_=identifier, asset_information=asset_info)
136 aas.id_short = id_short
139 description_text = {
"en": f
"{description}"}
140 aas.description = model.MultiLanguageTextType(description_text)
143 display_name_text = {
"en": f
"{display_name}"}
144 aas.display_name = model.MultiLanguageNameType(display_name_text)
150 """Return a basic AssetInformation instance.
152 :param id_short: short ID of the AssetInformation
153 :param namespace: namespace of the AssetInformation, defaults to "basyx_python_aas_server"
154 :return: AssetInformation instance
156 return model.AssetInformation(model.AssetKind.INSTANCE, identifier)
160 """Create a ModelReference.
162 :param id: ID of the Submodel to reference
163 :return: ModelReference instance
165 return model.ModelReference.from_referable(model.Submodel(id))
model.Submodel create_submodel_from_file(str json_file="")
Creates a submodel from a JSON file file.
model.Property create_base_submodel_element_property(str|None id_short, model.datatypes type, Any value, str display_name="", str description="")
Create a basic SubmodelElement of type Property.
model.AssetAdministrationShell create_base_aas(str identifier, str id_short, str global_asset_identifier, str display_name="", str description="")
Create a basic AAS.
model.AssetInformation create_base_asset_information(str identifier)
Return a basic AssetInformation instance.
model.SubmodelElementCollection create_base_submodel_element_collection(str id_short, list[model.SubmodelElement] value, str display_name="", str description="")
Create a basic SubmodelElement of type SubmodelElementCollection.
str create_unique_short_id(str id_short)
Generate a unique identifier string by appending a UUID to the provided ID short.
model.Submodel create_base_submodel(str identifier, str id_short, str display_name="", str description="")
Create a basic Submodel.
model.ModelReference create_reference(str id)
Create a ModelReference.