aas-http-client 0.2.7__tar.gz → 0.2.8__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.

Files changed (20) hide show
  1. {aas_http_client-0.2.7 → aas_http_client-0.2.8}/PKG-INFO +1 -1
  2. {aas_http_client-0.2.7 → aas_http_client-0.2.8}/aas_http_client/client.py +26 -0
  3. {aas_http_client-0.2.7 → aas_http_client-0.2.8}/aas_http_client/wrapper/sdk_wrapper.py +11 -0
  4. {aas_http_client-0.2.7 → aas_http_client-0.2.8}/aas_http_client.egg-info/PKG-INFO +1 -1
  5. {aas_http_client-0.2.7 → aas_http_client-0.2.8}/pyproject.toml +1 -1
  6. {aas_http_client-0.2.7 → aas_http_client-0.2.8}/tests/test_client.py +8 -1
  7. {aas_http_client-0.2.7 → aas_http_client-0.2.8}/tests/test_wrapper.py +25 -6
  8. {aas_http_client-0.2.7 → aas_http_client-0.2.8}/LICENSE +0 -0
  9. {aas_http_client-0.2.7 → aas_http_client-0.2.8}/README.md +0 -0
  10. {aas_http_client-0.2.7 → aas_http_client-0.2.8}/aas_http_client/__init__.py +0 -0
  11. {aas_http_client-0.2.7 → aas_http_client-0.2.8}/aas_http_client/core/encoder.py +0 -0
  12. {aas_http_client-0.2.7 → aas_http_client-0.2.8}/aas_http_client/core/version_check.py +0 -0
  13. {aas_http_client-0.2.7 → aas_http_client-0.2.8}/aas_http_client/demo/demo_process.py +0 -0
  14. {aas_http_client-0.2.7 → aas_http_client-0.2.8}/aas_http_client/demo/logging_handler.py +0 -0
  15. {aas_http_client-0.2.7 → aas_http_client-0.2.8}/aas_http_client/utilities/__init__.py +0 -0
  16. {aas_http_client-0.2.7 → aas_http_client-0.2.8}/aas_http_client/utilities/model_builder.py +0 -0
  17. {aas_http_client-0.2.7 → aas_http_client-0.2.8}/aas_http_client.egg-info/SOURCES.txt +0 -0
  18. {aas_http_client-0.2.7 → aas_http_client-0.2.8}/aas_http_client.egg-info/dependency_links.txt +0 -0
  19. {aas_http_client-0.2.7 → aas_http_client-0.2.8}/aas_http_client.egg-info/top_level.txt +0 -0
  20. {aas_http_client-0.2.7 → aas_http_client-0.2.8}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: aas-http-client
3
- Version: 0.2.7
3
+ Version: 0.2.8
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
@@ -510,6 +510,32 @@ class AasHttpClient(BaseModel):
510
510
  content = response.content.decode("utf-8")
511
511
  return json.loads(content)
512
512
 
513
+ def get_submodel_element_by_path_submodel_repo(self, submodel_id: str, submodel_element_path: str) -> dict | None:
514
+ """Returns a specific submodel element from the Submodel at a specified path.
515
+
516
+ :param submodel_id: Encoded ID of the Submodel to retrieve element from
517
+ :param submodel_element_path: Path of the Submodel element to retrieve
518
+ :return: Submodel element data or None if an error occurred
519
+ """
520
+ decoded_submodel_id: str = decode_base_64(submodel_id)
521
+
522
+ url = f"{self.base_url}/submodels/{decoded_submodel_id}/submodel-elements/{submodel_element_path}"
523
+
524
+ try:
525
+ response = self._session.get(url, headers=HEADERS, timeout=self.time_out)
526
+ logger.debug(f"Call REST API url '{response.url}'")
527
+
528
+ if response.status_code != STATUS_CODE_200:
529
+ log_response_errors(response)
530
+ return None
531
+
532
+ except requests.exceptions.RequestException as e:
533
+ logger.error(f"Error call REST API: {e}")
534
+ return None
535
+
536
+ content = response.content.decode("utf-8")
537
+ return json.loads(content)
538
+
513
539
 
514
540
  # endregion
515
541
 
@@ -253,6 +253,16 @@ class SdkWrapper:
253
253
  content: dict = self._client.post_submodel_element_submodel_repo(submodel_id, sme_data)
254
254
  return _to_object(content)
255
255
 
256
+ def get_submodel_element_by_path_submodel_repo(self, submodel_id: str, submodel_element_path: str) -> model.SubmodelElement | None:
257
+ """Returns a specific submodel element from the Submodel at a specified path.
258
+
259
+ :param submodel_id: Encoded ID of the Submodel to retrieve element from
260
+ :param submodel_element_path: Path of the Submodel element to retrieve
261
+ :return: Submodel element object or None if an error occurred
262
+ """
263
+ content: dict = self._client.get_submodel_element_by_path_submodel_repo(submodel_id, submodel_element_path)
264
+ return _to_object(content)
265
+
256
266
 
