Skip to content

Enable multiple requests in smartprotocol - #584

Merged
rytilahti merged 3 commits into
python-kasa:masterfrom
sdb9696:multiple_smart_requests
Dec 20, 2023
Merged

Enable multiple requests in smartprotocol#584
rytilahti merged 3 commits into
python-kasa:masterfrom
sdb9696:multiple_smart_requests

Conversation

@sdb9696

@sdb9696 sdb9696 commented Dec 19, 2023

Copy link
Copy Markdown
Contributor

Hopefully a nice and small PR to enable multipleRequest in smartprotocol and the test framework.

A subsequent PRs will introduce the smart request helper functions and use the component_nego result to determine which requests to make rather than hardcoding.

@codecov

codecov Bot commented Dec 19, 2023

Copy link
Copy Markdown

Codecov Report

Attention: 4 lines in your changes are missing coverage. Please review.

Comparison is base (20ea670) 83.63% compared to head (b3bfeaa) 84.78%.

Files Patch % Lines
kasa/tapo/tapoplug.py 55.55% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #584      +/-   ##
==========================================
+ Coverage   83.63%   84.78%   +1.15%     
==========================================
  Files          37       37              
  Lines        3183     3220      +37     
  Branches      803      810       +7     
==========================================
+ Hits         2662     2730      +68     
+ Misses        436      413      -23     
+ Partials       85       77       -8     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@rytilahti rytilahti added the enhancement New feature or request label Dec 19, 2023

@rytilahti rytilahti left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nice work, seems to be (mostly) working! 🥇 I added a couple of comments to avoid unnecessary deep nesting, which should help to keep it easier to test and read.

The device main query succeeds querying multiple "modules", but looks like there is a regression on emeter access:

  File "/home/tpr/code/python-kasa/kasa/cli.py", line 474, in state
    echo(f"\t{emeter_status}")
         ^^^^^^^^^^^^^^^^^^^^
  File "/home/tpr/code/python-kasa/kasa/emeterstatus.py", line 52, in __repr__
    f"<EmeterStatus power={self.power} voltage={self.voltage}"
                           ^^^^^^^^^^
  File "/home/tpr/code/python-kasa/kasa/emeterstatus.py", line 30, in power
    return self["power"]
           ~~~~^^^^^^^^^
  File "/home/tpr/code/python-kasa/kasa/emeterstatus.py", line 83, in __getitem__
    return self.__getitem__(i) / 1000
           ~~~~~~~~~~~~~~~~~~~~^~~~~~
TypeError: unsupported operand type(s) for /: 'NoneType' and 'int'

The emeter status container contains only dict_items([('power_mw', None), ('total', None)]).

Comment thread kasa/tests/newfakes.py
Comment thread kasa/smartprotocol.py Outdated
Comment thread kasa/smartprotocol.py Outdated
Comment thread kasa/smartprotocol.py Outdated
Comment thread kasa/smartprotocol.py Outdated
Comment thread kasa/smartprotocol.py Outdated
@sdb9696

sdb9696 commented Dec 20, 2023

Copy link
Copy Markdown
Contributor Author

All comments addressed, emeter regression is fixed and the test framework tweaked to cover this regression case.

@sdb9696
sdb9696 requested a review from rytilahti December 20, 2023 09:35

@rytilahti rytilahti left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good to me, I'd extract the error code passing into its own PR though 👍

Comment thread kasa/tests/newfakes.py
Comment thread kasa/exceptions.py Outdated
Comment thread kasa/aestransport.py
@sdb9696

sdb9696 commented Dec 20, 2023

Copy link
Copy Markdown
Contributor Author

Hi @rytilahti, that's extracted now. I'll submit the new PR once this is merged and I can rebase on top.

@rytilahti rytilahti left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks nice and tidy now, thanks!

@rytilahti
rytilahti merged commit 6819c74 into python-kasa:master Dec 20, 2023
@sdb9696
sdb9696 deleted the multiple_smart_requests branch December 20, 2023 17:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants