1"""Utility functions for working with the BaSyx SDK framework objects."""
7import basyx.aas.adapter.json
8from basyx.aas
import model
10_logger = logging.getLogger(__name__)
14 """Add a given Submodel correctly to a provided AssetAdministrationShell.
16 :param aas: provided AssetAdministrationShell to which the Submodel should be added
17 :param submodel: given Submodel to add
19 aas.submodel.add(model.ModelReference.from_referable(submodel))
23 """Remove a given Submodel correctly from a provided AssetAdministrationShell.
25 :param aas: provided AssetAdministrationShell from which the Submodel should be removed
26 :param submodel: given Submodel to remove
28 aas.submodel.remove(model.ModelReference.from_referable(submodel))
31def convert_to_object(content: dict) -> Any |
None:
32 """Convert a dictionary to a BaSyx SDK framework object.
34 :param content: dictionary to convert
35 :return: BaSyx SDK framework object or None
37 if not content
or len(content) == 0:
38 _logger.debug(
"Empty content provided for conversion to object.")
42 dict_string = json.dumps(content)
43 return json.loads(dict_string, cls=basyx.aas.adapter.json.json_deserialization.AASFromJsonDecoder)
44 except Exception
as e:
45 _logger.error(f
"Decoding error: {e}")
46 _logger.error(f
"In JSON: {content}")
50def convert_to_dict(object: Any) -> dict |
None:
51 """Convert a BaSyx SDK framework object. to a dictionary.
53 :param object: BaSyx SDK framework object to convert
54 :return: dictionary representation of the object or None
57 _logger.debug(
"Empty object provided for conversion to dictionary.")
61 data_string = json.dumps(object, cls=basyx.aas.adapter.json.AASToJsonEncoder)
62 model_dict = json.loads(data_string)
64 except Exception
as e:
65 _logger.error(f
"Encoding error: {e}")
66 _logger.error(f
"In object: {object}")