From 4579b926de8d6a208448bf2bc19448175aa4d0f2 Mon Sep 17 00:00:00 2001 From: Feng Wang Date: Thu, 19 Dec 2024 22:55:04 +0800 Subject: [PATCH] handle wrong mime type from cloud --- custom_components/xiaomi_home/miot/miot_cloud.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/custom_components/xiaomi_home/miot/miot_cloud.py b/custom_components/xiaomi_home/miot/miot_cloud.py index dd4746a..283da3e 100644 --- a/custom_components/xiaomi_home/miot/miot_cloud.py +++ b/custom_components/xiaomi_home/miot/miot_cloud.py @@ -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 @@ -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)}, ' @@ -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)}, ' @@ -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