Skip to content

Commit

Permalink
handle wrong mime type from cloud
Browse files Browse the repository at this point in the history
  • Loading branch information
chemwolf6922 committed Dec 19, 2024
1 parent 4b1f2a8 commit 4579b92
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions custom_components/xiaomi_home/miot/miot_cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,8 @@ async def __get_token_async(self, data) -> dict:
raise MIoTOauthError(
f'invalid http status code, {http_res.status}')

res_obj = await http_res.json()
res_str = await http_res.text()
res_obj = json.loads(res_str)
if (
not res_obj
or res_obj.get('code', None) != 0
Expand Down Expand Up @@ -287,7 +288,8 @@ async def __mihome_api_get_async(
raise MIoTHttpError(
f'mihome api get failed, {http_res.status}, '
f'{url_path}, {params}')
res_obj: dict = await http_res.json()
res_str = await http_res.text()
res_obj: dict = json.loads(res_str)
if res_obj.get('code', None) != 0:
raise MIoTHttpError(
f'invalid response code, {res_obj.get("code",None)}, '
Expand Down Expand Up @@ -316,7 +318,8 @@ async def __mihome_api_post_async(
raise MIoTHttpError(
f'mihome api post failed, {http_res.status}, '
f'{url_path}, {data}')
res_obj: dict = await http_res.json()
res_str = await http_res.text()
res_obj: dict = json.loads(res_str)
if res_obj.get('code', None) != 0:
raise MIoTHttpError(
f'invalid response code, {res_obj.get("code",None)}, '
Expand All @@ -335,7 +338,8 @@ async def get_user_info_async(self) -> dict:
timeout=MIHOME_HTTP_API_TIMEOUT
)

res_obj = await http_res.json()
res_str = await http_res.text()
res_obj = json.loads(res_str)
if (
not res_obj
or res_obj.get('code', None) != 0
Expand Down

0 comments on commit 4579b92

Please sign in to comment.