8000 Perform initial update only using the sysinfo query by rytilahti · Pull Request #199 · python-kasa/python-kasa · GitHub
[go: up one dir, main page]

Skip to content

Perform initial update only using the sysinfo query #199

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

Merged
merged 1 commit into from
Sep 19, 2021

Conversation

rytilahti
Copy link
Member

Some devices are known to fail when trying to query non-supported modules like emeter information.
This commit makes the initial update() only request the sysinfo, followed up by a second query
if emeter is supported by the device.

Fixes #161 inspired by #120 which is obsolete by this, thanks to @mfalzone

@brianthedavis @mfalzone @SimonWilkinson - mind giving this a quick test to see if it solves the problem?

Some devices are known to fail when trying to query non-supported modules like emeter information.
This commit makes the initial update() only request the sysinfo, followed up by a second query
if emeter is supported by the device.
@codecov-commenter
Copy link
codecov-commenter commented Sep 19, 2021

Codecov Report

Merging #199 (76a3cfd) into master (f8e7258) will increase coverage by 0.47%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #199      +/-   ##
==========================================
+ Coverage   74.26%   74.73%   +0.47%     
==========================================
  Files          11       11              
  Lines        1224     1231       +7     
  Branches      178      180       +2     
==========================================
+ Hits          909      920      +11     
+ Misses        282      273       -9     
- Partials       33       38       +5     
Impacted Files Coverage Δ
kasa/smartdevice.py 82.75% <100.00%> (+0.35%) ⬆️
kasa/smartstrip.py 81.20% <0.00%> (+3.00%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f8e7258...76a3cfd. Read the comment docs.

@brianthedavis
Copy link
Contributor

This change seems to have fixed the issue! Nicely done!

Here was the output I got from the command on the current master branch:

kasa --debug --plug --host kasa-sw01
DEBUG:kasa.smartdevice:Initializing kasa-sw01 of type <class 'kasa.smartplug.SmartPlug'>
DEBUG:kasa.protocol:> (143) {"system": {"get_sysinfo": null}, "emeter": {"get_realtime": null, "get_monthstat": {"year": 2021}, "get_daystat": {"month": 9, "year": 2021}}}

...and it stalls there, never returning.

Running that same command on this PR yields:

kasa --debug --plug --host kasa-sw01
DEBUG:kasa.smartdevice:Initializing kasa-sw01 of type <class 'kasa.smartplug.SmartPlug'>
DEBUG:kasa.smartdevice:Performing the initial update to obtain sysinfo
DEBUG:kasa.protocol:> (33) {"system": {"get_sysinfo": null}}
DEBUG:kasa.protocol:< (573) {'system': {'get_sysinfo': {'active_mode': 'none',
                            'alias': 'House Fan',
                            'dev_name': 'Smart Wi-Fi Light Switch',
                            'deviceId': '8006537A25B360E196DFC5B433BBF7E41DFBA004',
                            'err_code': 0,
                            'feature': 'TIM',
                            'hwId': '6F710464613C9F1EA67305BD422BC2D0',
                            'hw_ver': '5.0',
                            'icon_hash': '',
                            'latitude_i': 397310,
                            'led_off': 0,
                            'longitude_i': -1049060,
                            'mac': '90:9A:4A:55:BC:71',
                            'mic_type': 'IOT.SMARTPLUGSWITCH',
                            'model': 'HS200(US)',
                            'next_action': {'type': -1},
                            'oemId': '8754F01961F1BCDAEC5B68B74FFFA7E0',
                            'on_time': 0,
                            'relay_state': 0,
                            'rssi': -47,
                            'status': 'new',
                            'sw_ver': '1.0.2 Build 200819 Rel.105309',
                            'updating': 0}}}
== House Fan - HS200(US) ==
        Host: kasa-sw01
        Device state: OFF

        == Generic information ==
DEBUG:kasa.protocol:> (28) {"time": {"get_time": null}}
DEBUG:kasa.protocol:< (96) {'time': {'get_time': {'err_code': 0,
                       'hour': 15,
                       'mday': 19,
                       'min': 16,
                       'month': 9,
                       'sec': 36,
                       'year': 2021}}}
        Time:         2021-09-19 15:16:36
        Hardware:     5.0
        Software:     1.0.2 Build 200819 Rel.105309
        MAC (rssi):   90:9A:4A:55:BC:71 (-47)
        Location:     {'latitude': 397310, 'longitude': -1049060}

        == Device specific information ==
        LED state: True
        On since: None

without hanging.

I also ran this version against an HS103 HW v3.0, KL125 HW v1.20, and KP400 HW v2.0 and they all worked just fine as well. Any other test you'd like ran?

@rytilahti
Copy link
Member Author

Glad to hear that and thanks for testing, it's always tricky to develop when you do not have device access! I don't think there's more testing necessary for now, so I'll just merge this for the next pre-release. I have also tested this with my HS110, KL130 and KP303.

@rytilahti rytilahti merged commit b088596 into python-kasa:master Sep 19, 2021
@rytilahti rytilahti deleted the fix/multiquery branch September 19, 2021 21:43
rytilahti added a commit to rytilahti/python-kasa that referenced this pull request Sep 23, 2021
The most important enhancements in this release are:
* Support for emeter on strip sockets
* Fix discovery and update() on some devices that do not support multi-module queries (e.g., HS200)
* Improved support for bulbs

[Full Changelog](python-kasa/python-kasa@0.4.0.dev3...0.4.0.dev4)

**Implemented enhancements:**

- HS300 Children plugs have emeter [\python-kasa#64](python-kasa#64)
- Improve emeterstatus API, move into own module [\python-kasa#205](python-kasa#205) ([rytilahti](https://github.com/rytilahti))
- Avoid temp array during encrypt and decrypt [\python-kasa#204](python-kasa#204) ([bdraco](https://github.com/bdraco))
- Add emeter support for strip sockets [\python-kasa#203](python-kasa#203) ([bdraco](https://github.com/bdraco))
- Add own device type for smartstrip children [\python-kasa#201](python-kasa#201) ([rytilahti](https://github.com/rytilahti))
- bulb: allow set\_hsv without v, add fallback ct range [\python-kasa#200](python-kasa#200) ([rytilahti](https://github.com/rytilahti))
- Improve bulb support \(alias, time settings\) [\python-kasa#198](python-kasa#198) ([rytilahti](https://github.com/rytilahti))
- Improve testing harness to allow tests on real devices [\python-kasa#197](python-kasa#197) ([rytilahti](https://github.com/rytilahti))
- cli: add human-friendly printout when calling temperature on non-supported devices [\python-kasa#196](python-kasa#196) ([JaydenRA](https://github.com/JaydenRA))

**Fixed bugs:**

- KL430: Throw error for Device specific information [\python-kasa#189](python-kasa#189)
- dump\_devinfo: handle latitude/longitude keys properly [\python-kasa#175](python-kasa#175) ([rytilahti](https://github.com/rytilahti))

**Closed issues:**

- Feature Request - Toggle Command [\python-kasa#188](python-kasa#188)
- Is It Compatible With HS105? [\python-kasa#186](python-kasa#186)
- Cannot use some functions with KP303 [\python-kasa#181](python-kasa#181)
- Help needed - awaiting game  [\python-kasa#179](python-kasa#179)
- Version inconsistency between CLI and pip [\python-kasa#177](python-kasa#177)
- Release 0.4.0.dev3? [\python-kasa#169](python-kasa#169)
- Discover does not support specifying network interface [\python-kasa#167](python-kasa#167)
- Can't command or query HS200 v5 switch [\python-kasa#161](python-kasa#161)

**Merged pull requests:**

- More CI fixes [\python-kasa#208](python-kasa#208) ([rytilahti](https://github.com/rytilahti))
- Fix CI dep installation [\python-kasa#207](python-kasa#207) ([rytilahti](https://github.com/rytilahti))
- Use github actions instead of azure pipelines [\python-kasa#206](python-kasa#206) ([rytilahti](https://github.com/rytilahti))
- Add KP115 fixture [\python-kasa#202](python-kasa#202) ([rytilahti](https://github.com/rytilahti))
- Perform initial update only using the sysinfo query [\python-kasa#199](python-kasa#199) ([rytilahti](https://github.com/rytilahti))
- Add real kasa KL430\(UN\) device dump [\python-kasa#192](python-kasa#192) ([iprodanovbg](https://github.com/iprodanovbg))
- Use less strict matcher for kl430 color temperature [\python-kasa#190](python-kasa#190) ([rytilahti](https://github.com/rytilahti))
- Add EP10\(US\) 1.0 1.0.2 fixture [\python-kasa#174](python-kasa#174) ([nbrew](https://github.com/nbrew))
- Add a note about using the discovery target parameter [\python-kasa#168](python-kasa#168) ([leandroreox](https://github.com/leandroreox))
@rytilahti rytilahti mentioned this pull request Sep 23, 2021
rytilahti added a commit to rytilahti/python-kasa that referenced this pull request Sep 23, 2021
The most important enhancements in this release are:
* Support for emeter on strip sockets
* Fix discovery and update() on some devices that do not support multi-module queries (e.g., HS200)
* Improved support for bulbs

[Full Changelog](python-kasa/python-kasa@0.4.0.dev3...0.4.0.dev4)

**Implemented enhancements:**

- HS300 Children plugs have emeter [\python-kasa#64](python-kasa#64)
- Improve emeterstatus API, move into own module [\python-kasa#205](python-kasa#205) ([rytilahti](https://github.com/rytilahti))
- Avoid temp array during encrypt and decrypt [\python-kasa#204](python-kasa#204) ([bdraco](https://github.com/bdraco))
- Add emeter support for strip sockets [\python-kasa#203](python-kasa#203) ([bdraco](https://github.com/bdraco))
- Add own device type for smartstrip children [\python-kasa#201](python-kasa#201) ([rytilahti](https://github.com/rytilahti))
- bulb: allow set\_hsv without v, add fallback ct range [\python-kasa#200](python-kasa#200) ([rytilahti](https://github.com/rytilahti))
- Improve bulb support \(alias, time settings\) [\python-kasa#198](python-kasa#198) ([rytilahti](https://github.com/rytilahti))
- Improve testing harness to allow tests on real devices [\python-kasa#197](python-kasa#197) ([rytilahti](https://github.com/rytilahti))
- cli: add human-friendly printout when calling temperature on non-supported devices [\python-kasa#196](python-kasa#196) ([JaydenRA](https://github.com/JaydenRA))

**Fixed bugs:**

- KL430: Throw error for Device specific information [\python-kasa#189](python-kasa#189)
- dump\_devinfo: handle latitude/longitude keys properly [\python-kasa#175](python-kasa#175) ([rytilahti](https://github.com/rytilahti))

**Closed issues:**

- Feature Request - Toggle Command [\python-kasa#188](python-kasa#188)
- Is It Compatible With HS105? [\python-kasa#186](python-kasa#186)
- Cannot use some functions with KP303 [\python-kasa#181](python-kasa#181)
- Help needed - awaiting game  [\python-kasa#179](python-kasa#179)
- Version inconsistency between CLI and pip [\python-kasa#177](python-kasa#177)
- Release 0.4.0.dev3? [\python-kasa#169](python-kasa#169)
- Discover does not support specifying network interface [\python-kasa#167](python-kasa#167)
- Can't command or query HS200 v5 switch [\python-kasa#161](python-kasa#161)

**Merged pull requests:**

- More CI fixes [\python-kasa#208](python-kasa#208) ([rytilahti](https://github.com/rytilahti))
- Fix CI dep installation [\python-kasa#207](python-kasa#207) ([rytilahti](https://github.com/rytilahti))
- Use github actions instead of azure pipelines [\python-kasa#206](python-kasa#206) ([rytilahti](https://github.com/rytilahti))
- Add KP115 fixture [\python-kasa#202](python-kasa#202) ([rytilahti](https://github.com/rytilahti))
- Perform initial update only using the sysinfo query [\python-kasa#199](python-kasa#199) ([rytilahti](https://github.com/rytilahti))
- Add real kasa KL430\(UN\) device dump [\python-kasa#192](python-kasa#192) ([iprodanovbg](https://github.com/iprodanovbg))
- Use less strict matcher for kl430 color temperature [\python-kasa#190](python-kasa#190) ([rytilahti](https://github.com/rytilahti))
- Add EP10\(US\) 1.0 1.0.2 fixture [\python-kasa#174](python-kasa#174) ([nbrew](https://github.com/nbrew))
- Add a note about using the discovery target parameter [\python-kasa#168](python-kasa#168) ([leandroreox](https://github.com/leandroreox))
rytilahti added a commit that referenced this pull request Sep 23, 2021
* Release 0.4.0.dev4

The most important enhancements in this release are:
* Support for emeter on strip sockets
* Fix discovery and update() on some devices that do not support multi-module queries (e.g., HS200)
* Improved support for bulbs

[Full Changelog](0.4.0.dev3...0.4.0.dev4)

**Implemented enhancements:**

- HS300 Children plugs have emeter [\#64](#64)
- Improve emeterstatus API, move into own module [\#205](#205) ([rytilahti](https://github.com/rytilahti))
- Avoid temp array during encrypt and decrypt [\#204](#204) ([bdraco](https://github.com/bdraco))
- Add emeter support for strip sockets [\#203](#203) ([bdraco](https://github.com/bdraco))
- Add own device type for smartstrip children [\#201](#201) ([rytilahti](https://github.com/rytilahti))
- bulb: allow set\_hsv without v, add fallback ct range [\#200](#200) ([rytilahti](https://github.com/rytilahti))
- Improve bulb support \(alias, time settings\) [\#198](#198) ([rytilahti](https://github.com/rytilahti))
- Improve testing harness to allow tests on real devices [\#197](#197) ([rytilahti](https://github.com/rytilahti))
- cli: add human-friendly printout when calling temperature on non-supported devices [\#196](#196) ([JaydenRA](https://github.com/JaydenRA))

**Fixed bugs:**

- KL430: Throw error for Device specific information [\#189](#189)
- dump\_devinfo: handle latitude/longitude keys properly [\#175](#175) ([rytilahti](https://github.com/rytilahti))

**Closed issues:**

- Feature Request - Toggle Command [\#188](#188)
- Is It Compatible With HS105? [\#186](#186)
- Cannot use some functions with KP303 [\#181](#181)
- Help needed - awaiting game  [\#179](#179)
- Version inconsistency between CLI and pip [\#177](#177)
- Release 0.4.0.dev3? [\#169](#169)
- Discover does not support specifying network interface [\#167](#167)
- Can't command or query HS200 v5 switch [\#161](#161)

**Merged pull requests:**

- More CI fixes [\#208](#208) ([rytilahti](https://github.com/rytilahti))
- Fix CI dep installation [\#207](#207) ([rytilahti](https://github.com/rytilahti))
- Use github actions instead of azure pipelines [\#206](#206) ([rytilahti](https://github.com/rytilahti))
- Add KP115 fixture [\#202](#202) ([rytilahti](https://github.com/rytilahti))
- Perform initial update only using the sysinfo query [\#199](#199) ([rytilahti](https://github.com/rytilahti))
- Add real kasa KL430\(UN\) device dump [\#192](#192) ([iprodanovbg](https://github.com/iprodanovbg))
- Use less strict matcher for kl430 color temperature [\#190](#190) ([rytilahti](https://github.com/rytilahti))
- Add EP10\(US\) 1.0 1.0.2 fixture [\#174](#174) ([nbrew](https://github.com/nbrew))
- Add a note about using the discovery target parameter [\#168](#168) ([leandroreox](https://github.com/leandroreox))

* replace pypy3 with pypy-3.7 as we do not support python3.6 anyway

* skip pypy-3.7 on windows to avoid flaky ci
rytilahti added a commit to rytilahti/python-kasa that referenced this pull request Oct 11, 2021
* Release 0.4.0.dev4

The most important enhancements in this release are:
* Support for emeter on strip sockets
* Fix discovery and update() on some devices that do not support multi-module queries (e.g., HS200)
* Improved support for bulbs

[Full Changelog](python-kasa/python-kasa@0.4.0.dev3...0.4.0.dev4)

**Implemented enhancements:**

- HS300 Children plugs have emeter [\python-kasa#64](python-kasa#64)
- Improve emeterstatus API, move into own module [\python-kasa#205](python-kasa#205) ([rytilahti](https://github.com/rytilahti))
- Avoid temp array during encrypt and decrypt [\python-kasa#204](python-kasa#204) ([bdraco](https://github.com/bdraco))
- Add emeter support for strip sockets [\python-kasa#203](python-kasa#203) ([bdraco](https://github.com/bdraco))
- Add own device type for smartstrip children [\python-kasa#201](python-kasa#201) ([rytilahti](https://github.com/rytilahti))
- bulb: allow set\_hsv without v, add fallback ct range [\python-kasa#200](python-kasa#200) ([rytilahti](https://github.com/rytilahti))
- Improve bulb support \(alias, time settings\) [\python-kasa#198](python-kasa#198) ([rytilahti](https://github.com/rytilahti))
- Improve testing harness to allow tests on real devices [\python-kasa#197](python-kasa#197) ([rytilahti](https://github.com/rytilahti))
- cli: add human-friendly printout when calling temperature on non-supported devices [\python-kasa#196](python-kasa#196) ([JaydenRA](https://github.com/JaydenRA))

**Fixed bugs:**

- KL430: Throw error for Device specific information [\python-kasa#189](python-kasa#189)
- dump\_devinfo: handle latitude/longitude keys properly [\python-kasa#175](python-kasa#175) ([rytilahti](https://github.com/rytilahti))

**Closed issues:**

- Feature Request - Toggle Command [\python-kasa#188](python-kasa#188)
- Is It Compatible With HS105? [\python-kasa#186](python-kasa#186)
- Cannot use some functions with KP303 [\python-kasa#181](python-kasa#181)
- Help needed - awaiting game  [\python-kasa#179](python-kasa#179)
- Version inconsistency between CLI and pip [\python-kasa#177](python-kasa#177)
- Release 0.4.0.dev3? [\python-kasa#169](python-kasa#169)
- Discover does not support specifying network interface [\python-kasa#167](python-kasa#167)
- Can't command or query HS200 v5 switch [\python-kasa#161](python-kasa#161)

**Merged pull requests:**

- More CI fixes [\python-kasa#208](python-kasa#208) ([rytilahti](https://github.com/rytilahti))
- Fix CI dep installation [\python-kasa#207](python-kasa#207) ([rytilahti](https://github.com/rytilahti))
- Use github actions instead of azure pipelines [\python-kasa#206](python-kasa#206) ([rytilahti](https://github.com/rytilahti))
- Add KP115 fixture [\python-kasa#202](python-kasa#202) ([rytilahti](https://github.com/rytilahti))
- Perform initial update only using the sysinfo query [\python-kasa#199](python-kasa#199) ([rytilahti](https://github.com/rytilahti))
- Add real kasa KL430\(UN\) device dump [\python-kasa#192](python-kasa#192) ([iprodanovbg](https://github.com/iprodanovbg))
- Use less strict matcher for kl430 color temperature [\python-kasa#190](python-kasa#190) ([rytilahti](https://github.com/rytilahti))
- Add EP10\(US\) 1.0 1.0.2 fixture [\python-kasa#174](python-kasa#174) ([nbrew](https://github.com/nbrew))
- Add a note about using the discovery target parameter [\python-kasa#168](python-kasa#168) ([leandroreox](https://github.com/leandroreox))

* replace pypy3 with pypy-3.7 as we do not support python3.6 anyway

* skip pypy-3.7 on windows to avoid flaky ci
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.

Can't command or query HS200 v5 switch
3 participants
0