From 4e5574859c41626050a92fbe72cff38ca5db4ab2 Mon Sep 17 00:00:00 2001 From: Feng Wang Date: Thu, 19 Dec 2024 14:45:42 +0800 Subject: [PATCH] fixs --- .../xiaomi_home/miot/miot_cloud.py | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/custom_components/xiaomi_home/miot/miot_cloud.py b/custom_components/xiaomi_home/miot/miot_cloud.py index 2fd0b2a..f00cb7d 100644 --- a/custom_components/xiaomi_home/miot/miot_cloud.py +++ b/custom_components/xiaomi_home/miot/miot_cloud.py @@ -142,18 +142,18 @@ def gen_auth_url( return f'{OAUTH2_AUTH_URL}?{encoded_params}' async def __get_token_async(self, data) -> dict: - http_res = await aiohttp.get( + http_res = await self._session.get( url=f'https://{self._oauth_host}/app/v2/ha/oauth/get_token', params={'data': json.dumps(data)}, headers={'content-type': 'application/x-www-form-urlencoded'}, timeout=MIHOME_HTTP_API_TIMEOUT ) - if http_res.status_code == 401: + if http_res.status == 401: raise MIoTOauthError( 'unauthorized(401)', MIoTErrorCode.CODE_OAUTH_UNAUTHORIZED) - if http_res.status_code != 200: + if http_res.status != 200: raise MIoTOauthError( - f'invalid http status code, {http_res.status_code}') + f'invalid http status code, {http_res.status}') res_obj = await http_res.json() if ( @@ -278,13 +278,13 @@ async def __mihome_api_get_async( url=f'{self._base_url}{url_path}', params=params, timeout=timeout) - if http_res.status_code == 401: + if http_res.status == 401: raise MIoTHttpError( 'mihome api get failed, unauthorized(401)', MIoTErrorCode.CODE_HTTP_INVALID_ACCESS_TOKEN) - if http_res.status_code != 200: + if http_res.status != 200: raise MIoTHttpError( - f'mihome api get failed, {http_res.status_code}, ' + f'mihome api get failed, {http_res.status}, ' f'{url_path}, {params}') res_obj: dict = await http_res.json() if res_obj.get('code', None) != 0: @@ -307,13 +307,13 @@ async def __mihome_api_post_async( url=f'{self._base_url}{url_path}', data=encoded_data, timeout=timeout) - if http_res.status_code == 401: + if http_res.status == 401: raise MIoTHttpError( 'mihome api get failed, unauthorized(401)', MIoTErrorCode.CODE_HTTP_INVALID_ACCESS_TOKEN) - if http_res.status_code != 200: + if http_res.status != 200: raise MIoTHttpError( - f'mihome api post failed, {http_res.status_code}, ' + f'mihome api post failed, {http_res.status}, ' f'{url_path}, {data}') res_obj: dict = await http_res.json() if res_obj.get('code', None) != 0: