Skip to content

Commit

Permalink
Fix bug caused by new error format
Browse files Browse the repository at this point in the history
- Increase update interval to 90 seconds
- Increase delay between requests to 2 seconds
- Reduce timeout to 20 seconds
  • Loading branch information
osk2 committed Aug 6, 2021
1 parent 783abba commit 888f165
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 14 deletions.
5 changes: 4 additions & 1 deletion custom_components/panasonic_smart_app/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,10 @@ async def async_update_data():
update_interval=timedelta(seconds=UPDATE_INTERVAL),
)

await coordinator.async_config_entry_first_refresh()
await coordinator.async_refresh()

if not coordinator.last_update_success:
raise ConfigEntryNotReady

hass.data[DOMAIN][entry.entry_id] = {
DATA_CLIENT: client,
Expand Down
2 changes: 1 addition & 1 deletion custom_components/panasonic_smart_app/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
DATA_CLIENT = "client"
DATA_COORDINATOR = "coordinator"

UPDATE_INTERVAL = 60
UPDATE_INTERVAL = 90

DEVICE_STATUS_CODES = {
DEVICE_TYPE_AC: [
Expand Down
15 changes: 5 additions & 10 deletions custom_components/panasonic_smart_app/smartApp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,9 @@ async def request(
except:
resp = {}
elif response.status == HTTP_EXPECTATION_FAILED:
returned_raw_data = await response.text()
resp = await response.json()

if returned_raw_data == EXCEPTION_COMMAND_NOT_FOUND:
if resp.get("StateMsg") == EXCEPTION_COMMAND_NOT_FOUND:
auth = headers["auth"]
if auth:
device = list(
Expand All @@ -187,20 +187,15 @@ async def request(
)
else:
raise PanasonicDeviceOffline
elif resp.get("StateMsg") == EXCEPTION_INVALID_REFRESH_TOKEN:
raise PanasonicTokenExpired
else:
_LOGGER.error(
"Failed to access API. Returned" " %d: %s",
response.status,
returned_raw_data,
)
try:
resp = await response.json()
if resp["StateMsg"] == EXCEPTION_INVALID_REFRESH_TOKEN:
raise PanasonicTokenExpired
else:
raise PanasonicLoginFailed
except:
raise PanasonicInvalidRefreshToken
raise PanasonicLoginFailed
elif response.status == HTTP_TOO_MANY_REQUESTS:
_LOGGER.error(
"Failed to access API. Returned" " %d: %s",
Expand Down
4 changes: 2 additions & 2 deletions custom_components/panasonic_smart_app/smartApp/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
APP_TOKEN = "D8CBFF4C-2824-4342-B22D-189166FEF503"
USER_AGENT = "Mozilla/5.0 (Linux; U; Android 2.2) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1"

SECONDS_BETWEEN_REQUEST = 1
REQUEST_TIMEOUT = 15
SECONDS_BETWEEN_REQUEST = 2
REQUEST_TIMEOUT = 20

HTTP_EXPECTATION_FAILED = 417
HTTP_TOO_MANY_REQUESTS = 429
Expand Down

0 comments on commit 888f165

Please sign in to comment.