Asset Connector Documentation
Loading...
Searching...
No Matches
asset_connector.py
Go to the documentation of this file.
1import logging
2
3from aas_standard_parser import AIDParser
4from aas_standard_parser.aid_parser import IAuthenticationDetails
5from basyx.aas.model import ModelReference, SubmodelElementCollection
6
7logger = logging.getLogger(__name__)
8
9
10class IAssetConnector:
11 """Interface for asset connectors.
12 It serves as the base class for any protocol-specific implementations and provides common functionality.
13 """
14
15 def __init__(self, aid_id: str, interface_smc: SubmodelElementCollection):
16 """Initialize the AssetConnector with AID ID and interface submodel collection.
17
18 :param aid_id: The ID of the AID submodel.
19 :param interface_smc: A SubmodelElementCollection inside the AID submodel specifying the asset interface.
20 """
21 self._aid_id = aid_id
22 self._interface = interface_smc
23 self.is_connected = False
24
25 if not self._parse_aid_interface():
26 raise ValueError("Failed to parse AID interface.")
27
28 def _parse_aid_interface(self) -> bool:
29 """Parse the asset interface definition.
30 Extracts authentication details, base address, and property endpoints for connecting to the asset.
31 Stores the extracted information in self._auth, `self.base`, and `self._parsed_properties`."""
32 # extract the base url
33 aid_parser = AIDParser()
34 try:
35 self.base = aid_parser.parse_base(self._interface)
36 self._parsed_properties = aid_parser.parse_properties(self._interface)
37 self._auth: IAuthenticationDetails = aid_parser.parse_security(self._interface)
38 except ValueError as e:
39 logger.error(f"Error parsing aid interface: {e}")
40 return False
41
42 return True
43
44 async def connect(self):
45 """Connect to the asset."""
46
47 async def get_value(self, endpoint_reference: ModelReference) -> str | None:
48 """Get value from the asset for the specified endpoint reference.
49
50 :param endpoint_reference: A reference pointing to an endpoint inside the AID interface specification.
51 """
52
53 async def set_value(self, endpoint_reference: ModelReference, *args):
54 """Set a value on the asset via the specified endpoint.
55
56 :param endpoint_reference: A reference pointing to an endpoint inside the AID interface specification.
57 :param args: Key-value pairs to be written to the endpoint.
58 """
59
60 async def do_action(self, endpoint_reference: ModelReference, *args):
61 """Invoke action on the asset for the specified endpoint reference.
62 Not implemented yet.
63
64 :param endpoint_reference: A reference pointing to an endpoint inside the AID interface specification.
65 :param args: Key-value pairs as parameters to the invoked action.
66 """
do_action(self, ModelReference endpoint_reference, *args)
Invoke action on the asset for the specified endpoint reference.
set_value(self, ModelReference endpoint_reference, *args)
Set a value on the asset via the specified endpoint.
__init__(self, str aid_id, SubmodelElementCollection interface_smc)
Initialize the AssetConnector with AID ID and interface submodel collection.
bool _parse_aid_interface(self)
Parse the asset interface definition.
str|None get_value(self, ModelReference endpoint_reference)
Get value from the asset for the specified endpoint reference.