8000 Add module support & query their information during update cycle by rytilahti · Pull Request #243 · python-kasa/python-kasa · GitHub
[go: up one dir, main page]

Skip to content

Add module support & query their information during update cycle #243

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 9 commits into from
Nov 7, 2021

Conversation

rytilahti
Copy link
Member
@rytilahti rytilahti commented Oct 27, 2021

This PR creates a modularized foundation to expose more features on the supported devices, with the goal of making it more straightforward to implement new features in the future. This PR should not break the API.

At the moment, the most visible change is that each update cycle queries the information from all modules in a single query:

  • Basic system info
  • Cloud (new)
  • Countdown (new)
  • Antitheft (new)
  • Schedule (new)
  • Usage (new)
  • Time (existing, implements the time/timezone handling)
  • Emeter (existing, partially separated from smartdevice)

As some devices are known to be picky on multimodule queries, I'm marking this a draft in hopes of getting feedback if this works on the majority of devices as it is or not.

Further updates and improvements are to be done on modularize branch which is the target branch of this PR.

This creates a base to expose more features on the supported devices.
At the moment, the most visible change is that each update cycle gets information from all available modules:
* Basic system info
* Cloud (new)
* Countdown (new)
* Antitheft (new)
* Schedule (new)
* Time (existing, implements the time/timezone handling)
* Emeter (existing, partially separated from smartdevice)
@codecov-commenter
Copy link
codecov-commenter commented Oct 27, 2021

Codecov Report

Merging #243 (a37a244) into master (8a4068c) will increase coverage by 0.19%.
The diff coverage is 84.37%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #243      +/-   ##
==========================================
+ Coverage   81.63%   81.83%   +0.19%     
==========================================
  Files          12       22      +10     
  Lines        1307     1525     +218     
  Branches      176      187      +11     
==========================================
+ Hits         1067     1248     +181     
- Misses        209      243      +34     
- Partials       31       34       +3     
Impacted Files Coverage Δ
kasa/modules/usage.py 60.86% <60.86%> (ø)
kasa/cli.py 56.86% <62.50%> (+0.01%) ⬆️
kasa/smartstrip.py 89.86% <71.42%> (-3.15%) ⬇️
kasa/modules/cloud.py 81.48% <81.48%> (ø)
kasa/modules/rulemodule.py 82.60% <82.60%> (ø)
kasa/modules/module.py 87.50% <87.50%> (ø)
kasa/modules/emeter.py 90.00% <90.00%> (ø)
kasa/smartdevice.py 86.62% <96.42%> (+0.95%) ⬆️
kasa/modules/__init__.py 100.00% <100.00%> (ø)
kasa/modules/antitheft.py 100.00% <100.00%> (ø)
... and 9 more

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 8a4068c...a37a244. Read the comment docs.

@rytilahti rytilahti changed the base branch from master to modularize November 2, 2021 16:35
@rytilahti
Copy link
Member Author

I want to get this merged before continuing on improving the modules so I created a new development branch on which this PR is to be merged. The further improvement PRs can then be done separately on top of the modularize branch, which can be merged back when it's ready.

@rytilahti rytilahti marked this pull request as ready for review November 2, 2021 16:40
@rytilahti rytilahti merged commit 31631ce into python-kasa:modularize Nov 7, 2021
@rytilahti rytilahti deleted the feat/modularize branch November 7, 2021 01:41
@rytilahti rytilahti added the enhancement New feature or request label Jan 14, 2022
rytilahti added a commit that referenced this pull request Jan 29, 2022
* Add module support & modularize existing query

This creates a base to expose more features on the supported devices.
At the moment, the most visible change is that each update cycle gets information from all available modules:
* Basic system info
* Cloud (new)
* Countdown (new)
* Antitheft (new)
* Schedule (new)
* Time (existing, implements the time/timezone handling)
* Emeter (existing, partially separated from smartdevice)

* Fix imports

* Fix linting

* Use device host instead of alias in module repr

* Add property to list available modules, print them in cli state report

* usage: fix the get_realtime query

* separate usage from schedule to avoid multi-inheritance

* Fix module querying

* Add is_supported property to modules
rytilahti added a commit to rytilahti/python-kasa that referenced this pull request Jan 29, 2022
…hon-kasa#243)

