[docs]classCheckPhysicalAssetBehaviour(OneShotBehaviour):""" This class implements the behaviour responsible for check that all information about the physical asset is available in the submodels and also that the connection is established. """def__init__(self,agent_object):""" The constructor method is rewritten to add the object of the agent Args: agent_object (spade.Agent): the SPADE agent object of the AAS Manager agent. """# The constructor of the inherited class is executed.super().__init__()# The SPADE agent object is stored as a variable of the behaviour classself.myagent=agent_object
[docs]asyncdefrun(self):""" This method implements the logic of the behaviour. """# First it is checked if the submodel file exists has to be checkedifSubmodels_utils.check_if_submodel_exists("asset_identification")isFalse:# TODO pensar que hacer en el caso de que no exista (matar al agente?)_logger.error("The submodel asset identification does not exist.")_logger.info("The submodel 'Asset identification' of the asset exists.")# Besides, it is necessary to check whether the connection to the asset is established. To do that, a message# to the AAS Core has to be sent.# Create the valid JSON structure to save in svcRequests.jsoncurrent_interaction_id=self.myagent.interaction_idsvc_request_json=Interactions_utils.create_svc_request_json(interaction_id=current_interaction_id,svc_id='checkAssetConnection',svc_type='AssetRelatedService')# Save the JSON in svcRequests.jsonInteractions_utils.add_new_svc_request(svc_request_json)# Since a new service has been request, the interaction of the agent has to be incrementedself.myagent.interaction_id+=1# Check i# Wait until the service is completed# TODO cambiarlo. No debe haber una espera hasta que se complete el servicio de esta manerawhileTrue:_logger.info("checkAssetConnection service not completed yet.")svc_response=Interactions_utils.get_svc_response_info(current_interaction_id)ifsvc_responseisnotNone:print(svc_response)# Set the service as completed# Write the information in the log fileInteractions_utils.save_svc_info_in_log_file('Manager',AASarchiveInfo.ASSET_RELATED_SVC_LOG_FILENAME,current_interaction_id)# Return message to the sender_logger.info("Service completed! Response: "+str(svc_response))break_logger.info("The connection with the asset is established.")