diff --git a/homeassistant/components/huawei_lte/__init__.py b/homeassistant/components/huawei_lte/__init__.py index ca15731641d2..d8afbd752a4c 100644 --- a/homeassistant/components/huawei_lte/__init__.py +++ b/homeassistant/components/huawei_lte/__init__.py @@ -10,9 +10,9 @@ import logging import time from typing import Any, NamedTuple, cast -from huawei_lte_api.AuthorizedConnection import AuthorizedConnection from huawei_lte_api.Client import Client from huawei_lte_api.Connection import Connection +from huawei_lte_api.enums.device import ControlModeEnum from huawei_lte_api.exceptions import ( ResponseErrorException, ResponseErrorLoginRequiredException, @@ -186,9 +186,12 @@ class Router: try: self.data[key] = func() except ResponseErrorLoginRequiredException: - if isinstance(self.connection, AuthorizedConnection): + if not self.config_entry.options.get(CONF_UNAUTHENTICATED_MODE): _LOGGER.debug("Trying to authorize again") - if self.connection.enforce_authorized_connection(): + if self.client.user.login( + self.config_entry.data.get(CONF_USERNAME, ""), + self.config_entry.data.get(CONF_PASSWORD, ""), + ): _LOGGER.debug( "success, %s will be updated by a future periodic run", key, @@ -276,8 +279,6 @@ class Router: def logout(self) -> None: """Log out router session.""" - if not isinstance(self.connection, AuthorizedConnection): - return try: self.client.user.logout() except ResponseErrorNotSupportedException: @@ -293,6 +294,7 @@ class Router: self.subscriptions.clear() self.logout() + self.connection.requests_session.close() class HuaweiLteData(NamedTuple): @@ -315,7 +317,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: _LOGGER.debug("Connecting in authenticated mode, full feature set") username = entry.data.get(CONF_USERNAME) or "" password = entry.data.get(CONF_PASSWORD) or "" - connection = AuthorizedConnection( + connection = Connection( url, username=username, password=password, timeout=CONNECTION_TIMEOUT ) return connection @@ -515,7 +517,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: if router.suspended: _LOGGER.debug("%s: ignored, integration suspended", service.service) return - result = router.client.device.reboot() + result = router.client.device.set_control(ControlModeEnum.REBOOT) _LOGGER.debug("%s: %s", service.service, result) elif service.service == SERVICE_RESUME_INTEGRATION: # Login will be handled automatically on demand diff --git a/homeassistant/components/huawei_lte/config_flow.py b/homeassistant/components/huawei_lte/config_flow.py index f4ea7cd86f77..3dfd38d63040 100644 --- a/homeassistant/components/huawei_lte/config_flow.py +++ b/homeassistant/components/huawei_lte/config_flow.py @@ -5,9 +5,9 @@ import logging from typing import TYPE_CHECKING, Any from urllib.parse import urlparse -from huawei_lte_api.AuthorizedConnection import AuthorizedConnection from huawei_lte_api.Client import Client -from huawei_lte_api.Connection import GetResponseType +from huawei_lte_api.Connection import Connection +from huawei_lte_api.Session import GetResponseType from huawei_lte_api.exceptions import ( LoginErrorPasswordWrongException, LoginErrorUsernamePasswordOverrunException, @@ -108,19 +108,17 @@ class ConfigFlowHandler(config_entries.ConfigFlow, domain=DOMAIN): user_input=user_input, errors=errors ) - conn: AuthorizedConnection - def logout() -> None: try: - conn.user.logout() + conn.user_session.user.logout() # type: ignore[union-attr] except Exception: # pylint: disable=broad-except _LOGGER.debug("Could not logout", exc_info=True) - def try_connect(user_input: dict[str, Any]) -> AuthorizedConnection: + def try_connect(user_input: dict[str, Any]) -> Connection: """Try connecting with given credentials.""" username = user_input.get(CONF_USERNAME) or "" password = user_input.get(CONF_PASSWORD) or "" - conn = AuthorizedConnection( + conn = Connection( user_input[CONF_URL], username=username, password=password, diff --git a/homeassistant/components/huawei_lte/manifest.json b/homeassistant/components/huawei_lte/manifest.json index 3e7ebf24b163..dd0382d5f555 100644 --- a/homeassistant/components/huawei_lte/manifest.json +++ b/homeassistant/components/huawei_lte/manifest.json @@ -4,7 +4,7 @@ "config_flow": true, "documentation": "https://www.home-assistant.io/integrations/huawei_lte", "requirements": [ - "huawei-lte-api==1.4.18", + "huawei-lte-api==1.6.0", "stringcase==1.2.0", "url-normalize==1.4.1" ], diff --git a/homeassistant/components/huawei_lte/utils.py b/homeassistant/components/huawei_lte/utils.py index 69b346a58f4e..37f9f1a55427 100644 --- a/homeassistant/components/huawei_lte/utils.py +++ b/homeassistant/components/huawei_lte/utils.py @@ -1,7 +1,7 @@ """Utilities for the Huawei LTE integration.""" from __future__ import annotations -from huawei_lte_api.Connection import GetResponseType +from huawei_lte_api.Session import GetResponseType from homeassistant.helpers.device_registry import format_mac diff --git a/requirements_all.txt b/requirements_all.txt index 4a7f5e25e46b..eb0b504bdaad 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -837,7 +837,7 @@ horimote==0.4.1 httplib2==0.20.4 # homeassistant.components.huawei_lte -huawei-lte-api==1.4.18 +huawei-lte-api==1.6.0 # homeassistant.components.huisbaasje huisbaasje-client==0.1.0 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index 8d1f5da4bbb7..01f4a2d339a1 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -595,7 +595,7 @@ homepluscontrol==0.0.5 httplib2==0.20.4 # homeassistant.components.huawei_lte -huawei-lte-api==1.4.18 +huawei-lte-api==1.6.0 # homeassistant.components.huisbaasje huisbaasje-client==0.1.0 diff --git a/tests/components/huawei_lte/test_config_flow.py b/tests/components/huawei_lte/test_config_flow.py index 52b46c57b982..b363836cc4f5 100644 --- a/tests/components/huawei_lte/test_config_flow.py +++ b/tests/components/huawei_lte/test_config_flow.py @@ -127,7 +127,7 @@ def login_requests_mock(requests_mock): LoginErrorEnum.USERNAME_PWD_WRONG, {CONF_USERNAME: "invalid_auth"}, ), - (LoginErrorEnum.USERNAME_PWD_ORERRUN, {"base": "login_attempts_exceeded"}), + (LoginErrorEnum.USERNAME_PWD_OVERRUN, {"base": "login_attempts_exceeded"}), (ResponseCodeEnum.ERROR_SYSTEM_UNKNOWN, {"base": "response_error"}), ), )