Skip to content

Commit

Permalink
Merge pull request #9 from jordanh/make-static
Browse files Browse the repository at this point in the history
Makes get_local_current_sample static
  • Loading branch information
jordanh committed May 30, 2016
2 parents 83f7254 + 20f9210 commit 8c2f457
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 6 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).

## [0.3.1]
### Changes
- Made `get_local_current_sample()` method static.

## [0.3.0]
### Added
- Added method get_local_current_sample for querying sensor on local network
Expand Down Expand Up @@ -72,6 +76,8 @@ This project adheres to [Semantic Versioning](http://semver.org/).
### Added
- Initial release

[0.3.1]: https://github.com/jordanh/neurio-python/compare/0.3.0...0.3.1
[0.3.0]: https://github.com/jordanh/neurio-python/compare/0.2.10...0.3.0
[0.3.0]: https://github.com/jordanh/neurio-python/compare/0.2.10...0.3.0
[0.2.10]: https://github.com/jordanh/neurio-python/compare/0.2.9...0.2.10
[0.2.9]: https://github.com/jordanh/neurio-python/compare/0.2.8...0.2.9
Expand Down
12 changes: 10 additions & 2 deletions neurio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
except ImportError:
from urllib.parse import urlparse, parse_qsl, urlunparse

__version__ = "0.3.0"
__version__ = "0.3.1"

class TokenProvider(object):
__key = None
Expand Down Expand Up @@ -88,6 +88,11 @@ def __init__(self, token_provider):
Args:
token_provider (TokenProvider): object providing authentication services
"""
if token_provider is None:
raise ValueError("token_provider is required")
if not isinstance(token_provider, TokenProvider):
raise ValueError("token_provider must be instance of TokenProvider")

self.__token = token_provider.get_token()

def __gen_headers(self):
Expand Down Expand Up @@ -381,9 +386,12 @@ def get_appliance_stats_by_location(self, location_id, start, end, granularity=N
r = requests.get(url, headers=headers)
return r.json()

def get_local_current_sample(self, ip):
@staticmethod
def get_local_current_sample(ip):
"""Gets current sample from *local* Neurio device IP address.
This is a static method. It doesn't require a token to authenticate.
Note, call get_user_information to determine local Neurio IP addresses.
Args:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
setup(
name = 'neurio',
packages = ['neurio'],
version = "0.3.0",
version = "0.3.1",
description = 'Neurio energy sensor and appliance automation API library',
author = 'Jordan Husney',
author_email = '[email protected]',
Expand Down
8 changes: 8 additions & 0 deletions tests/auth_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ def test_token_provider_invalid_credentials(self):
with self.assertRaises(Exception):
tp.get_token()

def test_token_provider_none(self):
with self.assertRaises(ValueError):
neurio.Client(token_provider=None)

def test_token_provider_type(self):
with self.assertRaises(ValueError):
neurio.Client(token_provider=object())


if __name__ == '__main__':
unittest.main()
7 changes: 4 additions & 3 deletions tests/local_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,17 @@ def test_local_current_sample(self):
for sensor in sublist if sensor['sensorType'] == 'neurio'
]
self.assertGreater(len(ips), 0)
sample = self.nc.get_local_current_sample(ips[0])
# test static method:
sample = neurio.Client.get_local_current_sample(ips[0])
self.assertGreater(len(sample['timestamp']), 0)

def test_local_current_sample_ip_arg(self):
bad_ip1 = "hostname.domain"
with self.assertRaises(ValueError):
self.nc.get_local_current_sample(bad_ip1)
neurio.Client.get_local_current_sample(bad_ip1)
bad_ip2 = "255.256.257.258"
with self.assertRaises(ValueError):
self.nc.get_local_current_sample(bad_ip2)
neurio.Client.get_local_current_sample(bad_ip2)


if __name__ == '__main__':
Expand Down

0 comments on commit 8c2f457

Please sign in to comment.