Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/multiple local network sensors #19

Merged
merged 3 commits into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified docs/doctrees/PurpleAirLocalAPI.doctree
Binary file not shown.
Binary file modified docs/doctrees/environment.pickle
Binary file not shown.
2 changes: 1 addition & 1 deletion docs/html/.buildinfo
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Sphinx build info version 1
# This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done.
config: 2fb0fde188d98b30d7936f902f8a9d8a
config: 0e3dd2b003b323d457484d3d023fbd15
tags: 645f666f9bcd5a90fca523b33c5a78b7
2 changes: 1 addition & 1 deletion docs/html/PurpleAirAPI.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<meta charset="utf-8" /><meta name="generator" content="Docutils 0.18.1: http://docutils.sourceforge.net/" />

<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>PurpleAirAPI module &mdash; PurpleAir API V1.1.0 documentation</title>
<title>PurpleAirAPI module &mdash; PurpleAir API V1.1.1a0 documentation</title>
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<link rel="stylesheet" href="_static/css/theme.css" type="text/css" />
<!--[if lt IE 9]>
Expand Down
2 changes: 1 addition & 1 deletion docs/html/PurpleAirAPIConstants.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<meta charset="utf-8" /><meta name="generator" content="Docutils 0.18.1: http://docutils.sourceforge.net/" />

<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>PurpleAirAPIConstants module &mdash; PurpleAir API V1.1.0 documentation</title>
<title>PurpleAirAPIConstants module &mdash; PurpleAir API V1.1.1a0 documentation</title>
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<link rel="stylesheet" href="_static/css/theme.css" type="text/css" />
<!--[if lt IE 9]>
Expand Down
2 changes: 1 addition & 1 deletion docs/html/PurpleAirAPIError.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<meta charset="utf-8" /><meta name="generator" content="Docutils 0.18.1: http://docutils.sourceforge.net/" />

<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>PurpleAirAPIError module &mdash; PurpleAir API V1.1.0 documentation</title>
<title>PurpleAirAPIError module &mdash; PurpleAir API V1.1.1a0 documentation</title>
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<link rel="stylesheet" href="_static/css/theme.css" type="text/css" />
<!--[if lt IE 9]>
Expand Down
2 changes: 1 addition & 1 deletion docs/html/PurpleAirAPIHelpers.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<meta charset="utf-8" /><meta name="generator" content="Docutils 0.18.1: http://docutils.sourceforge.net/" />

<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>PurpleAirAPIHelpers module &mdash; PurpleAir API V1.1.0 documentation</title>
<title>PurpleAirAPIHelpers module &mdash; PurpleAir API V1.1.1a0 documentation</title>
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<link rel="stylesheet" href="_static/css/theme.css" type="text/css" />
<!--[if lt IE 9]>
Expand Down
13 changes: 9 additions & 4 deletions docs/html/PurpleAirLocalAPI.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<meta charset="utf-8" /><meta name="generator" content="Docutils 0.18.1: http://docutils.sourceforge.net/" />

<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>PurpleAirLocalAPI module &mdash; PurpleAir API V1.1.0 documentation</title>
<title>PurpleAirLocalAPI module &mdash; PurpleAir API V1.1.1a0 documentation</title>
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<link rel="stylesheet" href="_static/css/theme.css" type="text/css" />
<!--[if lt IE 9]>
Expand Down Expand Up @@ -95,13 +95,18 @@
<a class="reference external" href="https://api.purpleair.com/#api-welcome">https://api.purpleair.com/#api-welcome</a></p>
<dl class="py class">
<dt class="sig sig-object py" id="PurpleAirLocalAPI.PurpleAirLocalAPI">
<em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">PurpleAirLocalAPI.</span></span><span class="sig-name descname"><span class="pre">PurpleAirLocalAPI</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">ipv4_address</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#PurpleAirLocalAPI.PurpleAirLocalAPI" title="Permalink to this definition"></a></dt>
<em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">PurpleAirLocalAPI.</span></span><span class="sig-name descname"><span class="pre">PurpleAirLocalAPI</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">ipv4_address_list</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#PurpleAirLocalAPI.PurpleAirLocalAPI" title="Permalink to this definition"></a></dt>
<dd><p>Bases: <code class="xref py py-class docutils literal notranslate"><span class="pre">object</span></code></p>
<p>The PurpleAirLocalAPI class designed to send valid
local network requests.</p>
local network requests. It can work with one or many IPv4 addresses.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters<span class="colon">:</span></dt>
<dd class="field-odd"><p><strong>ipv4_address_list</strong> (<em>list</em>) – A list of strings with valid IPv4 addresses for your sensors. The addresses don’t need a CIDR.</p>
</dd>
</dl>
<dl class="py method">
<dt class="sig sig-object py" id="PurpleAirLocalAPI.PurpleAirLocalAPI.request_local_sensor_data">
<span class="sig-name descname"><span class="pre">request_local_sensor_data</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#PurpleAirLocalAPI.PurpleAirLocalAPI.request_local_sensor_data" title="Permalink to this definition"></a></dt>
<span class="sig-name descname"><span class="pre">request_local_sensor_data</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span> <span class="sig-return"><span class="sig-return-icon">&#x2192;</span> <span class="sig-return-typehint"><span class="pre">dict</span></span></span><a class="headerlink" href="#PurpleAirLocalAPI.PurpleAirLocalAPI.request_local_sensor_data" title="Permalink to this definition"></a></dt>
<dd><p>A method to request a local sensors data. This sensor must be in a netork that is accessible</p>
</dd></dl>

