From fdae3bfbc122bd6af16d5413c2360e5db8686148 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20Skytt=C3=A4?= Date: Mon, 25 Oct 2021 21:49:11 +0300 Subject: [PATCH] Use http.HTTPStatus instead of const.HTTP_* https://github.com/home-assistant/core/pull/58380 --- .../panasonic_smart_app/smartApp/__init__.py | 10 ++++------ .../panasonic_smart_app/smartApp/const.py | 3 --- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/custom_components/panasonic_smart_app/smartApp/__init__.py b/custom_components/panasonic_smart_app/smartApp/__init__.py index 64d5d31..6fc97ef 100644 --- a/custom_components/panasonic_smart_app/smartApp/__init__.py +++ b/custom_components/panasonic_smart_app/smartApp/__init__.py @@ -2,10 +2,10 @@ from typing import Literal from datetime import datetime from collections import defaultdict +from http import HTTPStatus import asyncio import logging -from homeassistant.const import HTTP_OK from .exceptions import ( PanasonicRefreshTokenNotFound, PanasonicTokenExpired, @@ -20,8 +20,6 @@ SECONDS_BETWEEN_REQUEST, REQUEST_TIMEOUT, COMMANDS_PER_REQUEST, - HTTP_EXPECTATION_FAILED, - HTTP_TOO_MANY_REQUESTS, EXCEPTION_COMMAND_NOT_FOUND, EXCEPTION_INVALID_REFRESH_TOKEN, ) @@ -258,12 +256,12 @@ async def request( else: raise PanasonicDeviceOffline(f"無法連線至裝置,將於下輪更新時重試") - if response.status == HTTP_OK: + if response.status == HTTPStatus.OK: try: resp = await response.json() except: resp = {} - elif response.status == HTTP_EXPECTATION_FAILED: + elif response.status == HTTPStatus.EXPECTATION_FAILED: resp = {} try: resp = await response.json() @@ -293,7 +291,7 @@ async def request( ) raise PanasonicLoginFailed - elif response.status == HTTP_TOO_MANY_REQUESTS: + elif response.status == HTTPStatus.TOO_MANY_REQUESTS: raise PanasonicExceedRateLimit else: _LOGGER.error( diff --git a/custom_components/panasonic_smart_app/smartApp/const.py b/custom_components/panasonic_smart_app/smartApp/const.py index 02a62b9..fb5bcbe 100644 --- a/custom_components/panasonic_smart_app/smartApp/const.py +++ b/custom_components/panasonic_smart_app/smartApp/const.py @@ -6,9 +6,6 @@ REQUEST_TIMEOUT = 20 COMMANDS_PER_REQUEST = 6 -HTTP_EXPECTATION_FAILED = 417 -HTTP_TOO_MANY_REQUESTS = 429 - EXCEPTION_COMMAND_NOT_FOUND = "無法透過CommandId取得Commmand" EXCEPTION_TOKEN_EXPIRED = "無法依據您的CPToken,auth取得相關資料" EXCEPTION_INVALID_REFRESH_TOKEN = "無效RefreshToken"