Fix P100 error getting conn closed when trying default login after login failure (#690)

This commit is contained in:
Steven B 2024-01-23 21:51:07 +00:00 committed by GitHub
parent e233e377ad
commit f045696ebe
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 32 additions and 13 deletions

View File

@ -180,19 +180,28 @@ class AesTransport(BaseTransport):
"""Login to the device.""" """Login to the device."""
try: try:
await self.try_login(self._login_params) await self.try_login(self._login_params)
except AuthenticationException as ex: except AuthenticationException as aex:
if ex.error_code != SmartErrorCode.LOGIN_ERROR: try:
raise ex if aex.error_code != SmartErrorCode.LOGIN_ERROR:
if self._default_credentials is None: raise aex
self._default_credentials = get_default_credentials( if self._default_credentials is None:
DEFAULT_CREDENTIALS["TAPO"] self._default_credentials = get_default_credentials(
DEFAULT_CREDENTIALS["TAPO"]
)
await self.perform_handshake()
await self.try_login(self._get_login_params(self._default_credentials))
_LOGGER.debug(
"%s: logged in with default credentials",
self._host,
) )
await self.perform_handshake() except AuthenticationException:
await self.try_login(self._get_login_params(self._default_credentials)) raise
_LOGGER.debug( except Exception as ex:
"%s: logged in with default credentials", raise AuthenticationException(
self._host, "Unable to login and trying default "
) + "login raised another exception: %s",
ex,
) from ex
async def try_login(self, login_params): async def try_login(self, login_params):
"""Try to login with supplied login_params.""" """Try to login with supplied login_params."""

View File

@ -106,8 +106,18 @@ async def test_login(mocker, status_code, error_code, inner_error_code, expectat
pytest.raises(AuthenticationException), pytest.raises(AuthenticationException),
1, 1,
), ),
(
[SmartErrorCode.LOGIN_ERROR, SmartErrorCode.SESSION_TIMEOUT_ERROR],
pytest.raises(SmartDeviceException),
3,
),
], ],
ids=("LOGIN_ERROR-success", "LOGIN_ERROR-LOGIN_ERROR", "LOGIN_FAILED_ERROR"), ids=(
"LOGIN_ERROR-success",
"LOGIN_ERROR-LOGIN_ERROR",
"LOGIN_FAILED_ERROR",
"LOGIN_ERROR-SESSION_TIMEOUT_ERROR",
),
) )
async def test_login_errors(mocker, inner_error_codes, expectation, call_count): async def test_login_errors(mocker, inner_error_codes, expectation, call_count):
host = "127.0.0.1" host = "127.0.0.1"