Allow returning raw bytes from a request, without attempting to decode.#136
Conversation
|
Example usage to fetch a user's profile image to a file: |
|
Oh! That's actually pretty cool. |
Codecov Report
@@ Coverage Diff @@
## dev #136 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 20 20
Lines 947 953 +6
=========================================
+ Hits 947 953 +6
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
… `poetry run mypy homeassistant_api --show-error-codes`
For some reason, mypy didn't like the typechecking in the ternary operator, but is fine with the statement.
|
TIL how to use There was a type error detected by mypy unrelated to my changes ( |
|
Mypy can be weird like that sometimes lol |
|
Sorry, one last tweak - copied the wrong line earlier, thank you type-checking. |
Allow returning raw bytes from a request, without attempting to decode.
Some API calls can return binary data, e.g. fetching a user's profile image (e.g. api path like
/api/image/serve/<hash>/512x512).Currently this library attempts to decode all responses from
bytestostrusing the defaultutf-8encoding, which fails for API calls returning binary data since the first byte of e.g. JPEG data (0xFF) can't be decoded to text.This PR adds a by-default-no-change-to-external-behaviour flag to the
RawClient.requestmethod to optionally disable decoding for that request, just returning the raw bytes.