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 test_properties command to device class #1014

Merged
merged 3 commits into from
Apr 11, 2021
Merged

Conversation

rytilahti
Copy link
Owner

@rytilahti rytilahti commented Apr 10, 2021

This allows simple testing of available properties, their values & the number of properties that can be requested at once.
This is done in two steps:

  1. Testing all given properties one by one to see which return non-None/non-empty values
  2. Testing all valid values using a single request, and removing items one by one on failures to obtain usable obtain the max_properties value

Example output:

$ miiocli device --ip <addr> --token <token> test_properties power on off usb_on temperature wifi_led foofoo x
Running command test_properties
Testing properties ('power', 'on', 'off', 'usb_on', 'temperature', 'wifi_led', 'foofoo', 'x') for zimi.powerstrip.v2
Testing power.. on <class 'str'>
Testing on.. None
Testing off.. None
Testing usb_on.. None
Testing temperature.. 46.07 <class 'float'>
Testing wifi_led.. off <class 'str'>
Testing foofoo.. None
Testing x.. None
Found 8 valid properties, testing max_properties..
Testing 8 properties at once.. OK for 8 properties

Please copy the results below to your report
Model: zimi.powerstrip.v2
Total responsives: 8
Total non-empty: 3
All non-empty properties:
{'power': 'on', 'temperature': 46.07, 'wifi_led': 'off'}
Max properties: 8
Done

image

Closes #919

This allows simple testing of available properties, their values & the number of properties that can be requested at once.
This is done in two steps:
1. Testing all given properties one by one to see which return non-None values
2. Testing all valid, non-None values at once and removing properties to request on failures to obtain the max_properties value

Example output:

```
$ miiocli device --ip <addr> --token <token> test_properties power on off usb_on temperature wifi_led foofoo x
Running command test_properties
Testing properties ('power', 'on', 'off', 'usb_on', 'temperature', 'wifi_led', 'foofoo', 'x') for zimi.powerstrip.v2
Testing power.. on <class 'str'>
Testing on.. None
Testing off.. None
Testing usb_on.. None
Testing temperature.. 46.07 <class 'float'>
Testing wifi_led.. off <class 'str'>
Testing foofoo.. None
Testing x.. None
Found 8 valid properties, testing max_properties..
Testing 8 properties at once.. OK for 8 properties

Please copy the results below to your report
Model: zimi.powerstrip.v2
Total responsives: 8
Total non-empty: 3
All non-empty properties:
{'power': 'on', 'temperature': 46.07, 'wifi_led': 'off'}
Max properties: 8
Done
```
@syssi
Copy link
Collaborator

syssi commented Apr 10, 2021

Awesome!

@rytilahti
Copy link
Owner Author

Another example from my vacuum that doesn't support properties (nor info), so it shouldn't crash on unexpected replies:

$ miiocli device --ip $MIROBO_IP --token $MIROBO_TOKEN test_properties on off power status
Running command test_properties
WARNING:miio.device:Unable to obtain device model: Unable to request miIO.info from the device
Testing properties ('on', 'off', 'power', 'status') for <unavailable>
Testing on.. ERROR:miio.miioprotocol:Got error when receiving: timed out
WARNING:miio.device:Unable to request on: No response from the device
Testing off.. ERROR:miio.miioprotocol:Got error when receiving: timed out
WARNING:miio.device:Unable to request off: No response from the device
Testing power.. ERROR:miio.miioprotocol:Got error when receiving: timed out
WARNING:miio.device:Unable to request power: No response from the device
Testing status.. ERROR:miio.miioprotocol:Got error when receiving: timed out
WARNING:miio.device:Unable to request status: No response from the device
Found 0 valid properties, testing max_properties..

Please copy the results below to your report
### Results ###
Model: <unavailable>
Total responsives: 0
Total non-empty: 0
All non-empty properties:
{}
Max properties: -1
Done

and yet another from yeelight, which seems to respond with empty strings instead of Nones for invalid properties:

$ miiocli device --ip <addr> --token <token> test_properties power bright ct rgb hue sat color_mode name lan_ctrl save_state foo bar baz dup dap zap
Running command test_properties
Testing properties ('power', 'bright', 'ct', 'rgb', 'hue', 'sat', 'color_mode', 'name', 'lan_ctrl', 'save_state', 'foo', 'bar', 'baz', 'dup', 'dap', 'zap') for yeelink.light.color1
Testing power.. on <class 'str'>
Testing bright.. 99 <class 'str'>
Testing ct.. 4201 <class 'str'>
Testing rgb.. 16711680 <class 'str'>
Testing hue.. 359 <class 'str'>
Testing sat.. 100 <class 'str'>
Testing color_mode.. 2 <class 'str'>
Testing name..  <class 'str'>
Testing lan_ctrl.. 1 <class 'str'>
Testing save_state.. 0 <class 'str'>
Testing foo..  <class 'str'>
Testing bar..  <class 'str'>
Testing baz..  <class 'str'>
Testing dup..  <class 'str'>
Testing dap..  <class 'str'>
Testing zap..  <class 'str'>
Found 16 valid properties, testing max_properties..
Testing 16 properties at once.. OK for 16 properties

