aas_repository
aas_client3_2.aas_repository implements the Asset Administration Shell Repository API: it stores the shells, their asset information and thumbnails, and gives access to their submodels through the shells.
We introduced the basic operations in Create a Shell with Submodels and Change the Shell and its Submodels.
import requests
import aas_core3_2.types as aas_types
from aas_client3_2 import (
aas_repository as aas_client_aas_repository,
http as aas_client_http,
pagination as aas_client_pagination,
requests_transport as aas_client_requests_transport,
submodel_repository as aas_client_submodel_repository,
)
transport = aas_client_requests_transport.RequestsTransport(
requests.Session()
)
server = aas_client_http.Server(
transport=transport, base_url="http://localhost:5004"
)
submodel_repository_server = aas_client_http.Server(
transport=transport, base_url="http://localhost:5005"
)
shell = aas_types.AssetAdministrationShell(
id="https://example.com/ids/aas/getting-started/aas-repository",
id_short="Pump",
asset_information=aas_types.AssetInformation(
asset_kind=aas_types.AssetKind.INSTANCE,
global_asset_id="https://example.com/ids/asset/pump-0007",
),
)
aas_client_aas_repository.post_asset_administration_shell(
server, shell
)
Find Shells
The listing filters the shells by their ID-short, or by the IDs of their assets:
def get_page(cursor):
return (
aas_client_aas_repository.get_all_asset_administration_shells(
server, id_short="Pump", cursor=cursor
)
)
for a_shell in aas_client_pagination.iterate(get_page):
print(a_shell.id)
# Prints:
# https://example.com/ids/aas/getting-started/aas-repository
Read and Change the Asset Information
The asset information can be read and replaced without the rest of the shell:
asset_information = aas_client_aas_repository.get_asset_information(
server, shell.id
)
print(asset_information.global_asset_id)
# Prints: https://example.com/ids/asset/pump-0007
asset_information.specific_asset_ids = [
aas_types.SpecificAssetID(name="serialNumber", value="0007")
]
aas_client_aas_repository.put_asset_information(
server, shell.id, asset_information
)
Submodels through the Shell
The repository also serves the submodels of a shell under the shell itself, so you can work with a submodel knowing only the shell. These functions take the identifier of the shell and of the submodel, and otherwise work as those of submodel_repository. Here, the submodel lives in the Submodel Repository, and the shell refers to it:
operating_hours = aas_types.Submodel(
id="https://example.com/ids/sm/getting-started/operating-hours",
id_short="OperatingHours",
submodel_elements=[
aas_types.Property(
id_short="Total",
value_type=aas_types.DataTypeDefXSD.INT,
value="1200",
),
],
)
aas_client_submodel_repository.post_submodel(
submodel_repository_server, operating_hours
)
aas_client_aas_repository.post_submodel_reference(
server,
shell.id,
aas_types.Reference(
type=aas_types.ReferenceTypes.MODEL_REFERENCE,
keys=[
aas_types.Key(
type=aas_types.KeyTypes.SUBMODEL,
value=operating_hours.id,
)
],
),
)
total = (
aas_client_aas_repository.get_submodel_element_by_path_value_only(
server, shell.id, operating_hours.id, "Total"
)
)
print(total)
# Prints: 1200.0
Clean Up
Delete what we created in this chapter, so that you can run the code of this chapter again. The identifiers are unique, so the server would refuse to create the shell and the submodel a second time:
aas_client_aas_repository.delete_asset_administration_shell_by_id(
server, shell.id
)
aas_client_submodel_repository.delete_submodel_by_id(
submodel_repository_server, operating_hours.id
)