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

Fix 'mirobo discover' without --ip and --token #194

Closed
wants to merge 1 commit into from

Conversation

M0ses
Copy link

@M0ses M0ses commented Jan 28, 2018

This patch fixes cli parameter validation for discover command:

  • by returning a default ip if None is passed to validate_ip
  • by catching the TypeError if None is passed to validate_token

without this patch I get the following errors

...:~/prj/python-miio/miio> mirobo discover --handshake 1
Usage: mirobo [OPTIONS] COMMAND [ARGS]...

Error: Invalid value for "--ip": Invalid IP: None does not appear to be an IPv4 or IPv6 address

and

...:~/prj/python-miio/miio> mirobo --ip 192.168.8.1 discover --handshake 1
Traceback (most recent call last):
  File "/usr/bin/mirobo", line 11, in <module>
    load_entry_point('python-miio==0.3.4', 'console_scripts', 'mirobo')()
  File "/usr/lib/python3.6/site-packages/miio/click_common.py", line 43, in __call__
    return self.main(*args, **kwargs)
  File "/usr/lib/python3.6/site-packages/click/core.py", line 696, in main
    with self.make_context(prog_name, args, **extra) as ctx:
  File "/usr/lib/python3.6/site-packages/click/core.py", line 621, in make_context
    self.parse_args(ctx, args)
  File "/usr/lib/python3.6/site-packages/click/core.py", line 1018, in parse_args
    rest = Command.parse_args(self, ctx, args)
  File "/usr/lib/python3.6/site-packages/click/core.py", line 880, in parse_args
    value, args = param.handle_parse_result(ctx, opts, args)
  File "/usr/lib/python3.6/site-packages/click/core.py", line 1404, in handle_parse_result
    self.callback, ctx, self, value)
  File "/usr/lib/python3.6/site-packages/click/core.py", line 78, in invoke_param_callback
    return callback(ctx, param, value)
  File "/usr/lib/python3.6/site-packages/miio/click_common.py", line 28, in validate_token
    token_len = len(value)
TypeError: object of type 'NoneType' has no len()

@M0ses M0ses force-pushed the fix_discovery_without_token branch from a19facb to 2f94d47 Compare January 29, 2018 00:00
This patch fixes cli parameter validation for `discover` command:

* by returning a default ip if `None` is passed to `validate_ip`
* by catching the TypeError if `None` is passed to `validate_token`

without this patch I get the following errors

```
...:~/prj/python-miio/miio> mirobo discover --handshake 1
Usage: mirobo [OPTIONS] COMMAND [ARGS]...

Error: Invalid value for "--ip": Invalid IP: None does not appear to be an IPv4 or IPv6 address
```

and

```
...:~/prj/python-miio/miio> mirobo --ip 192.168.8.1 discover --handshake 1
Traceback (most recent call last):
  File "/usr/bin/mirobo", line 11, in <module>
    load_entry_point('python-miio==0.3.4', 'console_scripts', 'mirobo')()
  File "/usr/lib/python3.6/site-packages/miio/click_common.py", line 43, in __call__
    return self.main(*args, **kwargs)
  File "/usr/lib/python3.6/site-packages/click/core.py", line 696, in main
    with self.make_context(prog_name, args, **extra) as ctx:
  File "/usr/lib/python3.6/site-packages/click/core.py", line 621, in make_context
    self.parse_args(ctx, args)
  File "/usr/lib/python3.6/site-packages/click/core.py", line 1018, in parse_args
    rest = Command.parse_args(self, ctx, args)
  File "/usr/lib/python3.6/site-packages/click/core.py", line 880, in parse_args
    value, args = param.handle_parse_result(ctx, opts, args)
  File "/usr/lib/python3.6/site-packages/click/core.py", line 1404, in handle_parse_result
    self.callback, ctx, self, value)
  File "/usr/lib/python3.6/site-packages/click/core.py", line 78, in invoke_param_callback
    return callback(ctx, param, value)
  File "/usr/lib/python3.6/site-packages/miio/click_common.py", line 28, in validate_token
    token_len = len(value)
TypeError: object of type 'NoneType' has no len()
```
@M0ses M0ses force-pushed the fix_discovery_without_token branch from 2f94d47 to 06d133a Compare January 29, 2018 00:05
@coveralls
Copy link

coveralls commented Jan 29, 2018

Coverage Status

Coverage increased (+0.4%) to 67.374% when pulling 06d133a on M0ses:fix_discovery_without_token into a50c722 on rytilahti:master.

@rytilahti
Copy link
Owner

Hi and thanks for the patch (and especially pointing this out, I always had my env variables defined)!

I created a patch which feels to me simpler than this one, see #198 . What do you think?

rytilahti added a commit that referenced this pull request Jan 30, 2018
…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
@rytilahti
Copy link
Owner

Fixed with #198.

@rytilahti rytilahti closed this Jan 30, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants