Skip to content

Commit

Permalink
Make discovery to work with no IP addr and token, courtesy of M0ses (#…
Browse files Browse the repository at this point in the history
…198)

* Make discovery to work with no IP addr and token

Obsoletes #194

* Fix linting

* Add simple tests for click_common's validators, code courtesy of M0ses

* make linter happy
  • Loading branch information
rytilahti committed Jan 30, 2018
1 parent 21065f6 commit 93b8e0f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions miio/click_common.py
Expand Up @@ -17,6 +17,8 @@


def validate_ip(ctx, param, value):
if value is None:
return None
try:
ipaddress.ip_address(value)
return value
Expand All @@ -25,6 +27,8 @@ def validate_ip(ctx, param, value):


def validate_token(ctx, param, value):
if value is None:
return None
token_len = len(value)
if token_len != 32:
raise click.BadParameter("Token length != 32 chars: %s" % token_len)
Expand Down
10 changes: 10 additions & 0 deletions miio/tests/test_click_common.py
@@ -0,0 +1,10 @@
from miio.click_common import validate_token, validate_ip


def test_validate_token_empty():
assert not validate_token(None, None, None)


def test_validate_ip_empty():
assert validate_ip(None, None, None) is None

0 comments on commit 93b8e0f

Please sign in to comment.