diff --git a/demos/demo2/README.md b/demos/demo2/README.md index e6c5d9bb175866e1f53a322797c940f9601c4e36..242e50f877fd65433db4b7a706f36744a448c6b4 100644 --- a/demos/demo2/README.md +++ b/demos/demo2/README.md @@ -1,3 +1,5 @@ +### General + The latest version of the demo consists mainly of three communication partners: demo2_dzwald.py, demo2_forestmanager.py (which represents the Dienstleister) and demo2_forestmanager_waldbesitzer.py (which as the name implies represents the forest owner). demo2_dzwald.py uses the S3IBServer Component from broker_api.py to expose an underlying AAS through the AAS-Interface. @@ -95,6 +97,46 @@ event: model.BasicEventElement = await client.getValue(dzwald_id, dzwald_endpoin /submodel/submodelElements/Auftragsstatus_Updated") auftragsstatus_updated = await client.awaitEvent(event.message_topic) ``` +### Operations + +Operation Submodelelements can be thought of operation descriptions. The actual callable/invokable is added to the S3IBServer (alongside the operation path for authorization purposes): + +``` +getHolzpreisbereich_op = model.Operation( + id_short="getHolzpreisbereich", + input_variable=[model.OperationVariable(model.Property( + id_short="HolzlisteId", + value_type=model.datatypes.String + ))] + ) +holzliste.add_referable(getHolzpreisbereich_op) + +... + +def getHolzpreisbereich(provider: api.ModelProvider, HolzlisteId: str): + ... + return reply + +... + +callable = lambda **kwargs : getHolzpreisbereich(provider, **kwargs) +operation_path = f"/aas/submodels/{helpers.encode_id(HolzlisteId)}/submodel/submodelElements/getHolzpreisbereich" +server.add_callable(operation_path, callable) + +``` + +Invoke the Operation using S3IBAsyncClient's invokeOperation method: + +``` +HolzlisteId = "https://www.company.com/holzliste/1" +reply4 = await client.invokeOperation( + dzwald_id, + dzwald_endpoint, + f"/aas/submodels/{helpers.encode_id(HolzlisteId)}/submodel/submodelElements/getHolzpreisbereich", + {"HolzlisteId": HolzlisteId} +) +print(f"result of operation 'getHolzpreisbereich': {reply4}") +```