aas-http-client 0.3.2__py3-none-any.whl → 0.3.4__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.

Potentially problematic release.


This version of aas-http-client might be problematic. Click here for more details.

aas_http_client/client.py CHANGED
@@ -4,6 +4,7 @@ import json
4
4
  import logging
5
5
  import time
6
6
  from pathlib import Path
7
+ from typing import Any
7
8
 
8
9
  import basyx.aas.adapter.json
9
10
  import basyx.aas.adapter.json.json_serialization as js
@@ -26,7 +27,7 @@ STATUS_CODE_404 = 404
26
27
  HEADERS = {"Content-Type": "application/json"}
27
28
 
28
29
 
29
- def log_response_errors(response: Response):
30
+ def log_response_errors(response: Response): # noqa: C901
30
31
  """Create error messages from the response and log them.
31
32
 
32
33
  :param response: response
@@ -74,7 +75,6 @@ class AasHttpClient(BaseModel):
74
75
 
75
76
  base_url: str = "http://javaaasserver:5060/"
76
77
  username: str | None = None
77
- _password: str | None = PrivateAttr(default=None)
78
78
  https_proxy: str | None = None
79
79
  http_proxy: str | None = None
80
80
  time_out: int = 200
@@ -87,13 +87,11 @@ class AasHttpClient(BaseModel):
87
87
 
88
88
  :param password: password
89
89
  """
90
- self._password = password
91
-
92
90
  if self.base_url.endswith("/"):
93
91
  self.base_url = self.base_url[:-1]
94
92
 
95
93
  self._session = requests.Session()
96
- self._session.auth = HTTPBasicAuth(self.username, self._password)
94
+ self._session.auth = HTTPBasicAuth(self.username, password)
97
95
  self._session.verify = self.ssl_verify
98
96
 
99
97
  if self.https_proxy:
@@ -561,6 +559,32 @@ class AasHttpClient(BaseModel):
561
559
 
562
560
  return True
563
561
 
562
+ def patch_submodel_element_by_path_value_only_submodel_repo(self, submodel_id: str, submodel_element_path: str, value: str) -> bool:
563
+ """Updates the value of an existing SubmodelElement.
564
+
565
+ :param submodel_id: Encoded ID of the Submodel to update submodel element for
566
+ :param submodel_element_path: Path of the Submodel element to update
567
+ :param value: Submodel element value to update as string
568
+ :return: True if the patch was successful, False otherwise
569
+ """
570
+ decoded_submodel_id: str = decode_base_64(submodel_id)
571
+
572
+ url = f"{self.base_url}/submodels/{decoded_submodel_id}/submodel-elements/{submodel_element_path}/$value"
573
+
574
+ try:
575
+ response = self._session.patch(url, headers=HEADERS, json=value, timeout=self.time_out)
576
+ logger.debug(f"Call REST API url '{response.url}'")
577
+
578
+ if response.status_code != STATUS_CODE_204:
579
+ log_response_errors(response)
580
+ return False
581
+
582
+ except requests.exceptions.RequestException as e:
583
+ logger.error(f"Error call REST API: {e}")
584
+ return False
585
+
586
+ return True
587
+
564
588
 
565
589
  # endregion
566
590
 
@@ -633,12 +657,11 @@ def create_client_by_config(config_file: Path, password: str = "") -> AasHttpCli
633
657
  return _create_client(config_string, password)
634
658
 
635
659
 
636
- def _create_client(config_string: str, password) -> AasHttpClient | None:
660
+ def _create_client(config_string: str, password: str) -> AasHttpClient | None:
637
661
  try:
638
- connection_settings = AasHttpClient.model_validate_json(config_string)
639
- client = AasHttpClient(**connection_settings.model_dump())
662
+ client = AasHttpClient.model_validate_json(config_string)
640
663
  except ValidationError as ve:
641
- raise ValidationError(f"Invalid BaSyx server connection file: {ve}") from ve
664
+ raise ValidationError(f"Invalid BaSyx server configuration file: {ve}") from ve
642
665
 
