diff --git a/custom_components/panasonic_smart_app/__init__.py b/custom_components/panasonic_smart_app/__init__.py index 4c6bf10..af514e1 100644 --- a/custom_components/panasonic_smart_app/__init__.py +++ b/custom_components/panasonic_smart_app/__init__.py @@ -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, diff --git a/custom_components/panasonic_smart_app/const.py b/custom_components/panasonic_smart_app/const.py index 3b8a4ff..0d26b01 100644 --- a/custom_components/panasonic_smart_app/const.py +++ b/custom_components/panasonic_smart_app/const.py @@ -26,7 +26,7 @@ DATA_CLIENT = "client" DATA_COORDINATOR = "coordinator" -UPDATE_INTERVAL = 60 +UPDATE_INTERVAL = 90 DEVICE_STATUS_CODES = { DEVICE_TYPE_AC: [ diff --git a/custom_components/panasonic_smart_app/smartApp/__init__.py b/custom_components/panasonic_smart_app/smartApp/__init__.py index 21a85fa..5de42be 100644 --- a/custom_components/panasonic_smart_app/smartApp/__init__.py +++ b/custom_components/panasonic_smart_app/smartApp/__init__.py @@ -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( @@ -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", diff --git a/custom_components/panasonic_smart_app/smartApp/const.py b/custom_components/panasonic_smart_app/smartApp/const.py index e83928d..20b8d41 100644 --- a/custom_components/panasonic_smart_app/smartApp/const.py +++ b/custom_components/panasonic_smart_app/smartApp/const.py @@ -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