From 93b8e0fadf83d5b8cee0e64379ab443a2fbfb9fc Mon Sep 17 00:00:00 2001 From: Teemu R Date: Tue, 30 Jan 2018 22:41:18 +0100 Subject: [PATCH] Make discovery to work with no IP addr and token, courtesy of M0ses (#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 --- miio/click_common.py | 4 ++++ miio/tests/test_click_common.py | 10 ++++++++++ 2 files changed, 14 insertions(+) create mode 100644 miio/tests/test_click_common.py diff --git a/miio/click_common.py b/miio/click_common.py index 4fc773e9c..fdc674eb5 100644 --- a/miio/click_common.py +++ b/miio/click_common.py @@ -17,6 +17,8 @@ def validate_ip(ctx, param, value): + if value is None: + return None try: ipaddress.ip_address(value) return value @@ -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) diff --git a/miio/tests/test_click_common.py b/miio/tests/test_click_common.py new file mode 100644 index 000000000..a889a4b04 --- /dev/null +++ b/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 +