Expand Down
2 changes: 1 addition & 1 deletion docs/html/PurpleAirReadAPI.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<meta charset="utf-8" /><meta name="generator" content="Docutils 0.18.1: http://docutils.sourceforge.net/" />

<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>PurpleAirReadAPI module &mdash; PurpleAir API V1.1.0 documentation</title>
<title>PurpleAirReadAPI module &mdash; PurpleAir API V1.1.1a0 documentation</title>
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<link rel="stylesheet" href="_static/css/theme.css" type="text/css" />
<!--[if lt IE 9]>
Expand Down
2 changes: 1 addition & 1 deletion docs/html/PurpleAirWriteAPI.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<meta charset="utf-8" /><meta name="generator" content="Docutils 0.18.1: http://docutils.sourceforge.net/" />

<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>PurpleAirWriteAPI module &mdash; PurpleAir API V1.1.0 documentation</title>
<title>PurpleAirWriteAPI module &mdash; PurpleAir API V1.1.1a0 documentation</title>
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<link rel="stylesheet" href="_static/css/theme.css" type="text/css" />
<!--[if lt IE 9]>
Expand Down
2 changes: 1 addition & 1 deletion docs/html/_static/documentation_options.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var DOCUMENTATION_OPTIONS = {
URL_ROOT: document.getElementById("documentation_options").getAttribute('data-url_root'),
VERSION: 'V1.1.0',
VERSION: 'V1.1.1a0',
LANGUAGE: 'en',
COLLAPSE_INDEX: false,
BUILDER: 'html',
Expand Down
2 changes: 1 addition & 1 deletion docs/html/genindex.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Index &mdash; PurpleAir API V1.1.0 documentation</title>
<title>Index &mdash; PurpleAir API V1.1.1a0 documentation</title>
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<link rel="stylesheet" href="_static/css/theme.css" type="text/css" />
<!--[if lt IE 9]>
Expand Down
2 changes: 1 addition & 1 deletion docs/html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<meta charset="utf-8" /><meta name="generator" content="Docutils 0.18.1: http://docutils.sourceforge.net/" />

<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Welcome to PurpleAirAPI’s documentation! &mdash; PurpleAir API V1.1.0 documentation</title>
<title>Welcome to PurpleAirAPI’s documentation! &mdash; PurpleAir API V1.1.1a0 documentation</title>
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<link rel="stylesheet" href="_static/css/theme.css" type="text/css" />
<!--[if lt IE 9]>
Expand Down
2 changes: 1 addition & 1 deletion docs/html/modules.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<meta charset="utf-8" /><meta name="generator" content="Docutils 0.18.1: http://docutils.sourceforge.net/" />

<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>purpleair_api &mdash; PurpleAir API V1.1.0 documentation</title>
<title>purpleair_api &mdash; PurpleAir API V1.1.1a0 documentation</title>
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<link rel="stylesheet" href="_static/css/theme.css" type="text/css" />
<!--[if lt IE 9]>
Expand Down
2 changes: 1 addition & 1 deletion docs/html/py-modindex.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Python Module Index &mdash; PurpleAir API V1.1.0 documentation</title>
<title>Python Module Index &mdash; PurpleAir API V1.1.1a0 documentation</title>
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<link rel="stylesheet" href="_static/css/theme.css" type="text/css" />
<!--[if lt IE 9]>
Expand Down
2 changes: 1 addition & 1 deletion docs/html/search.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Search &mdash; PurpleAir API V1.1.0 documentation</title>
<title>Search &mdash; PurpleAir API V1.1.1a0 documentation</title>
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
<link rel="stylesheet" href="_static/css/theme.css" type="text/css" />

Expand Down
2 changes: 1 addition & 1 deletion docs/html/searchindex.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion purpleair_api/PurpleAirAPI.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def __init__(
retval_api_write_key = self._check_an_api_key(your_api_write_key)

if your_ipv4_address is not None:
PurpleAirLocalAPI.__init__(self, ipv4_address=your_ipv4_address)
PurpleAirLocalAPI.__init__(self, ipv4_address_list=your_ipv4_address)

if retval_api_read_key is not None:
if self._api_key_types[your_api_read_key] == "READ":
Expand Down
35 changes: 27 additions & 8 deletions purpleair_api/PurpleAirLocalAPI.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,43 @@
class PurpleAirLocalAPI:
"""
The PurpleAirLocalAPI class designed to send valid
local network requests.
local network requests. It can work with one or many IPv4 addresses.

:param list ipv4_address_list: A list of strings with valid IPv4 addresses for your sensors. The addresses don't need a CIDR.
"""

def __init__(self, ipv4_address=None):
def __init__(self, ipv4_address_list=None):
# Create the vase API request string for local networks.
error_msg = "Must provide the IPv4 address for the senson on your local network"
error_msg = (
"Must provide the IPv4 address list for the sensor(s) on your local network"
)

if type(ipv4_address) is type(None):
if type(ipv4_address_list) is type(None):
raise PurpleAirAPIError(error_msg)

elif len(ipv4_address) == 0:
elif type(ipv4_address_list) is not type(list()):
raise PurpleAirAPIError(error_msg)

self._base_api_local_network_request_string = f"http://{ipv4_address}/json"
for address in ipv4_address_list:
if len(address) == 0 or len(address) > 15:
raise PurpleAirAPIError(error_msg)

self._base_api_local_network_request_string_dict = dict()
for address in ipv4_address_list:
self._base_api_local_network_request_string_dict[
address
] = f"http://{address}/json"

def request_local_sensor_data(self):
def request_local_sensor_data(self) -> dict:
"""
A method to request a local sensors data. This sensor must be in a netork that is accessible
"""

return send_url_get_request(self._base_api_local_network_request_string)
retval = {}
for key, value in self._base_api_local_network_request_string_dict.items():
print("key", key)
print("value", value)
request_value = send_url_get_request(value)
retval[key] = request_value

return retval
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def read_file(filename):

setup(
name="purpleair_api",
version="1.1.0",
version="1.1.1a0",
license="MIT",
author="Carlos Santos",
author_email="dose.lucky.sake@cloak.id",
Expand Down
2 changes: 1 addition & 1 deletion sphinx_docs_build/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
author = "carlkidcrypto"

# The full version, including alpha/beta/rc tags
release = "V1.1.0"
release = "V1.1.1a0"


# -- General configuration ---------------------------------------------------
Expand Down
9 changes: 6 additions & 3 deletions test/test_purpleair_local_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

class PurpleAirLocalAPITest(unittest.TestCase):
def setUp(self):
self.pala = PurpleAirLocalAPI("192.168.1.2")
self.pala = PurpleAirLocalAPI(["192.168.1.2"])

def tearDown(self):
self.pala = None
Expand Down Expand Up @@ -48,7 +48,7 @@ def test_request_local_sensor_data_none_ip_provided(self):
with self.assertRaises(PurpleAirAPIError):
self.pala = PurpleAirLocalAPI(None)

def test_request_local_sensor_data_empty_string_ip_provided(self):
def test_request_local_sensor_data_empty_list_ip_provided(self):
"""
Test that providing no IP address results in a `PurpleAirAPIError`
"""
Expand All @@ -58,7 +58,10 @@ def test_request_local_sensor_data_empty_string_ip_provided(self):
self.pala = PurpleAirLocalAPI(None)

with self.assertRaises(PurpleAirAPIError):
self.pala = PurpleAirLocalAPI("")
self.pala = PurpleAirLocalAPI(["", ""])

with self.assertRaises(PurpleAirAPIError):
self.pala = PurpleAirLocalAPI({})


if __name__ == "__main__":
Expand Down
Loading