643
666
  logger.info(
644
667
  f"Using server configuration: '{client.base_url}' | "
@@ -275,10 +275,28 @@ class SdkWrapper:
275
275
  :return: Submodel element object or None if an error occurred
276
276
  """
277
277
  content: dict = self._client.get_submodel_element_by_path_submodel_repo(submodel_id, submodel_element_path)
278
+ print(content)
278
279
  return _to_object(content)
279
280
 
281
+ def patch_submodel_element_by_path_value_only_submodel_repo(self, submodel_id: str, submodel_element_path: str, value: str) -> bool:
282
+ """Updates the value of an existing SubmodelElement.
283
+
284
+ :param submodel_id: Encoded ID of the Submodel to update submodel element for
285
+ :param submodel_element_path: Path of the Submodel element to update
286
+ :param value: Submodel element value to update as string
287
+ :return: True if the patch was successful, False otherwise
288
+ """
289
+ return self._client.patch_submodel_element_by_path_value_only_submodel_repo(submodel_id, submodel_element_path, value)
290
+
291
+ # endregion
292
+
293
+ def get_client(self) -> AasHttpClient:
294
+ """Returns the underlying AAS HTTP client.
295
+
296
+ :return: The AAS HTTP client instance.
297
+ """
298
+ return self._client
280
299
 
281
- # endregion
282
300
 
283
301
  # region utils
284
302
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: aas-http-client
3
- Version: 0.3.2
3
+ Version: 0.3.4
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,14 +1,14 @@
1
1
  aas_http_client/__init__.py,sha256=cAr1mQzWp0G0LKtkAOYzc9t95OY3jM3Aj4bKnxx0Dso,901
2
- aas_http_client/client.py,sha256=tangqT-KJgI28y-CrPPWVc26ZEik4IfgZBjmakkG4lU,25930
2
+ aas_http_client/client.py,sha256=DFflDiU7oyDQ98-X4KQlkFDKQFN3_hqBd723n_h-NkE,26954
3
3
  aas_http_client/core/encoder.py,sha256=FS7P0FPakzFsGz70eRFDHQZFA_2nlKLlWIxavtnFrPg,660
4
4
  aas_http_client/core/version_check.py,sha256=721Zs3xSRrJTYZtAxkaUWg9LLKtpU7oFM62DzQHZdE4,705
5
5
  aas_http_client/demo/demo_process.py,sha256=6sN_N3QbA4iLUmzeg1Y_XOwVAuDNtwkR4grAg7EkjWM,3301
6
6
  aas_http_client/demo/logging_handler.py,sha256=VJtZ4u3x_LhYZQtfNck7FuXhGFZm7gid0uDhvf9GjJ8,5596
7
7
  aas_http_client/utilities/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
8
8
  aas_http_client/utilities/model_builder.py,sha256=EUqVvKgXiyJNtyUeFrL6ronfF4hiF1KCipxSaLj6EiE,4465
9
- aas_http_client/wrapper/sdk_wrapper.py,sha256=SU-JZwT4O_bOGfjlBUrN_GIJXrSNY8NvfDCGWC7zCOk,14353
10
- aas_http_client-0.3.2.dist-info/licenses/LICENSE,sha256=ayt4HY-Tjoe1Uvj47j6UdNq8mEufKcKFangurChIHxQ,5990
11
- aas_http_client-0.3.2.dist-info/METADATA,sha256=etLzP5usn0WyK9ovOEUctZKzDdPOMrCfa3HtbsN0_zQ,10467
12
- aas_http_client-0.3.2.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
13
- aas_http_client-0.3.2.dist-info/top_level.txt,sha256=vzvoz2vjeTLwpuz-Y-eEfoQ7T3byoaKshVlFMFH5NaM,16
14
- aas_http_client-0.3.2.dist-info/RECORD,,
9
+ aas_http_client/wrapper/sdk_wrapper.py,sha256=dSckMIbFJ_9wFvYKVjWNPIofcl5aINk43nIY3Un0ht4,15197
10
+ aas_http_client-0.3.4.dist-info/licenses/LICENSE,sha256=ayt4HY-Tjoe1Uvj47j6UdNq8mEufKcKFangurChIHxQ,5990
11
+ aas_http_client-0.3.4.dist-info/METADATA,sha256=Iel95Gsqa7EywECf0qFN1IuMCbK6hlwk_rNzm0_IqgE,10467
12
+ aas_http_client-0.3.4.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
13
+ aas_http_client-0.3.4.dist-info/top_level.txt,sha256=vzvoz2vjeTLwpuz-Y-eEfoQ7T3byoaKshVlFMFH5NaM,16
14
+ aas_http_client-0.3.4.dist-info/RECORD,,