257
267
  # endregion
258
268
 
@@ -260,6 +270,7 @@ class SdkWrapper:
260
270
  def _to_object(content: dict) -> Any | None:
261
271
  try:
262
272
  dict_string = json.dumps(content)
273
+ print(dict_string)
263
274
  return json.loads(dict_string, cls=basyx.aas.adapter.json.AASFromJsonDecoder)
264
275
  except Exception as e:
265
276
  logger.error(f"Decoding error: {e}")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: aas-http-client
3
- Version: 0.2.7
3
+ Version: 0.2.8
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
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "aas-http-client"
7
- version = "0.2.7"
7
+ version = "0.2.8"
8
8
  description = "Generic python HTTP client for communication with various types of AAS servers"
9
9
  readme = "README.md"
10
10
  license = { file = "LICENSE" }
@@ -354,9 +354,16 @@ def test_016_post_submodel_element_submodel_repo(client: AasHttpClient, shared_s
354
354
 
355
355
  get_result = client.get_all_submodel_elements_submodel_repository(shared_sm.id)
356
356
 
357
- parsed = urlparse(client.base_url)
358
357
  assert len(get_result.get("result", [])) == 1
359
358
 
359
+ def test_017_get_submodel_element_by_path_submodel_repo(client: AasHttpClient, shared_sm: model.Submodel, shared_sme: model.Property):
360
+ result = client.get_submodel_element_by_path_submodel_repo(shared_sm.id, shared_sme.id_short)
361
+
362
+ assert result is not None
363
+ assert result.get("idShort", "") == shared_sme.id_short
364
+ assert result.get("description", {})[0].get("text", "") == shared_sme.description.get("en", "")
365
+ assert result.get("displayName", {})[0].get("text", "") == shared_sme.display_name.get("en", "")
366
+
360
367
  def test_098_delete_asset_administration_shell_by_id(client: AasHttpClient, shared_aas: model.AssetAdministrationShell):
361
368
  result = client.delete_asset_administration_shell_by_id(shared_aas.id)
362
369
 
@@ -7,6 +7,7 @@ from urllib.parse import urlparse
7
7
 
8
8
  JAVA_SERVER_PORTS = [8075]
9
9
  PYTHON_SERVER_PORTS = [8080, 80]
10
+ DOTNET_SERVER_PORTS = [5043]
10
11
 
11
12
  CONFIG_FILES = [
12
13
  "./tests/server_configs/test_dotnet_server_config.json",
@@ -296,20 +297,38 @@ def test_016_post_submodel_element_submodel_repo(wrapper: SdkWrapper, shared_sm:
296
297
 
297
298
  assert submodel_element is not None
298
299
 
299
- # currently only dict is returned
300
+ parsed = urlparse(wrapper.base_url)
301
+ if int(parsed.port) in DOTNET_SERVER_PORTS:
302
+ # NOTE: dotNet server provides a wrong representation of submodel elements
303
+ return
300
304
 
301
- # property: model.Property = submodel_element
305
+ assert isinstance(submodel_element, model.Property)
302
306
 
303
- # assert property.id_short == shared_sme.id_short
304
- # assert property.description.get("em", "") == shared_sme.description.get("en", "")
305
- # assert property.display_name.get("em", "") == shared_sme.display_name.get("en", "")
306
- # assert property.value == shared_sme.value
307
+ assert submodel_element.id_short == shared_sme.id_short
308
+ assert submodel_element.description.get("en", "") == shared_sme.description.get("en", "")
309
+ assert submodel_element.display_name.get("en", "") == shared_sme.display_name.get("en", "")
307
310
 
308
311
  submodel_elements = wrapper.get_all_submodel_elements_submodel_repository(shared_sm.id)
309
312
 
310
313
  assert submodel_elements is not None
311
314
  assert len(submodel_elements) == 1
312
315
 
316
+ def test_017_get_submodel_element_by_path_submodel_repo(wrapper: SdkWrapper, shared_sm: model.Submodel, shared_sme: model.Property):
317
+ submodel_element = wrapper.get_submodel_element_by_path_submodel_repo(shared_sm.id, shared_sme.id_short)
318
+
319
+ assert submodel_element is not None
320
+
321
+ parsed = urlparse(wrapper.base_url)
322
+ if int(parsed.port) in DOTNET_SERVER_PORTS:
323
+ # NOTE: dotNet server provides a wrong representation of submodel elements
324
+ return
325
+
326
+ assert isinstance(submodel_element, model.Property)
327
+
328
+ assert submodel_element.id_short == shared_sme.id_short
329
+ assert submodel_element.description.get("en", "") == shared_sme.description.get("en", "")
330
+ assert submodel_element.display_name.get("en", "") == shared_sme.display_name.get("en", "")
331
+
313
332
  def test_098_delete_asset_administration_shell_by_id(wrapper: SdkWrapper, shared_aas: model.AssetAdministrationShell):
314
333
  result = wrapper.delete_asset_administration_shell_by_id(shared_aas.id)
315
334
 
File without changes