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

Make discovery to work with no IP addr and token, courtesy of M0ses #198

Merged
merged 4 commits into from
Jan 30, 2018
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
4 changes: 4 additions & 0 deletions miio/click_common.py
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

blank line at end of file