-
-
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
KeyError('token') in EncryptionAdapter #1824
Comments
Hi Jarkko, that piece of code is one of the oldest in this project and it's indeed confusing for developers and end-users alike... Feel free to create a PR to separate the discovery from the handling of payload messages! The instructions for setting up a development env are documented in https://python-miio.readthedocs.io/en/latest/contributing.html . A cleaner separation will likely cleanup the code a bit, allow better error reporting towards users (there are plenty of hard-to-debug reports like home-assistant/core#92774 home-assistant/core#59215 home-assistant/core#67926 to name some from homeassistant repo, there are plenty in issues of this one, too where having a clearer separation in errors would be very useful to have), and open a way for cleaner implementation of #1683 in the future. |
Describe the bug
Library prints
Unable to decrypt, returning raw bytes
message for Hello packets due to missing context. This scary text confuses people when they debug unrelated issues. (yes, the issue title is a clickbait)Details
MiIOProtocol::discover
atpython-miio/miio/miioprotocol.py
Line 121 in f7b554f
Message
without giving contexttoken
EncryptionAdapter::_decode
atpython-miio/miio/protocol.py
Line 165 in f7b554f
token
is accessed from the context. It doesn't exists in the context and this throwsKeyError('token')
python-miio/miio/protocol.py
Line 168 in f7b554f
Proposed fix
Since the hello message is parsed differently in any case (see
Utils.is_hello
), we could separate the message types as:Additionally.
_discover
, we'd then useDiscoverMessage
instad ofMessage
Utils.is_hello
m.checksum
when accessing the token withm.token
inmiioprotocol.py
Other
I can also do a PR if that's prefereable. It'll take me a few moments to set up the environment first though.
The text was updated successfully, but these errors were encountered: