mirror of https://github.com/home-assistant/core
Upgrade huawei-lte-api to 1.6.0, adapt to it (#71041)
* Upgrade huawei-lte-api to 1.6.0, adapt to it https://github.com/Salamek/huawei-lte-api/releases/tag/1.5 https://github.com/Salamek/huawei-lte-api/releases/tag/1.5.1 https://github.com/Salamek/huawei-lte-api/releases/tag/1.5.2 https://github.com/Salamek/huawei-lte-api/releases/tag/1.5.3 https://github.com/Salamek/huawei-lte-api/releases/tag/1.5.4 https://github.com/Salamek/huawei-lte-api/releases/tag/1.6 * Fix logout on config flow Co-authored-by: Antonino Piazza <antpza@gmail.com>
This commit is contained in:
parent
8c89f68d2c
commit
e3433008a2
|
@ -10,9 +10,9 @@ import logging
|
||||||
import time
|
import time
|
||||||
from typing import Any, NamedTuple, cast
|
from typing import Any, NamedTuple, cast
|
||||||
|
|
||||||
from huawei_lte_api.AuthorizedConnection import AuthorizedConnection
|
|
||||||
from huawei_lte_api.Client import Client
|
from huawei_lte_api.Client import Client
|
||||||
from huawei_lte_api.Connection import Connection
|
from huawei_lte_api.Connection import Connection
|
||||||
|
from huawei_lte_api.enums.device import ControlModeEnum
|
||||||
from huawei_lte_api.exceptions import (
|
from huawei_lte_api.exceptions import (
|
||||||
ResponseErrorException,
|
ResponseErrorException,
|
||||||
ResponseErrorLoginRequiredException,
|
ResponseErrorLoginRequiredException,
|
||||||
|
@ -186,9 +186,12 @@ class Router:
|
||||||
try:
|
try:
|
||||||
self.data[key] = func()
|
self.data[key] = func()
|
||||||
except ResponseErrorLoginRequiredException:
|
except ResponseErrorLoginRequiredException:
|
||||||
if isinstance(self.connection, AuthorizedConnection):
|
if not self.config_entry.options.get(CONF_UNAUTHENTICATED_MODE):
|
||||||
_LOGGER.debug("Trying to authorize again")
|
_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(
|
_LOGGER.debug(
|
||||||
"success, %s will be updated by a future periodic run",
|
"success, %s will be updated by a future periodic run",
|
||||||
key,
|
key,
|
||||||
|
@ -276,8 +279,6 @@ class Router:
|
||||||
|
|
||||||
def logout(self) -> None:
|
def logout(self) -> None:
|
||||||
"""Log out router session."""
|
"""Log out router session."""
|
||||||
if not isinstance(self.connection, AuthorizedConnection):
|
|
||||||
return
|
|
||||||
try:
|
try:
|
||||||
self.client.user.logout()
|
self.client.user.logout()
|
||||||
except ResponseErrorNotSupportedException:
|
except ResponseErrorNotSupportedException:
|
||||||
|
@ -293,6 +294,7 @@ class Router:
|
||||||
self.subscriptions.clear()
|
self.subscriptions.clear()
|
||||||
|
|
||||||
self.logout()
|
self.logout()
|
||||||
|
self.connection.requests_session.close()
|
||||||
|
|
||||||
|
|
||||||
class HuaweiLteData(NamedTuple):
|
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")
|
_LOGGER.debug("Connecting in authenticated mode, full feature set")
|
||||||
username = entry.data.get(CONF_USERNAME) or ""
|
username = entry.data.get(CONF_USERNAME) or ""
|
||||||
password = entry.data.get(CONF_PASSWORD) or ""
|
password = entry.data.get(CONF_PASSWORD) or ""
|
||||||
connection = AuthorizedConnection(
|
connection = Connection(
|
||||||
url, username=username, password=password, timeout=CONNECTION_TIMEOUT
|
url, username=username, password=password, timeout=CONNECTION_TIMEOUT
|
||||||
)
|
)
|
||||||
return connection
|
return connection
|
||||||
|
@ -515,7 +517,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||||
if router.suspended:
|
if router.suspended:
|
||||||
_LOGGER.debug("%s: ignored, integration suspended", service.service)
|
_LOGGER.debug("%s: ignored, integration suspended", service.service)
|
||||||
return
|
return
|
||||||
result = router.client.device.reboot()
|
result = router.client.device.set_control(ControlModeEnum.REBOOT)
|
||||||
_LOGGER.debug("%s: %s", service.service, result)
|
_LOGGER.debug("%s: %s", service.service, result)
|
||||||
elif service.service == SERVICE_RESUME_INTEGRATION:
|
elif service.service == SERVICE_RESUME_INTEGRATION:
|
||||||
# Login will be handled automatically on demand
|
# Login will be handled automatically on demand
|
||||||
|
|
|
@ -5,9 +5,9 @@ import logging
|
||||||
from typing import TYPE_CHECKING, Any
|
from typing import TYPE_CHECKING, Any
|
||||||
from urllib.parse import urlparse
|
from urllib.parse import urlparse
|
||||||
|
|
||||||
from huawei_lte_api.AuthorizedConnection import AuthorizedConnection
|
|
||||||
from huawei_lte_api.Client import Client
|
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 (
|
from huawei_lte_api.exceptions import (
|
||||||
LoginErrorPasswordWrongException,
|
LoginErrorPasswordWrongException,
|
||||||
LoginErrorUsernamePasswordOverrunException,
|
LoginErrorUsernamePasswordOverrunException,
|
||||||
|
@ -108,19 +108,17 @@ class ConfigFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
||||||
user_input=user_input, errors=errors
|
user_input=user_input, errors=errors
|
||||||
)
|
)
|
||||||
|
|
||||||
conn: AuthorizedConnection
|
|
||||||
|
|
||||||
def logout() -> None:
|
def logout() -> None:
|
||||||
try:
|
try:
|
||||||
conn.user.logout()
|
conn.user_session.user.logout() # type: ignore[union-attr]
|
||||||
except Exception: # pylint: disable=broad-except
|
except Exception: # pylint: disable=broad-except
|
||||||
_LOGGER.debug("Could not logout", exc_info=True)
|
_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."""
|
"""Try connecting with given credentials."""
|
||||||
username = user_input.get(CONF_USERNAME) or ""
|
username = user_input.get(CONF_USERNAME) or ""
|
||||||
password = user_input.get(CONF_PASSWORD) or ""
|
password = user_input.get(CONF_PASSWORD) or ""
|
||||||
conn = AuthorizedConnection(
|
conn = Connection(
|
||||||
user_input[CONF_URL],
|
user_input[CONF_URL],
|
||||||
username=username,
|
username=username,
|
||||||
password=password,
|
password=password,
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
"config_flow": true,
|
"config_flow": true,
|
||||||
"documentation": "https://www.home-assistant.io/integrations/huawei_lte",
|
"documentation": "https://www.home-assistant.io/integrations/huawei_lte",
|
||||||
"requirements": [
|
"requirements": [
|
||||||
"huawei-lte-api==1.4.18",
|
"huawei-lte-api==1.6.0",
|
||||||
"stringcase==1.2.0",
|
"stringcase==1.2.0",
|
||||||
"url-normalize==1.4.1"
|
"url-normalize==1.4.1"
|
||||||
],
|
],
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
"""Utilities for the Huawei LTE integration."""
|
"""Utilities for the Huawei LTE integration."""
|
||||||
from __future__ import annotations
|
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
|
from homeassistant.helpers.device_registry import format_mac
|
||||||
|
|
||||||
|
|
|
@ -837,7 +837,7 @@ horimote==0.4.1
|
||||||
httplib2==0.20.4
|
httplib2==0.20.4
|
||||||
|
|
||||||
# homeassistant.components.huawei_lte
|
# homeassistant.components.huawei_lte
|
||||||
huawei-lte-api==1.4.18
|
huawei-lte-api==1.6.0
|
||||||
|
|
||||||
# homeassistant.components.huisbaasje
|
# homeassistant.components.huisbaasje
|
||||||
huisbaasje-client==0.1.0
|
huisbaasje-client==0.1.0
|
||||||
|
|
|
@ -595,7 +595,7 @@ homepluscontrol==0.0.5
|
||||||
httplib2==0.20.4
|
httplib2==0.20.4
|
||||||
|
|
||||||
# homeassistant.components.huawei_lte
|
# homeassistant.components.huawei_lte
|
||||||
huawei-lte-api==1.4.18
|
huawei-lte-api==1.6.0
|
||||||
|
|
||||||
# homeassistant.components.huisbaasje
|
# homeassistant.components.huisbaasje
|
||||||
huisbaasje-client==0.1.0
|
huisbaasje-client==0.1.0
|
||||||
|
|
|
@ -127,7 +127,7 @@ def login_requests_mock(requests_mock):
|
||||||
LoginErrorEnum.USERNAME_PWD_WRONG,
|
LoginErrorEnum.USERNAME_PWD_WRONG,
|
||||||
{CONF_USERNAME: "invalid_auth"},
|
{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"}),
|
(ResponseCodeEnum.ERROR_SYSTEM_UNKNOWN, {"base": "response_error"}),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
Loading…
Reference in New Issue