Fix UnicodeDecodeError on malformed UTF-8 radio responses#12
Merged
wlcrs merged 1 commit intozhelev:masterfrom Apr 3, 2026
Merged
Fix UnicodeDecodeError on malformed UTF-8 radio responses#12wlcrs merged 1 commit intozhelev:masterfrom
wlcrs merged 1 commit intozhelev:masterfrom
Conversation
11 tasks
wlcrs
added a commit
to wlcrs/python-afsapi
that referenced
this pull request
Apr 3, 2026
Related to zhelev#12
wlcrs
pushed a commit
to wlcrs/python-afsapi
that referenced
this pull request
Apr 3, 2026
14 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Some Frontier Silicon radios truncate text metadata (e.g.
netRemote.play.info.text) at a fixed byte boundary, which can split a multi-byte UTF-8 character in half. This causes aUnicodeDecodeErrorin__call()at:doc = ET.fromstring(await result.text(encoding="utf-8"))This crashes the entire API call, making the device entity unavailable in downstream consumers like Home Assistant.
Root cause
The radio firmware returns text fields with a fixed-size buffer. When the text contains multi-byte UTF-8 characters (common in languages with diacritics - Czech, German, French, etc.), the firmware may cut the buffer mid-character.
For example, a real response from a Hama DIT2010 tuned to a Czech station (Expres FM):
The byte
0xc3at position0x14eis the start of a 2-byte UTF-8 sequence (e.g.c3 a9=e), but the continuation byte is missing - the text was truncated right before the closing</c8_array>XML tag.This produces:
Full traceback from Home Assistant:
Fix
Pass
errors="replace"toaiohttp'sresponse.text()so that malformed bytes are replaced with the Unicode replacement character (U+FFFD) instead of raising an exception. The textpodobn\xc3becomespodobn\ufffd- a single character is lost but the rest of the response (including the XML structure) is preserved.Test plan
get_play_text()raisesUnicodeDecodeError, device entity becomes unavailableget_play_text()returns the text with a replacement character, device stays functional