mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 03:07:37 +00:00
huawei_lte: try unsupported data retrievals only once (#25524)
* huawei_lte: try unsupported data retrievals only once Refs https://github.com/home-assistant/home-assistant/pull/23809 * Move huawei_lte_api imports to top level
This commit is contained in:
parent
1f9f201571
commit
f379bb4016
@ -3,9 +3,13 @@ from datetime import timedelta
|
|||||||
from functools import reduce
|
from functools import reduce
|
||||||
import logging
|
import logging
|
||||||
import operator
|
import operator
|
||||||
|
from typing import Any, Callable
|
||||||
|
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
import attr
|
import attr
|
||||||
|
from huawei_lte_api.AuthorizedConnection import AuthorizedConnection
|
||||||
|
from huawei_lte_api.Client import Client
|
||||||
|
from huawei_lte_api.exceptions import ResponseErrorNotSupportedException
|
||||||
|
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
CONF_URL, CONF_USERNAME, CONF_PASSWORD, EVENT_HOMEASSISTANT_STOP,
|
CONF_URL, CONF_USERNAME, CONF_PASSWORD, EVENT_HOMEASSISTANT_STOP,
|
||||||
@ -81,20 +85,23 @@ class RouterData:
|
|||||||
|
|
||||||
def _update(self) -> None:
|
def _update(self) -> None:
|
||||||
debugging = _LOGGER.isEnabledFor(logging.DEBUG)
|
debugging = _LOGGER.isEnabledFor(logging.DEBUG)
|
||||||
if debugging or "device_information" in self._subscriptions:
|
|
||||||
self.device_information = self.client.device.information()
|
def get_data(path: str, func: Callable[[None], Any]) -> None:
|
||||||
_LOGGER.debug("device_information=%s", self.device_information)
|
if debugging or path in self._subscriptions:
|
||||||
if debugging or "device_signal" in self._subscriptions:
|
try:
|
||||||
self.device_signal = self.client.device.signal()
|
setattr(self, path, func())
|
||||||
_LOGGER.debug("device_signal=%s", self.device_signal)
|
except ResponseErrorNotSupportedException as ex:
|
||||||
if debugging or "monitoring_traffic_statistics" in self._subscriptions:
|
_LOGGER.warning(
|
||||||
self.monitoring_traffic_statistics = \
|
"%s not supported by device", path, exc_info=ex)
|
||||||
self.client.monitoring.traffic_statistics()
|
self._subscriptions.discard(path)
|
||||||
_LOGGER.debug("monitoring_traffic_statistics=%s",
|
finally:
|
||||||
self.monitoring_traffic_statistics)
|
_LOGGER.debug("%s=%s", path, getattr(self, path))
|
||||||
if debugging or "wlan_host_list" in self._subscriptions:
|
|
||||||
self.wlan_host_list = self.client.wlan.host_list()
|
get_data("device_information", self.client.device.information)
|
||||||
_LOGGER.debug("wlan_host_list=%s", self.wlan_host_list)
|
get_data("device_signal", self.client.device.signal)
|
||||||
|
get_data("monitoring_traffic_statistics",
|
||||||
|
self.client.monitoring.traffic_statistics)
|
||||||
|
get_data("wlan_host_list", self.client.wlan.host_list)
|
||||||
|
|
||||||
|
|
||||||
@attr.s
|
@attr.s
|
||||||
@ -124,9 +131,6 @@ def setup(hass, config) -> bool:
|
|||||||
|
|
||||||
def _setup_lte(hass, lte_config) -> None:
|
def _setup_lte(hass, lte_config) -> None:
|
||||||
"""Set up Huawei LTE router."""
|
"""Set up Huawei LTE router."""
|
||||||
from huawei_lte_api.AuthorizedConnection import AuthorizedConnection
|
|
||||||
from huawei_lte_api.Client import Client
|
|
||||||
|
|
||||||
url = lte_config[CONF_URL]
|
url = lte_config[CONF_URL]
|
||||||
username = lte_config[CONF_USERNAME]
|
username = lte_config[CONF_USERNAME]
|
||||||
password = lte_config[CONF_PASSWORD]
|
password = lte_config[CONF_PASSWORD]
|
||||||
|
@ -177,6 +177,9 @@ homematicip==0.10.9
|
|||||||
# homeassistant.components.remember_the_milk
|
# homeassistant.components.remember_the_milk
|
||||||
httplib2==0.10.3
|
httplib2==0.10.3
|
||||||
|
|
||||||
|
# homeassistant.components.huawei_lte
|
||||||
|
huawei-lte-api==1.2.0
|
||||||
|
|
||||||
# homeassistant.components.influxdb
|
# homeassistant.components.influxdb
|
||||||
influxdb==5.2.0
|
influxdb==5.2.0
|
||||||
|
|
||||||
|
@ -87,6 +87,7 @@ TEST_REQUIREMENTS = (
|
|||||||
'homekit[IP]',
|
'homekit[IP]',
|
||||||
'homematicip',
|
'homematicip',
|
||||||
'httplib2',
|
'httplib2',
|
||||||
|
'huawei-lte-api',
|
||||||
'influxdb',
|
'influxdb',
|
||||||
'jsonpath',
|
'jsonpath',
|
||||||
'libpurecool',
|
'libpurecool',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user