Ville Skyttä 2022-05-05 19:37:32 +03:00 committed by GitHub
parent 8c89f68d2c
commit e3433008a2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 19 additions and 19 deletions

View File

@ -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

View File

@ -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,

View File

@ -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"
],

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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"}),
),
)