aas-http-client 0.2.5__tar.gz → 0.2.7__tar.gz
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.
Potentially problematic release.
This version of aas-http-client might be problematic. Click here for more details.
- {aas_http_client-0.2.5 → aas_http_client-0.2.7}/PKG-INFO +1 -1
- {aas_http_client-0.2.5 → aas_http_client-0.2.7}/aas_http_client/client.py +15 -8
- aas_http_client-0.2.7/aas_http_client/demo/demo_process.py +95 -0
- {aas_http_client-0.2.5 → aas_http_client-0.2.7}/aas_http_client/utilities/model_builder.py +18 -24
- {aas_http_client-0.2.5 → aas_http_client-0.2.7}/aas_http_client/wrapper/sdk_wrapper.py +48 -38
- {aas_http_client-0.2.5 → aas_http_client-0.2.7}/aas_http_client.egg-info/PKG-INFO +1 -1
- {aas_http_client-0.2.5 → aas_http_client-0.2.7}/aas_http_client.egg-info/SOURCES.txt +3 -1
- aas_http_client-0.2.7/pyproject.toml +22 -0
- aas_http_client-0.2.7/tests/test_client.py +378 -0
- aas_http_client-0.2.7/tests/test_wrapper.py +329 -0
- aas_http_client-0.2.5/aas_http_client/demo/demo_process.py +0 -93
- aas_http_client-0.2.5/pyproject.toml +0 -17
- {aas_http_client-0.2.5 → aas_http_client-0.2.7}/LICENSE +0 -0
- {aas_http_client-0.2.5 → aas_http_client-0.2.7}/README.md +0 -0
- {aas_http_client-0.2.5 → aas_http_client-0.2.7}/aas_http_client/__init__.py +0 -0
- {aas_http_client-0.2.5 → aas_http_client-0.2.7}/aas_http_client/core/encoder.py +0 -0
- {aas_http_client-0.2.5 → aas_http_client-0.2.7}/aas_http_client/core/version_check.py +0 -0
- {aas_http_client-0.2.5 → aas_http_client-0.2.7}/aas_http_client/demo/logging_handler.py +0 -0
- {aas_http_client-0.2.5 → aas_http_client-0.2.7}/aas_http_client/utilities/__init__.py +0 -0
- {aas_http_client-0.2.5 → aas_http_client-0.2.7}/aas_http_client.egg-info/dependency_links.txt +0 -0
- {aas_http_client-0.2.5 → aas_http_client-0.2.7}/aas_http_client.egg-info/top_level.txt +0 -0
- {aas_http_client-0.2.5 → aas_http_client-0.2.7}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: aas-http-client
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.7
|
|
4
4
|
Summary: Generic python HTTP client for communication with various types of AAS servers
|
|
5
5
|
Author-email: Daniel Klein <daniel.klein@em.ag>
|
|
6
6
|
License: # :em engineering methods AG Software License
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
"""Client for HTTP API communication with AAS server."""
|
|
2
|
+
|
|
2
3
|
import json
|
|
3
4
|
import logging
|
|
4
5
|
import time
|
|
@@ -8,12 +9,13 @@ import basyx.aas.adapter.json
|
|
|
8
9
|
import basyx.aas.adapter.json.json_serialization as js
|
|
9
10
|
import requests
|
|
10
11
|
from basyx.aas.model import Reference, Submodel
|
|
11
|
-
from aas_http_client.core.encoder import decode_base_64
|
|
12
12
|
from pydantic import BaseModel, PrivateAttr, ValidationError
|
|
13
13
|
from requests import Session
|
|
14
14
|
from requests.auth import HTTPBasicAuth
|
|
15
15
|
from requests.models import Response
|
|
16
16
|
|
|
17
|
+
from aas_http_client.core.encoder import decode_base_64
|
|
18
|
+
|
|
17
19
|
logger = logging.getLogger(__name__)
|
|
18
20
|
|
|
19
21
|
STATUS_CODE_200 = 200
|
|
@@ -55,7 +57,7 @@ def log_response_errors(response: Response):
|
|
|
55
57
|
result_error_messages.append(str(message))
|
|
56
58
|
elif "error" in response_content_dict:
|
|
57
59
|
result_error_messages.append(response_content_dict.get("error", ""))
|
|
58
|
-
|
|
60
|
+
|
|
59
61
|
if len(result_error_messages) == 0 and response.text:
|
|
60
62
|
result_error_messages.append(response.text)
|
|
61
63
|
|
|
@@ -121,7 +123,7 @@ class AasHttpClient(BaseModel):
|
|
|
121
123
|
content = response.content.decode("utf-8")
|
|
122
124
|
return json.loads(content)
|
|
123
125
|
|
|
124
|
-
# region shells
|
|
126
|
+
# region shells
|
|
125
127
|
|
|
126
128
|
def post_asset_administration_shell(self, aas_data: dict) -> dict | None:
|
|
127
129
|
"""Creates a new Asset Administration Shell.
|
|
@@ -242,7 +244,6 @@ class AasHttpClient(BaseModel):
|
|
|
242
244
|
content = response.content.decode("utf-8")
|
|
243
245
|
return json.loads(content)
|
|
244
246
|
|
|
245
|
-
|
|
246
247
|
def get_asset_administration_shell_by_id_reference_aas_repository(self, aas_id: str) -> Reference | None:
|
|
247
248
|
"""Returns a specific Asset Administration Shell as a Reference.
|
|
248
249
|
|
|
@@ -278,7 +279,7 @@ class AasHttpClient(BaseModel):
|
|
|
278
279
|
decoded_submodel_id: str = decode_base_64(submodel_id)
|
|
279
280
|
|
|
280
281
|
url = f"{self.base_url}/shells/{decoded_aas_id}/submodels/{decoded_submodel_id}"
|
|
281
|
-
|
|
282
|
+
# /shells/{aasIdentifier}/submodels/{submodelIdentifier}
|
|
282
283
|
|
|
283
284
|
try:
|
|
284
285
|
response = self._session.get(url, headers=HEADERS, timeout=self.time_out)
|
|
@@ -318,9 +319,9 @@ class AasHttpClient(BaseModel):
|
|
|
318
319
|
|
|
319
320
|
return True
|
|
320
321
|
|
|
321
|
-
# endregion
|
|
322
|
+
# endregion
|
|
322
323
|
|
|
323
|
-
# region submodels
|
|
324
|
+
# region submodels
|
|
324
325
|
|
|
325
326
|
def post_submodel(self, submodel_data: dict) -> dict | None:
|
|
326
327
|
"""Creates a new Submodel.
|
|
@@ -509,10 +510,12 @@ class AasHttpClient(BaseModel):
|
|
|
509
510
|
content = response.content.decode("utf-8")
|
|
510
511
|
return json.loads(content)
|
|
511
512
|
|
|
513
|
+
|
|
512
514
|
# endregion
|
|
513
515
|
|
|
514
516
|
# region client
|
|
515
517
|
|
|
518
|
+
|
|
516
519
|
def create_client_by_url(
|
|
517
520
|
base_url: str,
|
|
518
521
|
username: str = "",
|
|
@@ -547,6 +550,7 @@ def create_client_by_url(
|
|
|
547
550
|
config_string = json.dumps(config_dict, indent=4)
|
|
548
551
|
return _create_client(config_string, password)
|
|
549
552
|
|
|
553
|
+
|
|
550
554
|
def create_client_by_config(config_file: Path, password: str = "") -> AasHttpClient | None:
|
|
551
555
|
"""Create a AAS HTTP client from the given parameters.
|
|
552
556
|
|
|
@@ -565,6 +569,7 @@ def create_client_by_config(config_file: Path, password: str = "") -> AasHttpCli
|
|
|
565
569
|
|
|
566
570
|
return _create_client(config_string, password)
|
|
567
571
|
|
|
572
|
+
|
|
568
573
|
def _create_client(config_string: str, password) -> AasHttpClient | None:
|
|
569
574
|
try:
|
|
570
575
|
connection_settings = AasHttpClient.model_validate_json(config_string)
|
|
@@ -590,6 +595,7 @@ def _create_client(config_string: str, password) -> AasHttpClient | None:
|
|
|
590
595
|
|
|
591
596
|
return client
|
|
592
597
|
|
|
598
|
+
|
|
593
599
|
def _connect_to_api(client: AasHttpClient) -> bool:
|
|
594
600
|
start_time = time.time()
|
|
595
601
|
logger.debug(f"Try to connect to REST API '{client.base_url}' for {client.connection_time_out} seconds")
|
|
@@ -609,4 +615,5 @@ def _connect_to_api(client: AasHttpClient) -> bool:
|
|
|
609
615
|
logger.warning(f"Retrying connection (attempt: {counter})")
|
|
610
616
|
time.sleep(1)
|
|
611
617
|
|
|
612
|
-
|
|
618
|
+
|
|
619
|
+
# endregion
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"""Main process for the demo."""
|
|
2
|
+
|
|
3
|
+
import logging
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
|
|
6
|
+
from basyx.aas import model
|
|
7
|
+
|
|
8
|
+
from aas_http_client.client import AasHttpClient, create_client_by_config
|
|
9
|
+
from aas_http_client.utilities import model_builder
|
|
10
|
+
from aas_http_client.wrapper.sdk_wrapper import SdkWrapper, create_wrapper_by_config
|
|
11
|
+
|
|
12
|
+
logger = logging.getLogger(__name__)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def start() -> None:
|
|
16
|
+
"""Start the demo process."""
|
|
17
|
+
# create a submodel element
|
|
18
|
+
sme_short_id: str = model_builder.create_unique_short_id("poc_sme")
|
|
19
|
+
sme = model_builder.create_base_submodel_element_Property(sme_short_id, model.datatypes.String, "Sample Value")
|
|
20
|
+
|
|
21
|
+
# create a submodel
|
|
22
|
+
sm_short_id: str = model_builder.create_unique_short_id("poc_sm")
|
|
23
|
+
submodel = model_builder.create_base_submodel(sm_short_id)
|
|
24
|
+
# add submodel element to submodel
|
|
25
|
+
# submodel.submodel_element.add(sme)
|
|
26
|
+
|
|
27
|
+
# create an AAS
|
|
28
|
+
aas_short_id: str = model_builder.create_unique_short_id("poc_aas")
|
|
29
|
+
aas = model_builder.create_base_ass(aas_short_id)
|
|
30
|
+
|
|
31
|
+
# add submodel to AAS
|
|
32
|
+
model_builder.add_submodel_to_aas(aas, submodel)
|
|
33
|
+
|
|
34
|
+
wrapper = _create_sdk_wrapper(Path("./aas_http_client/demo/python_server_config.json"))
|
|
35
|
+
# dotnet_sdk_wrapper = _create_sdk_wrapper(Path("./aas_http_client/demo/dotnet_server_config.json"))
|
|
36
|
+
|
|
37
|
+
for existing_shell in wrapper.get_all_asset_administration_shells():
|
|
38
|
+
logger.warning(f"Delete shell '{existing_shell.id}'")
|
|
39
|
+
wrapper.delete_asset_administration_shell_by_id(existing_shell.id)
|
|
40
|
+
|
|
41
|
+
for existing_submodel in wrapper.get_all_submodels():
|
|
42
|
+
logger.warning(f"Delete submodel '{existing_submodel.id}'")
|
|
43
|
+
wrapper.delete_submodel_by_id(existing_submodel.id)
|
|
44
|
+
|
|
45
|
+
wrapper.post_asset_administration_shell(aas)
|
|
46
|
+
wrapper.post_submodel(submodel)
|
|
47
|
+
|
|
48
|
+
tmp = wrapper.get_asset_administration_shell_by_id_reference_aas_repository(aas.id)
|
|
49
|
+
|
|
50
|
+
shell = wrapper.get_asset_administration_shell_by_id(aas.id)
|
|
51
|
+
submodel = wrapper.get_submodel_by_id(submodel.id)
|
|
52
|
+
|
|
53
|
+
wrapper.post_submodel_element_submodel_repo(submodel.id, sme)
|
|
54
|
+
|
|
55
|
+
submodel = wrapper.get_submodel_by_id(submodel.id)
|
|
56
|
+
|
|
57
|
+
for existing_shell in wrapper.get_all_asset_administration_shells():
|
|
58
|
+
logger.warning(f"Delete shell '{existing_shell.id}'")
|
|
59
|
+
wrapper.delete_asset_administration_shell_by_id(existing_shell.id)
|
|
60
|
+
|
|
61
|
+
for existing_submodel in wrapper.get_all_submodels():
|
|
62
|
+
logger.warning(f"Delete submodel '{existing_submodel.id}'")
|
|
63
|
+
wrapper.delete_submodel_by_id(existing_submodel.id)
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def _create_client(config: Path) -> AasHttpClient:
|
|
67
|
+
"""Create a HTTP client from a given configuration file.
|
|
68
|
+
|
|
69
|
+
:param config: Given configuration file
|
|
70
|
+
:return: HTTP client
|
|
71
|
+
"""
|
|
72
|
+
try:
|
|
73
|
+
file = config
|
|
74
|
+
client = create_client_by_config(file, password="")
|
|
75
|
+
|
|
76
|
+
except Exception as e:
|
|
77
|
+
logger.error(f"Failed to create client for {file}: {e}")
|
|
78
|
+
|
|
79
|
+
return client
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def _create_sdk_wrapper(config: Path) -> SdkWrapper:
|
|
83
|
+
"""Create a SDK wrapper from a given configuration file.
|
|
84
|
+
|
|
85
|
+
:param config: Given configuration file
|
|
86
|
+
:return: SDK wrapper
|
|
87
|
+
"""
|
|
88
|
+
try:
|
|
89
|
+
file = config
|
|
90
|
+
client = create_wrapper_by_config(file, password="")
|
|
91
|
+
|
|
92
|
+
except Exception as e:
|
|
93
|
+
logger.error(f"Failed to create client for {file}: {e}")
|
|
94
|
+
|
|
95
|
+
return client
|
|
@@ -4,9 +4,10 @@ Provides some helper methods for easier work with basyx sdk data model
|
|
|
4
4
|
"""
|
|
5
5
|
|
|
6
6
|
import uuid
|
|
7
|
+
from typing import Any
|
|
7
8
|
|
|
8
9
|
from basyx.aas import model
|
|
9
|
-
|
|
10
|
+
|
|
10
11
|
|
|
11
12
|
def create_unique_short_id(id_short: str) -> str:
|
|
12
13
|
"""Generate a unique identifier string by appending a UUID to the provided ID short.
|
|
@@ -16,41 +17,39 @@ def create_unique_short_id(id_short: str) -> str:
|
|
|
16
17
|
"""
|
|
17
18
|
return f"{id_short}_{str(uuid.uuid4()).replace('-', '_')}"
|
|
18
19
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
"""
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
20
|
+
|
|
21
|
+
def create_base_submodel_element_Property(
|
|
22
|
+
id_short: str, type: model.datatypes, value: Any, display_name: str = "", description: str = ""
|
|
23
|
+
) -> model.Property:
|
|
24
|
+
"""Create a basic Property Submodel Element."""
|
|
25
|
+
sme = model.Property(id_short=id_short, value_type=type, value=value)
|
|
26
|
+
|
|
27
27
|
if not description:
|
|
28
28
|
description = f"This is the submodel element with ID short '{id_short}'"
|
|
29
29
|
|
|
30
30
|
description_text = {"en": f"{description}"}
|
|
31
31
|
sme.description = model.MultiLanguageTextType(description_text)
|
|
32
|
-
|
|
32
|
+
|
|
33
33
|
if not display_name:
|
|
34
34
|
display_name = "POC Submodel Element"
|
|
35
35
|
|
|
36
36
|
display_name_text = {"en": f"{display_name}"}
|
|
37
37
|
sme.display_name = model.MultiLanguageTextType(display_name_text)
|
|
38
|
-
|
|
38
|
+
|
|
39
39
|
return sme
|
|
40
40
|
|
|
41
|
-
|
|
41
|
+
|
|
42
|
+
def create_base_submodel(id_short: str, namespace: str = "fluid40", display_name: str = "", description: str = "") -> model.Submodel:
|
|
42
43
|
"""Create a basic Submodel.
|
|
43
44
|
|
|
44
45
|
:param id_short: ID short of the Submodel
|
|
45
|
-
:param namespace: namespace of the Submodel , defaults to "
|
|
46
|
+
:param namespace: namespace of the Submodel , defaults to "fluid40"
|
|
46
47
|
:param display_name: display name of the Submodel, defaults to ""
|
|
47
48
|
:param description: description of the Submodel, defaults to ""
|
|
48
49
|
:return: Submodel instance
|
|
49
50
|
"""
|
|
50
|
-
if namespace
|
|
51
|
-
|
|
52
|
-
else:
|
|
53
|
-
identifier = id_short
|
|
51
|
+
identifier = f"{namespace}/{id_short}" if namespace else id_short
|
|
52
|
+
|
|
54
53
|
sm = model.Submodel(identifier)
|
|
55
54
|
sm.id_short = id_short
|
|
56
55
|
|
|
@@ -69,9 +68,7 @@ def create_base_submodel(id_short: str, namespace: str = "basyx_python_aas_serve
|
|
|
69
68
|
return sm
|
|
70
69
|
|
|
71
70
|
|
|
72
|
-
def create_base_ass(
|
|
73
|
-
id_short: str, namespace: str = "basyx_python_aas_server", display_name: str = "", description: str = ""
|
|
74
|
-
) -> model.AssetAdministrationShell:
|
|
71
|
+
def create_base_ass(id_short: str, namespace: str = "fluid40", display_name: str = "", description: str = "") -> model.AssetAdministrationShell:
|
|
75
72
|
"""Create a basic AAS.
|
|
76
73
|
|
|
77
74
|
:param id_short: ID short of the AAS
|
|
@@ -117,10 +114,7 @@ def create_base_asset_information(id_short: str, namespace: str = "basyx_python_
|
|
|
117
114
|
:param namespace: namespace of the AssetInformation, defaults to "basyx_python_aas_server"
|
|
118
115
|
:return: AssetInformation instance
|
|
119
116
|
"""
|
|
120
|
-
if namespace
|
|
121
|
-
identifier = f"{namespace}/{id_short}"
|
|
122
|
-
else:
|
|
123
|
-
identifier = id_short
|
|
117
|
+
identifier = f"{namespace}/{id_short}" if namespace else id_short
|
|
124
118
|
return model.AssetInformation(model.AssetKind.INSTANCE, identifier)
|
|
125
119
|
|
|
126
120
|
|
|
@@ -6,17 +6,20 @@ from pathlib import Path
|
|
|
6
6
|
from typing import Any
|
|
7
7
|
|
|
8
8
|
import basyx.aas.adapter.json
|
|
9
|
-
|
|
10
9
|
from basyx.aas import model
|
|
10
|
+
|
|
11
11
|
from aas_http_client.client import AasHttpClient, _create_client
|
|
12
|
+
|
|
12
13
|
logger = logging.getLogger(__name__)
|
|
13
14
|
|
|
14
|
-
|
|
15
|
+
|
|
16
|
+
class SdkWrapper:
|
|
15
17
|
"""Represents a wrapper for the BaSyx Python SDK to communicate with a REST API."""
|
|
16
|
-
_client: AasHttpClient = None
|
|
17
|
-
base_url: str = ""
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
_client: AasHttpClient = None
|
|
20
|
+
base_url: str = ""
|
|
21
|
+
|
|
22
|
+
# region shells
|
|
20
23
|
|
|
21
24
|
def post_asset_administration_shell(self, aas: model.AssetAdministrationShell) -> model.AssetAdministrationShell | None:
|
|
22
25
|
"""Creates a new Asset Administration Shell.
|
|
@@ -54,7 +57,7 @@ class SdkWrapper():
|
|
|
54
57
|
:return: Asset Administration Shells objects or None if an error occurred
|
|
55
58
|
"""
|
|
56
59
|
content: dict = self._client.get_all_asset_administration_shells()
|
|
57
|
-
|
|
60
|
+
|
|
58
61
|
if not content:
|
|
59
62
|
return None
|
|
60
63
|
|
|
@@ -79,16 +82,16 @@ class SdkWrapper():
|
|
|
79
82
|
|
|
80
83
|
def get_asset_administration_shell_by_id(self, aas_id: str) -> model.AssetAdministrationShell | None:
|
|
81
84
|
"""Returns a specific Asset Administration Shell.
|
|
82
|
-
|
|
85
|
+
|
|
83
86
|
:param aas_id: ID of the AAS to retrieve
|
|
84
87
|
:return: Asset Administration Shells object or None if an error occurred
|
|
85
88
|
"""
|
|
86
89
|
content: dict = self._client.get_asset_administration_shell_by_id(aas_id)
|
|
87
|
-
|
|
90
|
+
|
|
88
91
|
if not content:
|
|
89
92
|
logger.warning(f"No shell found with ID '{aas_id}' on server.")
|
|
90
93
|
return None
|
|
91
|
-
|
|
94
|
+
|
|
92
95
|
return _to_object(content)
|
|
93
96
|
|
|
94
97
|
def get_asset_administration_shell_by_id_reference_aas_repository(self, aas_id: str) -> model.Reference | None:
|
|
@@ -97,12 +100,12 @@ class SdkWrapper():
|
|
|
97
100
|
:param aas_id: ID of the AAS reference to retrieve
|
|
98
101
|
:return: Asset Administration Shells reference object or None if an error occurred
|
|
99
102
|
"""
|
|
100
|
-
#workaround because serialization not working
|
|
103
|
+
# workaround because serialization not working
|
|
101
104
|
aas = self.get_asset_administration_shell_by_id(aas_id)
|
|
102
105
|
return model.ModelReference.from_referable(aas)
|
|
103
|
-
|
|
104
|
-
# content: dict = self._client.
|
|
105
|
-
# return
|
|
106
|
+
|
|
107
|
+
# content: dict = self._client.get_asset_administration_shell_by_id_reference_aas_repository(aas_id)
|
|
108
|
+
# return _to_object(content)
|
|
106
109
|
|
|
107
110
|
def get_submodel_by_id_aas_repository(self, aas_id: str, submodel_id: str) -> model.Submodel | None:
|
|
108
111
|
"""Returns the Submodel.
|
|
@@ -122,9 +125,9 @@ class SdkWrapper():
|
|
|
122
125
|
"""
|
|
123
126
|
return self._client.delete_asset_administration_shell_by_id(aas_id)
|
|
124
127
|
|
|
125
|
-
# endregion
|
|
128
|
+
# endregion
|
|
126
129
|
|
|
127
|
-
# region submodels
|
|
130
|
+
# region submodels
|
|
128
131
|
|
|
129
132
|
def post_submodel(self, submodel: model.Submodel) -> model.Submodel | None:
|
|
130
133
|
"""Creates a new Submodel.
|
|
@@ -186,15 +189,15 @@ class SdkWrapper():
|
|
|
186
189
|
if not content:
|
|
187
190
|
logger.warning(f"No submodel found with ID '{submodel_id}' on server.")
|
|
188
191
|
return None
|
|
189
|
-
|
|
192
|
+
|
|
190
193
|
return _to_object(content)
|
|
191
194
|
|
|
192
195
|
def patch_submodel_by_id(self, submodel_id: str, submodel: model.Submodel):
|
|
193
|
-
"""Updates an existing Submodel
|
|
196
|
+
"""Updates an existing Submodel.
|
|
194
197
|
|
|
195
198
|
:param submodel_id: Encoded ID of the Submodel to delete
|
|
196
199
|
:return: True if the patch was successful, False otherwise
|
|
197
|
-
"""
|
|
200
|
+
"""
|
|
198
201
|
sm_data = _to_dict(submodel)
|
|
199
202
|
return self._client.patch_submodel_by_id(submodel_id, sm_data)
|
|
200
203
|
|
|
@@ -206,15 +209,17 @@ class SdkWrapper():
|
|
|
206
209
|
"""
|
|
207
210
|
return self._client.delete_submodel_by_id(submodel_id)
|
|
208
211
|
|
|
209
|
-
def get_all_submodel_elements_submodel_repository(
|
|
210
|
-
|
|
211
|
-
|
|
212
|
+
def get_all_submodel_elements_submodel_repository(
|
|
213
|
+
self,
|
|
214
|
+
submodel_id: str,
|
|
215
|
+
) -> list[model.SubmodelElement] | None:
|
|
216
|
+
"""Returns all submodel elements including their hierarchy. !!!Serialization to model.SubmodelElement currently not possible.
|
|
212
217
|
|
|
213
218
|
:param submodel_id: Encoded ID of the Submodel to retrieve elements from
|
|
214
219
|
:return: List of Submodel elements or None if an error occurred
|
|
215
220
|
"""
|
|
216
221
|
content = self._client.get_all_submodel_elements_submodel_repository(submodel_id)
|
|
217
|
-
|
|
222
|
+
|
|
218
223
|
if not content:
|
|
219
224
|
return []
|
|
220
225
|
|
|
@@ -238,9 +243,8 @@ class SdkWrapper():
|
|
|
238
243
|
return submodel_elements
|
|
239
244
|
|
|
240
245
|
def post_submodel_element_submodel_repo(self, submodel_id: str, submodel_element: model.SubmodelElement) -> model.SubmodelElement | None:
|
|
241
|
-
"""Creates a new submodel element.
|
|
242
|
-
|
|
243
|
-
|
|
246
|
+
"""Creates a new submodel element. !!!Serialization to model.SubmodelElements currently not possible.
|
|
247
|
+
|
|
244
248
|
:param submodel_id: Encoded ID of the submodel to create elements for
|
|
245
249
|
:param submodel_element: Submodel element to create
|
|
246
250
|
:return: List of submodel element objects or None if an error occurred
|
|
@@ -252,6 +256,7 @@ class SdkWrapper():
|
|
|
252
256
|
|
|
253
257
|
# endregion
|
|
254
258
|
|
|
259
|
+
|
|
255
260
|
def _to_object(content: dict) -> Any | None:
|
|
256
261
|
try:
|
|
257
262
|
dict_string = json.dumps(content)
|
|
@@ -260,7 +265,8 @@ def _to_object(content: dict) -> Any | None:
|
|
|
260
265
|
logger.error(f"Decoding error: {e}")
|
|
261
266
|
logger.error(f"In JSON: {content}")
|
|
262
267
|
return None
|
|
263
|
-
|
|
268
|
+
|
|
269
|
+
|
|
264
270
|
def _to_dict(object: Any) -> dict | None:
|
|
265
271
|
try:
|
|
266
272
|
data_string = json.dumps(object, cls=basyx.aas.adapter.json.AASToJsonEncoder)
|
|
@@ -268,10 +274,12 @@ def _to_dict(object: Any) -> dict | None:
|
|
|
268
274
|
except Exception as e:
|
|
269
275
|
logger.error(f"Encoding error: {e}")
|
|
270
276
|
logger.error(f"In object: {object}")
|
|
271
|
-
return None
|
|
277
|
+
return None
|
|
278
|
+
|
|
272
279
|
|
|
273
280
|
# region wrapper
|
|
274
281
|
|
|
282
|
+
|
|
275
283
|
def create_wrapper_by_url(
|
|
276
284
|
base_url: str,
|
|
277
285
|
username: str = "",
|
|
@@ -304,17 +312,18 @@ def create_wrapper_by_url(
|
|
|
304
312
|
config_dict["connection_time_out"] = connection_time_out
|
|
305
313
|
config_dict["ssl_verify"] = ssl_verify
|
|
306
314
|
config_string = json.dumps(config_dict, indent=4)
|
|
307
|
-
|
|
315
|
+
|
|
308
316
|
wrapper = SdkWrapper()
|
|
309
|
-
client = _create_client(config_string, password)
|
|
310
|
-
|
|
317
|
+
client = _create_client(config_string, password)
|
|
318
|
+
|
|
311
319
|
if not client:
|
|
312
320
|
return None
|
|
313
|
-
|
|
321
|
+
|
|
314
322
|
wrapper._client = client
|
|
315
|
-
wrapper.base_url = client.base_url
|
|
323
|
+
wrapper.base_url = client.base_url
|
|
316
324
|
return wrapper
|
|
317
|
-
|
|
325
|
+
|
|
326
|
+
|
|
318
327
|
def create_wrapper_by_config(config_file: Path, password: str = "") -> SdkWrapper | None:
|
|
319
328
|
"""Create a wrapper for the BaSyx Python SDK from the given parameters.
|
|
320
329
|
|
|
@@ -332,12 +341,13 @@ def create_wrapper_by_config(config_file: Path, password: str = "") -> SdkWrappe
|
|
|
332
341
|
|
|
333
342
|
wrapper = SdkWrapper()
|
|
334
343
|
client = _create_client(config_string, password)
|
|
335
|
-
|
|
344
|
+
|
|
336
345
|
if not client:
|
|
337
346
|
return None
|
|
338
|
-
|
|
339
|
-
wrapper._client = client
|
|
340
|
-
wrapper.base_url = client.base_url
|
|
347
|
+
|
|
348
|
+
wrapper._client = client
|
|
349
|
+
wrapper.base_url = client.base_url
|
|
341
350
|
return wrapper
|
|
342
351
|
|
|
343
|
-
|
|
352
|
+
|
|
353
|
+
# endregion
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: aas-http-client
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.7
|
|
4
4
|
Summary: Generic python HTTP client for communication with various types of AAS servers
|
|
5
5
|
Author-email: Daniel Klein <daniel.klein@em.ag>
|
|
6
6
|
License: # :em engineering methods AG Software License
|
|
@@ -13,4 +13,6 @@ aas_http_client/demo/demo_process.py
|
|
|
13
13
|
aas_http_client/demo/logging_handler.py
|
|
14
14
|
aas_http_client/utilities/__init__.py
|
|
15
15
|
aas_http_client/utilities/model_builder.py
|
|
16
|
-
aas_http_client/wrapper/sdk_wrapper.py
|
|
16
|
+
aas_http_client/wrapper/sdk_wrapper.py
|
|
17
|
+
tests/test_client.py
|
|
18
|
+
tests/test_wrapper.py
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "aas-http-client"
|
|
7
|
+
version = "0.2.7"
|
|
8
|
+
description = "Generic python HTTP client for communication with various types of AAS servers"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = { file = "LICENSE" }
|
|
11
|
+
authors = [{ name = "Daniel Klein", email = "daniel.klein@em.ag" }]
|
|
12
|
+
dependencies = []
|
|
13
|
+
|
|
14
|
+
[project.urls]
|
|
15
|
+
Homepage = "https://github.com/fluid40/aas-http-client"
|
|
16
|
+
|
|
17
|
+
[tool.commitizen]
|
|
18
|
+
name = "cz_conventional_commits"
|
|
19
|
+
version = "0.1.0"
|
|
20
|
+
|
|
21
|
+
[tool.commitizen.branch]
|
|
22
|
+
allowed = "^(main|master|develop|feature/.*|fix/.*|hotfix/.*)$"
|