Skip to content

Commit

Permalink
Merge pull request #37 from scop/patch-1
Browse files Browse the repository at this point in the history
Use http.HTTPStatus instead of const.HTTP_*
  • Loading branch information
osk2 authored Oct 26, 2021
2 parents 78c3e37 + fdae3bf commit 2a4113b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 9 deletions.
10 changes: 4 additions & 6 deletions custom_components/panasonic_smart_app/smartApp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
)
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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(
Expand Down
3 changes: 0 additions & 3 deletions custom_components/panasonic_smart_app/smartApp/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 2a4113b

Please sign in to comment.