Skip to content

Refactor the response parsing. Fixes an "increase volume" bug. Also minor comments and code cleanups.#31

Open
Plan-V64 wants to merge 5 commits intobasnijholt:mainfrom
Plan-V64:parse-refactor
Open

Refactor the response parsing. Fixes an "increase volume" bug. Also minor comments and code cleanups.#31
Plan-V64 wants to merge 5 commits intobasnijholt:mainfrom
Plan-V64:parse-refactor

Conversation

@Plan-V64
Copy link
Copy Markdown

When calling aiokef.AsyncKefSpeaker.increase_volume() when my speaker was at volume level 82%, aiokef did not parse the speaker's response data correctly, and thought that the volume level was 37%.

This caused aiokef to set the volume to 42% instead of the intended 87%.

The culprit is the .split(b"R") operation on the received data in _parse_response().


Heads-up: The refactored code introduces an assumption that the size of all responses that aiokef will currently encounter is 3 or 5 bytes. Please verify that you agree that that is a reasonable assumption for the current use cases of aiokef, before merging this commit.

Heads-up: The code cleanup includes a minor change of the API of _parse_response(). It now always returns the full message (including the leading "R" byte).

Plan V added 3 commits August 31, 2023 12:52
The prior code broke in the case where a response happened to contain a payload
byte equal to _RESPONSE_START. For example, when getting the speaker volume
which happens to be at 82%.

This refactoring also contains a minor API cleanup: it always returns the full
message, including the leading 0x52 byte. The old code was not consistent on
that point. This API change does not matter for the existing callers.
(Remove mixed use of the word "reply".)
@basnijholt
Copy link
Copy Markdown
Owner

basnijholt commented Sep 1, 2023

Thanks a lot!

Unfortunately, both my LS50Ws and LSXs broke ... so I do not have reliable means to test this.

Have you successfully run this code with real hardware?

If so, I will just click merge because the code seems solid 😄

@basnijholt
Copy link
Copy Markdown
Owner

I do not understand why the CI is not starting here 😅

@basnijholt basnijholt changed the base branch from main to always-disconnect September 2, 2023 05:44
@basnijholt basnijholt changed the base branch from always-disconnect to main September 2, 2023 05:44
@Plan-V64
Copy link
Copy Markdown
Author

Plan-V64 commented Sep 4, 2023

Unfortunately, both my LS50Ws and LSXs broke ... so I do not have reliable means to test this.

That is very disappointing! All the more so after you put in so much work to support them.

Have you successfully run this code with real hardware?

Yes, on the KEF LSX. (The original, not the LSX II.)

Caveats: I have:

  • Only used it to increase&decrease the volume parameter,
  • Only for a few days yet at this point,
  • Only from a tiny single-shot CLI process. (I.e. not from HomeAssistant or a similar use case.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants