-
-
Notifications
You must be signed in to change notification settings - Fork 563
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 support for chuangmi.remote.h102a03 and chuangmi.remote.v2 #1021
base: master
Are you sure you want to change the base?
Conversation
5a3ddbf
to
f902599
Compare
Not much idea how about fixing Tests PyPy Ubuntu. |
Just a quick comment as I don't currently have time to do a proper review:
|
Related:
OK, will do.
A squashed rebase is much simpler for me to do. I'll add credits on commit message. |
@rytilahti besides marking |
487fac1
to
6b13a4a
Compare
Changing the dependency to optional, I ignore how to fix it missing on CI, as reported by failing tests. |
I don't think there's a need to create a new extras entry, as the exception will inform anyone trying to use it to install the package. The docs entry is there just to simplify installing the required packages for development. re: pypy problems, from the looks of it there is no easy solution for that? If so, I think reporting the issue to the heatshrink2 developers, and disabling pypy checks (and marking the reason & including a link to the upstream issue) for this one test file is fine. |
@rytilahti I will report it on heatshrink2 repo, but could you take the torch about applying remaining details on merging this? Because I'm no knowledgeable Python dev and it's just my first contact with "poetry" and such. I'd have to look up how to "disable pypy checks for this one test file", which I simply ignore, and I don't have much time available for learning these tidbits. |
I'll try to find some time over the weekend to do a review, for the pypy checks in the test file, something like this near the beginning after the pytest import should mark the whole module to be skipped when run with pypy:
|
Ah, looks like the heatshrink2 needs to be added to the extras group to easier install for the CI. Do you mind adding it to the |
e01fd6c
to
d731610
Compare
Looks like simply renaming docs to dev on those two places and updating lock file didn't work. Any ideas? |
d731610
to
e4ff47a
Compare
That's really odd, I have no clue why it isn't installing the library using pip... I'll try to debug that locally to find the reason for it when I do the code review. |
18f6648
to
f7c3abb
Compare
Almost there, only this addition needs to be toggled off for PyPy on CI. I dunno the syntax for that. The trivial approach would be to have PyPy Tests in its own job separated from the main Tests matrix. |
This comment has been minimized.
This comment has been minimized.
Okay, the mark is not being set for some reason.. The comparison should be fine as I just tested it in pypy repl:
|
b4d13a1
to
ed631e2
Compare
The proper way is to find out why the pytestmark is not working, as that allows local testing, too. I can look into that later to figure out why it isn't working, the worst case is that every separate test function has to be decorated with the
|
@rytilahti both changes are needed, the pytestmark to skip the test on PyPy because heatshrink2 can't not be present anyways, and the Azure Pipelines condition to just not try installing heatshrink2 on PyPy, and installing it for the rest. |
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.
Considering the biggest change between these remotes is just the way they expect the payload to be encoded, I think it would be better to avoid creating separate classes, but also a parameter (model
) like done on many other devices and choose the encoding function based on that.
What do you think?
"""Class representing new type of Chuangmi IR Remote Controller identified by model | ||
"chuangmi-remote-h102a03_". |
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.
"""Class representing new type of Chuangmi IR Remote Controller identified by model | |
"chuangmi-remote-h102a03_". | |
"""Class representing Chuangmi IR Remote Controller (chuangmi-remote-h102a03_). |
Is info()
working fine for this device? If yes, could you also add that here. The long term goal is to separate the meta information to separate files to allow creating instances based on the model information.
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.
I can only confirm that it works for chuangmi-remote-v2, and it does. What should be added? I didn't get. Do you wish to add that info()
works for the device in the class description?
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.
The info will deliver the model of the device, could you check with miiocli device info
what is it for your device & add that to the corresponding class?
The reason why I'm pushing towards a single class is that it makes it simpler for downstreams like homeassistant to support all supported remotes as long as 1) info is working or 2) the user provides the wanted model as a parameter so that the class can adjust itself accordingly.
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.
I get:
Model: chuangmi.remote.v2
Hardware version: esp32
Firmware version: 2.0.6_0006
The ChuangmiRemoteV2
child class already states to cover "chuangmi-remote-v2". Do you wish it changed to "chuangmi.remote.v2" according to the model output above? (The default hostname on the network doesn't use periods though, but the actual model name is with periods). I can't confirm anything for the h102a03 model.
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.
Ah, yes, it's also in the ttile of the PR, sorry... The one reported by the info is the one to use for identification (as not all devices support the mDNS, which is used for the hostname).
"""Takes a Pronto Hex encoded IR command and number of repeats and returns a | ||
tuple containing a string encoded IR signal accepted by controller and | ||
frequency. Supports only raw Pronto format, starting with 0000. |
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.
"""Takes a Pronto Hex encoded IR command and number of repeats and returns a | |
tuple containing a string encoded IR signal accepted by controller and | |
frequency. Supports only raw Pronto format, starting with 0000. | |
"""Convert pronto to device-expected format. | |
Takes a Pronto Hex encoded IR command and number of repeats and returns a | |
tuple containing a string encoded IR signal accepted by controller and | |
frequency. Supports only raw Pronto format, starting with 0000. |
|
||
if heatshrink2 is None: | ||
raise ChuangmiIrException("heatshrink2 library is missing") | ||
raw, frequency = super().pronto_to_raw(pronto, repeats) |
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.
The docstring above mentions that only prontos starting with 0000
are supported. I think an exception should also be raised if the input is in invalid format.
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.
Also, the another class expects that repeats >= 0, that should also be the case here?
"""Class representing new type of Chuangmi IR Remote Controller identified by model | ||
"chuangmi-remote-v2". |
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.
See my comment above on simplifying the docstring & adding the model info.
I did not manage to write the azure expression correctly yet:
I'm looking for the proper way to refer to |
Should be great but I'm not willing to do it, as the current code works for me and I don't have time for a rewrite. TBH, this azure condition fix is my last contribution attempt. |
The heatshrink2 installs just fine here locally, so as long as those tests are not executed it should work just fine, no?
|
It didn't work on Azure, |
Hmm, actually sorry, on Azure at the moment it is failing when the tests are actually running. Checking it up.. |
Well, seems like the import is failing in other tests, a catch all try/except may fix it. |
Looking at the CI logs for the most recent build, the exception is
Fair enough, I appreciate your contribution & honesty, hopefully someone will hop in to do the last steps to get it merged :-) If you don't mind allow modifications to the PR from maintainers, I might do that at some point. |
The ImportError happens after a ValueError on traceback, while my |
All kudos to original work by @yawor's on PR rytilahti#501. Fixes rytilahti#495, fixes rytilahti#619, fixes rytilahti#811. Closes rytilahti#501. Partially covers rytilahti#1020.
ed631e2
to
07542d2
Compare
You are free to change the PR in whatever way you wish. My desire is just to have support for these devices merged in any way and get a new release with it so to easily import it in my projects. I commented above on one of the suggested additions asking what exactly you wish me to do, but you can simply reword it yourself as you please, seems easier. |
I'm wondering whether having changed the docs group to dev instead of creating a new one was worth it. I'm using |
Hi all, |
I've finished encoder too. I still have a FAIL on one test, but it is strange. The compression of a test file with default parameters produces a binary file slightly different than what the test expects, but the file decompresses properly and the decompressed content is identical to the original one. |
@oblitum yeah, you are right, the optional dependencies (currently android_backup and then heatshrink2 as new) should belong to their own group (sphinx & co are really useless for end users), my bad. @yawor hi there! Are you planning to publish that in pypi, too? So that we could simply swap the implementation later (or maybe even for this PR already)? |
@rytilahti yes, that's my plan. I've never done this though. I'll publish it on a github in a moment.
Results from my implementation:
The difference is quite big, but on the other hand IR payloads are rather small so the impact shouldn't be that big. The library can be imported conditionally. If the pyheatshrink2 is available, then use it. If not, then use pure Python version instead. |
Here's a link to my implementation: I think the best way to use it would be: try:
import heatshrink2
except ModuleNotFoundError:
import heatshrinkpy as heatshrink2 |
Nice work! 💯 Did you try to benchmark on pypy, too? It'll probably be faster, but in this case it does not really matter (due to payload sizes as you said, and no one is going to blast enough commands to notice the difference due to I/O anyway), so I think it's it's better to depend on heatshrinkpy directly without any fallbacks. |
Here's a benchmark on pypy 7.3.4 (Python 3.7.10 equivalent):
I'm actually surprised to see that much of a difference. |
chuangmi.remote.h102a03 warning, but device works fine. Logger: miio.device Found an unsupported model 'chuangmi.remote.h102a03' for class 'ChuangmiIr'. If this is working for you, please open an issue at https://github.com/rytilahti/python-miio/ About HA: Remote:
|
I've mostly rebased the work on #501, applied some formatting and adopted
heatshrink2 as dependency over heatshrink, which has become dead.
I've tested it on chuangmi.remote.v2 and it worked for sending pronto codes to
my Sony TV directly, which is great and will fulfill my intentions, but I still
couldn't make it learn commands, and discovery doesn't seem to work either.
Fixes #495, fixes #619, fixes #811
Closes #501
Partially covers #1020