Please copy the results below to your report
### Results ###
Model: yeelink.light.color1
Total responsives: 16
Total non-empty: 16
All non-empty properties:
{'bar': '',
 'baz': '',
 'bright': '99',
 'color_mode': '2',
 'ct': '4201',
 'dap': '',
 'dup': '',
 'foo': '',
 'hue': '359',
 'lan_ctrl': '1',
 'name': '',
 'power': 'on',
 'rgb': '16711680',
 'sat': '100',
 'save_state': '0',
 'zap': ''}
Max properties: 16
Done

Copy link
Collaborator

@syssi syssi left a comment

Choose a reason for hiding this comment

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

A very helpful feature. Hopefully with miOT support some day.

@rytilahti
Copy link
Owner Author

Adding similar feature to MiotDevice to use an existing JSON description to print out all values could indeed be useful!

@syssi
Copy link
Collaborator

syssi commented Apr 11, 2021

Feel free to merge.

@rytilahti rytilahti merged commit d7507bb into master Apr 11, 2021
@rytilahti rytilahti deleted the feat/add_test_properties branch April 11, 2021 16:49
rytilahti added a commit that referenced this pull request May 5, 2021
[Full Changelog](0.5.5.2...0.5.6)

**Implemented enhancements:**

- RFC: Add a script to simplify finding supported properties for miio [\#919](#919)
- Improve test\_properties output [\#1024](#1024) ([rytilahti](https://github.com/rytilahti))
- Relax zeroconf version requirement [\#1023](#1023) ([rytilahti](https://github.com/rytilahti))
- Add test\_properties command to device class [\#1014](#1014) ([rytilahti](https://github.com/rytilahti))
- Add discover command to miiocli [\#1013](#1013) ([rytilahti](https://github.com/rytilahti))
- Fix supported oscillation angles of the dmaker.fan.p9 [\#1011](#1011) ([syssi](https://github.com/syssi))
- Add additional operation mode of the deerma.humidifier.jsq1 [\#1010](#1010) ([syssi](https://github.com/syssi))
- Roborock S7: Parse history details returned as dict [\#1006](#1006) ([fettlaus](https://github.com/fettlaus))

**Fixed bugs:**

- zeroconf 0.29.0 which is incompatible [\#1022](#1022)
- Remove superfluous decryption failure for handshake responses [\#1008](#1008)
- Skip pausing on Roborock S50 [\#1005](#1005)
- Roborock S7 after Firmware Update 4.1.2-0928 - KeyError [\#1004](#1004)
- No air quality value when aqi is 1 [\#958](#958)
- Fix exception on devices with removed lan\_ctrl [\#1028](#1028) ([Kirmas](https://github.com/Kirmas))
- Fix start bug and improve error handling in walkingpad integration [\#1017](#1017) ([dewgenenny](https://github.com/dewgenenny))
- gateway: fix zigbee lights [\#1016](#1016) ([starkillerOG](https://github.com/starkillerOG))
- Silence unable to decrypt warning for handshake responses [\#1015](#1015) ([rytilahti](https://github.com/rytilahti))
- Fix set\_mode\_and\_speed mode for airdog airpurifier [\#993](#993) ([alexeypetrenko](https://github.com/alexeypetrenko))

**Closed issues:**

- Add Dafang camera \(isa.camera.df3\) support [\#996](#996)
- Roborock S7 [\#989](#989)
- WalkingPad A1 Pro [\#797](#797)

**Merged pull requests:**

- Add basic dmaker.fan.1c support [\#1012](#1012) ([syssi](https://github.com/syssi))
- Always return aqi value \[Revert PR\#930\] [\#1007](#1007) ([bieniu](https://github.com/bieniu))
- Added S6 to skip pause on docking [\#1002](#1002) ([Sian-Lee-SA](https://github.com/Sian-Lee-SA))
- Added number of dust collections to CleaningSummary if available [\#992](#992) ([fettlaus](https://github.com/fettlaus))
- Reformat history data if returned as a dict/Roborock S7 Support \(\#989\) [\#990](#990) ([fettlaus](https://github.com/fettlaus))
- Add support for Walkingpad A1 \(ksmb.walkingpad.v3\) [\#975](#975) ([dewgenenny](https://github.com/dewgenenny))
@rytilahti rytilahti mentioned this pull request May 5, 2021
rytilahti added a commit that referenced this pull request May 5, 2021
[Full Changelog](0.5.5.2...0.5.6)

**Implemented enhancements:**

- RFC: Add a script to simplify finding supported properties for miio [\#919](#919)
- Improve test\_properties output [\#1024](#1024) ([rytilahti](https://github.com/rytilahti))
- Relax zeroconf version requirement [\#1023](#1023) ([rytilahti](https://github.com/rytilahti))
- Add test\_properties command to device class [\#1014](#1014) ([rytilahti](https://github.com/rytilahti))
- Add discover command to miiocli [\#1013](#1013) ([rytilahti](https://github.com/rytilahti))
- Fix supported oscillation angles of the dmaker.fan.p9 [\#1011](#1011) ([syssi](https://github.com/syssi))
- Add additional operation mode of the deerma.humidifier.jsq1 [\#1010](#1010) ([syssi](https://github.com/syssi))
- Roborock S7: Parse history details returned as dict [\#1006](#1006) ([fettlaus](https://github.com/fettlaus))

**Fixed bugs:**

- zeroconf 0.29.0 which is incompatible [\#1022](#1022)
- Remove superfluous decryption failure for handshake responses [\#1008](#1008)
- Skip pausing on Roborock S50 [\#1005](#1005)
- Roborock S7 after Firmware Update 4.1.2-0928 - KeyError [\#1004](#1004)
- No air quality value when aqi is 1 [\#958](#958)
- Fix exception on devices with removed lan\_ctrl [\#1028](#1028) ([Kirmas](https://github.com/Kirmas))
- Fix start bug and improve error handling in walkingpad integration [\#1017](#1017) ([dewgenenny](https://github.com/dewgenenny))
- gateway: fix zigbee lights [\#1016](#1016) ([starkillerOG](https://github.com/starkillerOG))
- Silence unable to decrypt warning for handshake responses [\#1015](#1015) ([rytilahti](https://github.com/rytilahti))
- Fix set\_mode\_and\_speed mode for airdog airpurifier [\#993](#993) ([alexeypetrenko](https://github.com/alexeypetrenko))

**Closed issues:**

- Add Dafang camera \(isa.camera.df3\) support [\#996](#996)
- Roborock S7 [\#989](#989)
- WalkingPad A1 Pro [\#797](#797)

**Merged pull requests:**

- Add basic dmaker.fan.1c support [\#1012](#1012) ([syssi](https://github.com/syssi))
- Always return aqi value \[Revert PR\#930\] [\#1007](#1007) ([bieniu](https://github.com/bieniu))
- Added S6 to skip pause on docking [\#1002](#1002) ([Sian-Lee-SA](https://github.com/Sian-Lee-SA))
- Added number of dust collections to CleaningSummary if available [\#992](#992) ([fettlaus](https://github.com/fettlaus))
- Reformat history data if returned as a dict/Roborock S7 Support \(\#989\) [\#990](#990) ([fettlaus](https://github.com/fettlaus))
- Add support for Walkingpad A1 \(ksmb.walkingpad.v3\) [\#975](#975) ([dewgenenny](https://github.com/dewgenenny))
xvlady pushed a commit to xvlady/python-miio that referenced this pull request May 9, 2021
* Add test_properties command to device class

This allows simple testing of available properties, their values & the number of properties that can be requested at once.
This is done in two steps:
1. Testing all given properties one by one to see which return non-None values
2. Testing all valid, non-None values at once and removing properties to request on failures to obtain the max_properties value

Example output:

```
$ miiocli device --ip <addr> --token <token> test_properties power on off usb_on temperature wifi_led foofoo x
Running command test_properties
Testing properties ('power', 'on', 'off', 'usb_on', 'temperature', 'wifi_led', 'foofoo', 'x') for zimi.powerstrip.v2
Testing power.. on <class 'str'>
Testing on.. None
Testing off.. None
Testing usb_on.. None
Testing temperature.. 46.07 <class 'float'>
Testing wifi_led.. off <class 'str'>
Testing foofoo.. None
Testing x.. None
Found 8 valid properties, testing max_properties..
Testing 8 properties at once.. OK for 8 properties

Please copy the results below to your report
Model: zimi.powerstrip.v2
Total responsives: 8
Total non-empty: 3
All non-empty properties:
{'power': 'on', 'temperature': 46.07, 'wifi_led': 'off'}
Max properties: 8
Done
```

* Consider empty strings as non-existing properties

* Move pformat import to top of the file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

RFC: Add a script to simplify finding supported properties for miio
2 participants