Skip to content

Commit da09fbe

Browse files
authored
Merge pull request #42 from GrandMoff100/dev
Post Version Fixes
2 parents 90bfc7c + 0a01bd4 commit da09fbe

5 files changed

Lines changed: 17 additions & 11 deletions

File tree

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,8 @@
1818
**v2.4.0**
1919
- Bug fixes (see closed issues between releases)
2020
- Added a processing framework for hooking into mimetype processing
21-
- Fixed some issues with some ``AsyncClient`` methods
21+
- Fixed some issues with some ``AsyncClient`` methods
22+
23+
**v2.4.0.post1**
24+
- Replaced `text/plain` with `application/octet-stream` in docs and processing module.
25+
- Added message content to UnrecognizedStatusCodeError to help with user debugging

docs/processing.rst

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ To register a response processor you need to import the Processing class and the
1515
from homeassistant_api.processing import process_json
1616
1717
18-
@Processing.processor("text/plain", override=True)
18+
@Processing.processor("application/octet-stream", override=True)
1919
def text_processor(response):
2020
return response.text.lower()
2121
@@ -33,14 +33,17 @@ To register a response processor you need to import the Processing class and the
3333
client = Client(url, token)
3434
print(client.get_entities())
3535
36+
3637
In this example.
3738
The first processor (a function wrapped with the processor decorator) is going to be called when we receive a response that has that as its :code:`Content-Type` header.
38-
Because :code:`homeassistant_api` provides processors for :code:`text/plain` and :code:`application/json` by default,
39+
Because :code:`homeassistant_api` provides processors for :code:`application/octet-stream` and :code:`application/json` by default,
3940
we need to tell :code:`homeassistant_api` to override the default processor with :code:`override=True`.
4041
4142
The second processor is an async processor that only gets called when AsyncClient receives a response that has :code:`text/csv` as its :code:`Content-Type` header.
4243
If you wanted to override :code:`homeassistant_api`'s default json processing using the :code:`json` module with a different way to process json data.
4344
Such as using instead, the :code:`ujson` module (which is faster but more limiting).
4445
4546
The third processor function implements the default processor function for the :code:`application/json` mimetype after printing a string.
46-
If you wanted to run some intermediate processing
47+
If you wanted to run some intermediate processing.
48+
49+
Most likely the only processors you will ever use are :code:`application/json` and :code:`application/octet-stream`

homeassistant_api/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
from .processing import Processing
44

55

6-
__version__ = '2.4.0'
6+
__version__ = '2.4.0.post1'
77
__name__ = 'Homeassistant API'

homeassistant_api/errors.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ class ParameterMissingError(HomeassistantAPIError):
3131
class UnexpectedStatusCodeError(HomeassistantAPIError):
3232
"""Error raised when Homeassistant returns a response with status code that was unexpected."""
3333

34-
def __init__(self, code: int):
35-
super().__init__(f"Homeassistant return response with an unrecognized status code {code!r}")
34+
def __init__(self, code: int, content):
35+
super().__init__(f"Homeassistant return response with an unrecognized status code {code!r}.\n{content}")
3636

3737

3838
class UnauthorizedError(HomeassistantAPIError):

homeassistant_api/processing.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,7 @@ def process(self, _async=False):
7070
raise MethodNotAllowedError(self.response.request.method)
7171
else:
7272
print("If this happened, please report it at https://github.com/GrandMoff100/HomeAssistantAPI/issues with the request status code and the request content")
73-
print(self.response.content)
74-
raise UnexpectedStatusCodeError(self.response.status_code)
73+
raise UnexpectedStatusCodeError(self.response.status_code, self.response.content)
7574

7675

7776
# List of default processors
@@ -87,7 +86,7 @@ def process_json(response):
8786
raise MalformedDataError(f'Homeassistant responded with non-json response: {repr(response.text)}')
8887

8988

90-
@Processing.processor("text/plain")
89+
@Processing.processor("application/octet-stream")
9190
def process_text(response):
9291
"""Returns the plaintext of the reponse."""
9392
return response.text
@@ -105,7 +104,7 @@ async def async_process_json(response):
105104
raise MalformedDataError(f'Homeassistant responded with non-json response: {repr(await response.text())}')
106105

107106

108-
@Processing.async_processor("text/plain")
107+
@Processing.async_processor("application/octet-stream")
109108
async def async_process_text(response):
110109
"""Returns the plaintext of the reponse."""
111110
return await response.text()

0 commit comments

Comments
 (0)