Re-authorize Huawei LTE on login required error (#29597)

* Re-authorize Huawei LTE on login required error

Closes https://github.com/home-assistant/home-assistant/issues/29531

* Eliminate one indented "else" block

* Convert get_data from inline to instance method

* Use .get instead of [] for checking subscriptions for clarity
This commit is contained in:
Ville Skyttä 2019-12-10 22:41:29 +02:00 committed by GitHub
parent 99328bd4c1
commit 899f6cf1a3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -157,11 +157,8 @@ class Router:
"""Get router connections for device registry."""
return {(dr.CONNECTION_NETWORK_MAC, self.mac)} if self.mac else set()
def update(self) -> None:
"""Update router data."""
def get_data(key: str, func: Callable[[None], Any]) -> None:
if not self.subscriptions[key]:
def _get_data(self, key: str, func: Callable[[None], Any]) -> None:
if not self.subscriptions.get(key):
return
_LOGGER.debug("Getting %s for subscribers %s", key, self.subscriptions[key])
try:
@ -172,6 +169,15 @@ class Router:
)
self.subscriptions.pop(key)
except ResponseErrorLoginRequiredException:
if isinstance(self.connection, AuthorizedConnection):
_LOGGER.debug("Trying to authorize again...")
if self.connection.enforce_authorized_connection():
_LOGGER.debug(
"...success, %s will be updated by a future periodic run", key,
)
else:
_LOGGER.debug("...failed")
return
_LOGGER.info(
"%s requires authorization, excluding from future updates", key
)
@ -179,18 +185,25 @@ class Router:
finally:
_LOGGER.debug("%s=%s", key, self.data.get(key))
get_data(KEY_DEVICE_INFORMATION, self.client.device.information)
def update(self) -> None:
"""Update router data."""
self._get_data(KEY_DEVICE_INFORMATION, self.client.device.information)
if self.data.get(KEY_DEVICE_INFORMATION):
# Full information includes everything in basic
self.subscriptions.pop(KEY_DEVICE_BASIC_INFORMATION, None)
get_data(KEY_DEVICE_BASIC_INFORMATION, self.client.device.basic_information)
get_data(KEY_DEVICE_SIGNAL, self.client.device.signal)
get_data(KEY_DIALUP_MOBILE_DATASWITCH, self.client.dial_up.mobile_dataswitch)
get_data(KEY_MONITORING_STATUS, self.client.monitoring.status)
get_data(
self._get_data(
KEY_DEVICE_BASIC_INFORMATION, self.client.device.basic_information
)
self._get_data(KEY_DEVICE_SIGNAL, self.client.device.signal)
self._get_data(
KEY_DIALUP_MOBILE_DATASWITCH, self.client.dial_up.mobile_dataswitch
)
self._get_data(KEY_MONITORING_STATUS, self.client.monitoring.status)
self._get_data(
KEY_MONITORING_TRAFFIC_STATISTICS, self.client.monitoring.traffic_statistics
)
get_data(KEY_WLAN_HOST_LIST, self.client.wlan.host_list)
self._get_data(KEY_WLAN_HOST_LIST, self.client.wlan.host_list)
self.signal_update()