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 model autodetection #1038

Merged
merged 9 commits into from
Aug 16, 2021
Merged

Add model autodetection #1038

merged 9 commits into from
Aug 16, 2021

Conversation

rytilahti
Copy link
Owner

@rytilahti rytilahti commented May 6, 2021

Different device models (even when supported by a single integration) can have different features or even different properties/API.
Previously, some integrations have used a model argument to define the exact device type to be able to adapt to these differences,
but there has been no generalized solution for this issue.

This PR will introduce automatic model detection based on the miIO.info query.
The first invocation of any command-decorated method will do the query to find the model of the device.
The response of this query is cached, so this will only happen once.

  • info() has now a new keyword-only argument 'skip_cache' which can be used to bypass the cache
  • Device constructor has a new keyword-only argument to specifying the model (which skips the info query)
  • This PR converts Vacuum class to use these new facilities for fan speed controls

In the future, there should be no need to use different classes for devices/models that are using only a slightly different feature sets / commands / properties.
This would simplify the usage at least for users of the following classes (based on discovery.py): Fan, FanMiot, ChuangmiPlug, PowerStrip, AirDog*, AirHumidifer, AirhumidifierJsq, AirConditioningCompanion, AirFresh, AirQualityMonitor, and Heater.

@syssi your feedback would be greatly appreciated, as you have more insight on the classes using model! :-)

TBD:

  • Update docs
  • Convert other platforms
  • Make it less hacky
  • Skip info() if there is only a single supported model (potential optimization)

Different device models (even when supported by a single integration) can have different features or even different properties/API.
Previously, some integrations have used a model argument to define the exact device type to be able to adapt to these differences,
but there has been no generalized solution for this issue.

This PR will introduce automatic model detection based on the miIO.info query.
The first invokation of any command-decorated method will do the query to find the model of the device.
The response of this query is cached, so this will only happen once.

* info() has now a new keyword-only argument 'skip_cache' which can be used to bypass the cache
* Device constructor has a new keyword-only argument to specifying the model (which skips the info query)
* This PR converts Vacuum class to use these new facilities for fanspeed controls
@rytilahti rytilahti force-pushed the feat/model_autodetect branch from fe65426 to 5c941ad Compare June 16, 2021 16:01
@rytilahti rytilahti changed the title RFC: Add model autodetection Add model autodetection Jun 16, 2021
@rytilahti rytilahti requested a review from syssi June 16, 2021 17:09
@codecov-commenter
Copy link

codecov-commenter commented Jun 16, 2021

Codecov Report

Merging #1038 (3f389dd) into master (a3a9df5) will increase coverage by 0.78%.
The diff coverage is 61.11%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1038      +/-   ##
==========================================
+ Coverage   75.40%   76.19%   +0.78%     
==========================================
  Files          73       74       +1     
  Lines        8367     8337      -30     
  Branches      745      722      -23     
==========================================
+ Hits         6309     6352      +43     
+ Misses       1874     1805      -69     
+ Partials      184      180       -4     
Impacted Files Coverage Δ
miio/airconditioningcompanion.py 96.46% <0.00%> (+0.96%) ⬆️
miio/airdehumidifier.py 84.09% <0.00%> (+1.86%) ⬆️
miio/airfresh.py 90.25% <0.00%> (+1.72%) ⬆️
miio/airfresh_t2017.py 95.06% <0.00%> (+3.39%) ⬆️
miio/airhumidifier.py 87.30% <0.00%> (+1.36%) ⬆️
miio/airhumidifier_jsq.py 92.45% <0.00%> (-0.89%) ⬇️
miio/airhumidifier_mjjsq.py 92.30% <0.00%> (+2.94%) ⬆️
miio/airpurifier_airdog.py 91.20% <0.00%> (+8.20%) ⬆️
miio/airqualitymonitor.py 81.66% <0.00%> (+4.50%) ⬆️
miio/chuangmi_plug.py 87.75% <0.00%> (ø)
... and 20 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 a3a9df5...3f389dd. Read the comment docs.

@rytilahti rytilahti mentioned this pull request Aug 13, 2021
22 tasks
@rytilahti rytilahti merged commit 0b846e4 into next Aug 16, 2021
@rytilahti rytilahti deleted the feat/model_autodetect branch August 16, 2021 21:46
rytilahti added a commit that referenced this pull request Sep 17, 2021
* Add model autodetection

Different device models (even when supported by a single integration) can have different features or even different properties/API.
Previously, some integrations have used a model argument to define the exact device type to be able to adapt to these differences,
but there has been no generalized solution for this issue.

This PR will introduce automatic model detection based on the miIO.info query.
The first invokation of any command-decorated method will do the query to find the model of the device.
The response of this query is cached, so this will only happen once.

* info() has now a new keyword-only argument 'skip_cache' which can be used to bypass the cache
* Device constructor has a new keyword-only argument to specifying the model (which skips the info query)
* This PR converts Vacuum class to use these new facilities for fanspeed controls

* tests: self.model -> self._model

* WIP add some missing models, fix infinite loop, experiment with supported_models

* convert all devices to use the parent ctor's model kwarg, fix mypy errors

* Fix tests

* Add test for unsupported model logging

* revert mistakenly changed test call for test_forced_model

* powerstrip: add known models to supported models
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.

2 participants