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

Add JSON output for easier integration with other tools #98

Closed
MaxRei-dev opened this issue Oct 21, 2017 · 10 comments
Closed

Add JSON output for easier integration with other tools #98

MaxRei-dev opened this issue Oct 21, 2017 · 10 comments

Comments

@MaxRei-dev
Copy link

Hi,
not in debug or in status. where to find ?
Thanks

@rytilahti
Copy link
Owner

Could you be more precise what are you trying to do? For vacuum the is_on can be found in the status object: https:/rytilahti/python-miio/blob/master/miio/vacuumcontainers.py#L195 which is returned when status() is called.

@MaxRei-dev
Copy link
Author

SRY for the delay.

hmm if i call mirobo script and check for status, is_on is not returned. also not with debug.

mirobo, version 0.3.0

State: Charging Battery: 100 % Fanspeed: 77 % Cleaning since: 0:00:00 Cleaned area: 0.5025 m²

{'result': [{'error_code': 0, 'battery': 100, 'dnd_enabled': 1, 'map_present': 0, 'state': 8, 'clean_time': 0, 'msg_seq': 594, 'fan_power': 77, 'msg_ver': 5, 'in_cleaning': 0, 'clean_area': 502500}], 'id': 9455}

@rytilahti
Copy link
Owner

Like shown in the link I gave above, it just checks if the state variable is one of the listed ones, this will catch also manual & spot cleaning besides the normal automated one. This is done as the in_cleaning variable was sometimes inconsistent based on my experience what the robot was really doing (out of sync or just not working all times?).

@MaxRei-dev
Copy link
Author

Yes you are right. In_cleaning always returnes 0 for me (also in automatic and manual cleaning). But why is in_cleaning returned and not is_on (in Version 0.3.0). I dont understand this.
Side note. A json only output like in debug mode would be great.
Thank you

@rytilahti
Copy link
Owner

Neither of them is not returned if I'm not mistaken. Instead of it the state (pretty printed status) is returned if you call mirobo status, and only place I see in_cleaning is the commented out echo in it. Where do you see that in_cleaning is returned?

JSON mode is not currently planned as using the API is preferred, however I'm welcome for PRs (and if you want, you can open another issue for that).

@MaxRei-dev
Copy link
Author

in debug you see:
{'result': [{'error_code': 0, 'battery': 100, 'dnd_enabled': 1, 'map_present': 0, 'state': 8, 'clean_time': 0, 'msg_seq': 594, 'fan_power': 77, 'msg_ver': 5, 'in_cleaning': 0, 'clean_area': 502500}], 'id': 9455}
i'am using debug because there is no json output. (i phrase is in node red an put it over to MQTT. )

@rytilahti
Copy link
Owner

Oh, you probably should not be parsing the raw data, but maybe it makes sense to add a JSON output, so I'll just rename the issue. Adding that is not a priority of mine, but if someone wants to work on it I'll accept PRs on that.

@rytilahti rytilahti changed the title is_on Add JSON output for easier integration with other tools Oct 26, 2017
@MaxRei-dev
Copy link
Author

puhhh. ok thanks. i tried this last night, but i don't even know how to start.....
Any hint how to start. it looks not to complicated but i dont know how the 3 vacuum files are tied together ..
Thank you for an hint how to start ..
Thanks

@rytilahti
Copy link
Owner

I think the way to go with this would be to add a new --json option to cli, and implement it for each command / use a decorator to do the magic. This is however not a simple feat, would it be just easier for your use-case to have a separate script calling the wanted methods and using json.dumps() to do the conversion to JSON?

@rytilahti
Copy link
Owner

This will be available in the upcoming 0.4.0 release, see #191. Usage:

$ miiocli -o json_pretty vacuum --token XXXXX --ip 192.168.XXX.XXX status
{
  "msg_ver": 8,
  "msg_seq": 5092,
  "state": 8,
  "battery": 100,
  "clean_time": 1384,
  "clean_area": 22242500,
  "error_code": 0,
  "map_present": 1,
  "in_cleaning": 0,
  "fan_power": 60,
  "dnd_enabled": 0
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants