PurpleAirAPIHelpers module
Utility functions used throughout the PurpleAir API wrapper for common operations such as making HTTP requests, debugging, and data validation.
Overview
This module provides helper functions that are shared across the Read, Write, and Local API modules. These utilities handle HTTP communication, logging, and other common tasks.
API Reference
Copyright 2024 carlkidcrypto, All rights reserved. A python3 file containing helper functions for the PurpleAirAPI** files. https://api.purpleair.com/#api-welcome
- PurpleAirAPIHelpers.convert_requests_text_to_json(text=None) dict
A helper to convert request.text to json.
- Parameters:
text (str) – The request.txt to convert to json
:return dict
- PurpleAirAPIHelpers.debug_log(debug_msg_string)
A helper function to print out debug messages only if DEBUG is defined as True in ‘PurpleAirAPIConstants.py’. Messages will be the color red.
- Parameters:
debug_msg_string (str) – The debug message string
- PurpleAirAPIHelpers.sanitize_sensor_data_from_paa(paa_return_data) dict
A helper function. Since not all sensors support all field names we check that the keys exist in the sensor data. If they do not exist we add it in with a NULL equivalent. i.e 0.0, 0, “”, etc. We access the “sensor” key inside this function.
- Parameters:
paa_return_data (dict) – A dictionary with paa return data
- PurpleAirAPIHelpers.send_url_delete_request(request_url, api_key_to_use, json_post_parameters={})
A class helper to send the url request. It can also add onto the ‘request_url’ string if ‘optional_parameters_dict’ are provided.
- Parameters:
request_url (str) – The constructed string url request string.
- PurpleAirAPIHelpers.send_url_get_request(request_url, api_key_to_use=None, first_optional_parameter_separator=None, optional_parameters_dict=None)
A helper to send the url request. It can also add onto the ‘request_url’ string if ‘optional_parameters_dict’ are provided.
- Parameters:
request_url (str) – The constructed string url request string.
first_optional_parameter_separator (str) – The separator between first parameter in optional_parameters_dict. i.e ‘?’ or ‘&’.
optional_parameters_dict (dict) – Optional parameters that can be added onto the request_url.
- PurpleAirAPIHelpers.send_url_post_request(request_url, api_key_to_use, json_post_parameters={})
A class helper to send the url request. It can also add onto the ‘request_url’ string if ‘optional_parameters_dict’ are provided.
- Parameters:
request_url (str) – The constructed string url request string.
- PurpleAirAPIHelpers.verify_request_status_codes(status_code) bool
A helper to check those status codes. True if in SUCCESS_CODE_LIST False if in ERROR_CODES_LIST