Skip to main content

Device Ready

Description

The device_ready function sends a POST request to notify the web service that a device is ready, providing device and agent details. It returns the response code and response string after making the request.

Function Signature:

def device_ready(ws_config: WebServiceConfig, device_name: str, agent_type: str, agent_version: str, agent_index: int, process_id: int) -> tuple[int, str]:

Parameters

  • ws_config (WebServiceConfig): Configuration for the web service connection.
  • device_name (str): The name of the device being notified as ready.
  • agent_type (str): The type of the agent.
  • agent_version (str): The version of the agent.
  • agent_index (int): The index of the agent.
  • process_id (int): The process ID of the agent.

Returns

  • tuple[int, str]: The response code and the response string from the web service. If an error occurs, -1 and an error message are returned.

Example Usage

ws_config = WebServiceConfig(base_url="https://api.actionstreamer.com")
device_name = "Device123"
agent_type = "TypeA"
agent_version = "1.0"
agent_index = 1
process_id = 1234
response_code, response_string = device_ready(ws_config, device_name, agent_type, agent_version, agent_index, process_id)

Behavior

  • The function prepares a JSON payload with details about the device and agent.
  • It sends a POST request to the web service using the send_signed_request function.
  • The response from the web service is returned, or an error message is printed if an exception occurs.

Error Handling

  • General Exception: Any errors during the request (e.g., connection issues or invalid response) will be caught, and an error message will be printed.
  • Exception Information: If an error occurs, the function prints the filename and line number for easier debugging.