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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add additional select for dmaker.airfresh.t2017 to xiaomi_miio #67058
Add additional select for dmaker.airfresh.t2017 to xiaomi_miio #67058
Conversation
- Display Orientation("forward", "left", "right") - Auxiliary Heat Level("low", "medium", "high") - XiaomiGenericSelector was added to avoid new class creation for every new select
This pull request needs to be manually signed off by @home-assistant/core before it can get merged. |
Hey there @rytilahti, @syssi, @starkillerOG, @bieniu, mind taking a look at this pull request as it has been labeled with an integration ( |
@rytilahti What do you think if I tried move all Selector to new Generic class. I think this must work by default (if I configure it right) and will do code as simple as possible. But I haven`t all type of device to check? Or will it be out off scope of this PR? |
I think it makes sense to clean it up & generalize as much as possible as you did, also fine inside the scope of this PR. I'll try to find some time later tonight to take a look in the code and provide some initial feedback. |
Great cleanups @Kirmas, you inspired me to explore a bit on how we could generalize this even more! So the approach I was thinking involves using the type hints in the device classes of python-miio:
There is still the need to map the status container value to the "candidate", and some ways to mark the useful methods inside python-miio, return only the enum values that are relevant for the given instance, and maybe provide a title/description, icon etc. that could be directly used in homeassistant? Similar trick could be done for the status container information to provide sensors (this will again require some more metadata to python-miio to make it useful) :-) This will allow creating the homeassistant entities without hard-coding the specifics inside homeassistant, making it really easy to extend on new devices as long as they are supported by homeassistant. Check out https://gist.github.com/rytilahti/0a0a84e57c35ddb1ccdc7c9a7879c7f6 for the script, here's an example output for AirFreshT2017:
Now, this is outside of the scope of this PR, but I just wanted to give you a heads up on it. What do you think? |
@rytilahti Looks like grate idea for the future. Also if we will get device list and spec from the library its give us a chance add device support only on our side. (python_miio has a lot of device that not integrated in the HA and this is pity). |
@Kirmas I just wanted to point out how we can solve this better in the future, and this PR with its cleanups is a nice improvement towards towards that future. And please, please do not overburden yourself & just take care and stay safe, that's more important than any of this! Also, feel free to contact me via discord or via email if you wish to discuss about anything. |
@rytilahti As we spoke in private messages. I have added tests for select. Could you review and approve? |
from miio.airfresh_t2017 import ( | ||
DisplayOrientation as AirfreshT2017DisplayOrientation, | ||
PtcLevel as AirfreshT2017PtcLevel, | ||
) | ||
from miio.airhumidifier import LedBrightness as AirhumidifierLedBrightness | ||
from miio.airhumidifier_miot import LedBrightness as AirhumidifierMiotLedBrightness | ||
from miio.tests.test_airfresh_t2017 import DummyAirFreshT2017 | ||
from miio.tests.test_airhumidifier import DummyAirHumidifier | ||
from miio.tests.test_airhumidifier_miot import DummyAirHumidifierMiot |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's avoid importing anything from python-miio here, and simply create some dummy enums that fulfill the same purpose.
My personal opinion is that the tests should verify that XiaomiGenericSelector
and relevant pieces work in select.py
, no matter which device is exposing those.
But I'll take another look at the test code soon, I just wanted to give you some quick comments asap.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rytilahti I dont really understand how to do this with out import Dummy device. (Maybe only ones?) Because I need coordinator to check _handle_coordinator_update function. And other milo interfaces.
Maybe if I remove airhumidifier_miot , test_airfresh_t2017 and use only airhumidifier class it will be enough?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rytilahti Tests was updated. Could you look at please.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
Proposed change
Another step after #66331 and #66370 I have added select like:
Other change is adding XiaomiGenericSelector this new class give me chance to not create new class for every select, I use it for
dmaker.airfresh.t2017
andzhimi.humidifier.ca1 - Led Brightness
because I have this devices and can check - this is working. But for other humidifiers maybe someone who have it can migrate it or help me with migration to new generic class.@rytilahti could you check this PR with more notice, maybe I do it wrong?
Type of change
Additional information
Checklist
black --fast homeassistant tests
)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest
.requirements_all.txt
.Updated by running
python3 -m script.gen_requirements_all
..coveragerc
.The integration reached or maintains the following Integration Quality Scale:
To help with the load of incoming pull requests: