mirror of
https://github.com/home-assistant/core.git
synced 2025-07-10 06:47:09 +00:00
Handle UpnpError exceptions when getting WAN status and external IP address (#56744)
This commit is contained in:
parent
2e02945833
commit
a6a3745413
@ -8,6 +8,7 @@ from urllib.parse import urlparse
|
|||||||
|
|
||||||
from async_upnp_client import UpnpDevice, UpnpFactory
|
from async_upnp_client import UpnpDevice, UpnpFactory
|
||||||
from async_upnp_client.aiohttp import AiohttpSessionRequester
|
from async_upnp_client.aiohttp import AiohttpSessionRequester
|
||||||
|
from async_upnp_client.exceptions import UpnpError
|
||||||
from async_upnp_client.profiles.igd import IgdDevice
|
from async_upnp_client.profiles.igd import IgdDevice
|
||||||
|
|
||||||
from homeassistant.components import ssdp
|
from homeassistant.components import ssdp
|
||||||
@ -46,7 +47,7 @@ class Device:
|
|||||||
"""Create UPnP device."""
|
"""Create UPnP device."""
|
||||||
# Build async_upnp_client requester.
|
# Build async_upnp_client requester.
|
||||||
session = async_get_clientsession(hass)
|
session = async_get_clientsession(hass)
|
||||||
requester = AiohttpSessionRequester(session, True, 10)
|
requester = AiohttpSessionRequester(session, True, 20)
|
||||||
|
|
||||||
# Create async_upnp_client device.
|
# Create async_upnp_client device.
|
||||||
factory = UpnpFactory(requester, disable_state_variable_validation=True)
|
factory = UpnpFactory(requester, disable_state_variable_validation=True)
|
||||||
@ -168,10 +169,29 @@ class Device:
|
|||||||
values = await asyncio.gather(
|
values = await asyncio.gather(
|
||||||
self._igd_device.async_get_status_info(),
|
self._igd_device.async_get_status_info(),
|
||||||
self._igd_device.async_get_external_ip_address(),
|
self._igd_device.async_get_external_ip_address(),
|
||||||
|
return_exceptions=True,
|
||||||
)
|
)
|
||||||
|
result = []
|
||||||
|
for idx, value in enumerate(values):
|
||||||
|
if isinstance(value, UpnpError):
|
||||||
|
# Not all routers support some of these items although based
|
||||||
|
# on defined standard they should.
|
||||||
|
_LOGGER.debug(
|
||||||
|
"Exception occurred while trying to get status %s for device %s: %s",
|
||||||
|
"status" if idx == 1 else "external IP address",
|
||||||
|
self,
|
||||||
|
str(value),
|
||||||
|
)
|
||||||
|
result.append(None)
|
||||||
|
continue
|
||||||
|
|
||||||
|
if isinstance(value, Exception):
|
||||||
|
raise value
|
||||||
|
|
||||||
|
result.append(value)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
WAN_STATUS: values[0][0] if values[0] is not None else None,
|
WAN_STATUS: result[0][0] if result[0] is not None else None,
|
||||||
ROUTER_UPTIME: values[0][2] if values[0] is not None else None,
|
ROUTER_UPTIME: result[0][2] if result[0] is not None else None,
|
||||||
ROUTER_IP: values[1],
|
ROUTER_IP: result[1],
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user