Create dedicated methods for GET and POST#7
Conversation
- For Sonos, it can be missing
| async def __get(self, endpoint: str) -> Any: | ||
| """ Make a GET request to the TaHoma API """ | ||
| async with self.session.get(f"{self.api_url}{endpoint}") as response: | ||
| await self.check_response(response) | ||
| return await response.json() | ||
|
|
||
| async def __post(self, endpoint: str, payload: Optional[JSON] = None,) -> Any: | ||
| """ Make a POST request to the TaHoma API """ | ||
| async with self.session.post( | ||
| f"{self.api_url}{endpoint}", data=payload | ||
| ) as response: | ||
| await self.check_response(response) | ||
| return await response.json() |
There was a problem hiding this comment.
@iMicknl I don't call humps.decamelize for each response. I prefer call it only when needed to avoid useless process.
There was a problem hiding this comment.
I can understand, since we don't always process the response. For the event listener response you would need it as well (and it is missing now).
There was a problem hiding this comment.
Sure, we will have to think about it once implemented.
| operation (polling) | ||
| """ | ||
| response = await self.__do_http_request("POST", f"events/{listener_id}/fetch") | ||
| response = await self.__post(f"events/{listener_id}/fetch") |
There was a problem hiding this comment.
Could you add humps here as well?
There was a problem hiding this comment.
Why? We don't build the model here. We can create a Device from this response?
There was a problem hiding this comment.
Decimalising is not just for the models. Currently, no model has been created for the event listener, however this JSON can be consumed already and it would be good to have snake_case keys in there, instead of camelCase.
Otherwise, we add it back in a new PR, where we also add proper models.
There was a problem hiding this comment.
I prefer to do it in another PR when the model will be ready. Here it will make not yet sense.
No description provided.