Asset Connector Documentation
Loading...
Searching...
No Matches
get_value_payload.py
Go to the documentation of this file.
1from typing import Any
2
3from basyx.aas.model import Key, KeyTypes, ModelReference
4from pydantic import BaseModel, Field, PrivateAttr
5
6KEY_TYPE_MAPPING: dict[str, str] = {
7 "Submodel": "SUBMODEL",
8 "SubmodelElementCollection": "SUBMODEL_ELEMENT_COLLECTION",
9 "Property": "PROPERTY",
10}
11
12
13class GetValuePayload(BaseModel): # noqa: D101
14 """Defines the model class of the payload for the `get_value` (URL `/get-value`) endpoint
15 of this application using Pydantic.
16
17 The JSON payload must contain exactly the following fields:
18 - `Reference`
19
20 Inside the `Reference`-field, a properly serialized AAS reference according to the AAS JSON serialization
21 must be provided.
22 Will be parsed as `basyx.aas.model.ModelReference`.
23 The reference shall point to a SME in an AID submodel known to this application (refer to `add_or_update_config`).
24
25 Example:
26 ```
27 {
28 "Reference": {
29 "type": "ModelReference",
30 "keys": [
31 {
32 "type": "Submodel",
33 "value": "https://fluid40.de/ids/sm/4757_4856_8464_1441"
34 },
35 {
36 "type": "SubmodelElementCollection",
37 "value": "Interface_MQTT"
38 },
39 {
40 "type": "SubmodelElementCollection",
41 "value": "InteractionMetadata"
42 },
43 {
44 "type": "SubmodelElementCollection",
45 "value": "properties"
46 },
47 {
48 "type": "SubmodelElementCollection",
49 "value": "my_endpoint"
50 }
51 ]
52 }
53 }
54 ```
55 """
56
57 aid_ref_dict: dict = Field(..., alias="Reference")
58 _aid_ref: ModelReference = PrivateAttr(default=None)
59
60 def __init__(self, **data: Any): # noqa: D107
61 super().__init__(**data)
62 # aid_string = json.dumps(self.aid_ref_dict)
63 # self._aid_ref = json.loads(aid_string, cls=AASFromJsonDecoder)
65
66 def _build_model_reference(self) -> ModelReference:
67 if self.aid_ref_dict is None:
68 raise ValueError("AID Reference has not been initialized.")
69 key_list = [Key(type_=self._get_key_type(key["type"]), value=key["value"]) for key in self.aid_ref_dict["keys"]]
70 ref: ModelReference = ModelReference(key=tuple(key_list), type_=ModelReference)
72
73 def _get_key_type(self, key_str: str) -> KeyTypes:
74 key_type = KEY_TYPE_MAPPING.get(key_str)
75 if key_type is None:
76 raise ValueError(f"Unknown key type: {key_str}")
77 return KeyTypes[key_type]
Defines the model class of the payload for the get_value (URL /get-value) endpoint of this applicatio...
KeyTypes _get_key_type(self, str key_str)
ModelReference _build_model_reference(self)