* Add module support & modularize existing query

This creates a base to expose more features on the supported devices.
At the moment, the most visible change is that each update cycle gets information from all available modules:
* Basic system info
* Cloud (new)
* Countdown (new)
* Antitheft (new)
* Schedule (new)
* Time (existing, implements the time/timezone handling)
* Emeter (existing, partially separated from smartdevice)

* Fix imports

* Fix linting

* Use device host instead of alias in module repr

* Add property to list available modules, print them in cli state report

* usage: fix the get_realtime query

* separate usage from schedule to avoid multi-inheritance

* Fix module querying

* Add is_supported property to modules
rytilahti added a commit that referenced this pull request Mar 24, 2022
* Add module support & modularize existing query

This creates a base to expose more features on the supported devices.
At the moment, the most visible change is that each update cycle gets information from all available modules:
* Basic system info
* Cloud (new)
* Countdown (new)
* Antitheft (new)
* Schedule (new)
* Time (existing, implements the time/timezone handling)
* Emeter (existing, partially separated from smartdevice)

* Fix imports

* Fix linting

* Use device host instead of alias in module repr

* Add property to list available modules, print them in cli state report

* usage: fix the get_realtime query

* separate usage from schedule to avoid multi-inheritance

* Fix module querying

* Add is_supported property to modules
rytilahti added a commit that referenced this pull request Apr 5, 2022
* Add module support & modularize existing query

This creates a base to expose more features on the supported devices.
At the moment, the most visible change is that each update cycle gets information from all available modules:
* Basic system info
* Cloud (new)
* Countdown (new)
* Antitheft (new)
* Schedule (new)
* Time (existing, implements the time/timezone handling)
* Emeter (existing, partially separated from smartdevice)

* Fix imports

* Fix linting

* Use device host instead of alias in module repr

* Add property to list available modules, print them in cli state report

* usage: fix the get_realtime query

* separate usage from schedule to avoid multi-inheritance

* Fix module querying

* Add is_supported property to modules
rytilahti added a commit that referenced this pull request Apr 5, 2022
* Add module support & modularize existing query

This creates a base to expose more features on the supported devices.
At the moment, the most visible change is that each update cycle gets information from all available modules:
* Basic system info
* Cloud (new)
* Countdown (new)
* Antitheft (new)
* Schedule (new)
* Time (existing, implements the time/timezone handling)
* Emeter (existing, partially separated from smartdevice)

* Fix imports

* Fix linting

* Use device host instead of alias in module repr

* Add property to list available modules, print them in cli state report

* usage: fix the get_realtime query

* separate usage from schedule to avoid multi-inheritance

* Fix module querying

* Add is_supported property to modules
rytilahti added a commit that referenced this pull request Apr 5, 2022
* Add module support & modularize existing query

This creates a base to expose more features on the supported devices.
At the moment, the most visible change is that each update cycle gets information from all available modules:
* Basic system info
* Cloud (new)
* Countdown (new)
* Antitheft (new)
* Schedule (new)
* Time (existing, implements the time/timezone handling)
* Emeter (existing, partially separated from smartdevice)

* Fix imports

* Fix linting

* Use device host instead of alias in module repr

* Add property to list available modules, print them in cli state report

* usage: fix the get_realtime query

* separate usage from schedule to avoid multi-inheritance

* Fix module querying

* Add is_supported property to modules
rytilahti pushed a commit that referenced this pull request Apr 25, 2024
This fixes the current broken tests in
#844 caused by the
fixtures for `HS107(US)_1.0_1.0.8.json` and `KP400(US)_1.0_1.0.10.json`
having the `emeter` value in the fixture but no `get_realtime` value.
Other strips do not fail because they do not have the `emeter` value in
the fixture and the `FakeIotProtocol` creates one for them.

It seems that #299
introduced the adding of Emeter in the smart strip constructor (in
commit
c8ad99a)
and this was added after
#243 which adds the
Emeter in the IoDevice `update()` method so perhaps there is an
implication to this change that I'm missing, although it seems
`_create_emeter_request` is no longer called anywhere so maybe that was
a historical reason.

N.B. The tests all pass with this PR.

Link to [CI run on
branch](https://github.com/sdb9696/python-kasa/actions/runs/8831324308)
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
0