mirror of
https://github.com/home-assistant/core.git
synced 2025-07-14 00:37:13 +00:00
Add log message on timeout and update less often for upnp devices (#32740)
* Catch asyncio.TimeoutError, show a proper message instead * Throttle updates to max once per 30s * Change code owner * Fix CODEOWNERS + linting * Warn on connection timeout
This commit is contained in:
parent
f9634f0232
commit
b6e69cd370
@ -387,7 +387,7 @@ homeassistant/components/unifiled/* @florisvdk
|
|||||||
homeassistant/components/upc_connect/* @pvizeli
|
homeassistant/components/upc_connect/* @pvizeli
|
||||||
homeassistant/components/upcloud/* @scop
|
homeassistant/components/upcloud/* @scop
|
||||||
homeassistant/components/updater/* @home-assistant/core
|
homeassistant/components/updater/* @home-assistant/core
|
||||||
homeassistant/components/upnp/* @robbiet480
|
homeassistant/components/upnp/* @StevenLooman
|
||||||
homeassistant/components/uptimerobot/* @ludeeus
|
homeassistant/components/uptimerobot/* @ludeeus
|
||||||
homeassistant/components/usgs_earthquakes_feed/* @exxamalte
|
homeassistant/components/usgs_earthquakes_feed/* @exxamalte
|
||||||
homeassistant/components/utility_meter/* @dgomes
|
homeassistant/components/utility_meter/* @dgomes
|
||||||
|
@ -142,16 +142,28 @@ class Device:
|
|||||||
|
|
||||||
async def async_get_total_bytes_received(self):
|
async def async_get_total_bytes_received(self):
|
||||||
"""Get total bytes received."""
|
"""Get total bytes received."""
|
||||||
return await self._igd_device.async_get_total_bytes_received()
|
try:
|
||||||
|
return await self._igd_device.async_get_total_bytes_received()
|
||||||
|
except asyncio.TimeoutError:
|
||||||
|
_LOGGER.warning("Timeout during get_total_bytes_received")
|
||||||
|
|
||||||
async def async_get_total_bytes_sent(self):
|
async def async_get_total_bytes_sent(self):
|
||||||
"""Get total bytes sent."""
|
"""Get total bytes sent."""
|
||||||
return await self._igd_device.async_get_total_bytes_sent()
|
try:
|
||||||
|
return await self._igd_device.async_get_total_bytes_sent()
|
||||||
|
except asyncio.TimeoutError:
|
||||||
|
_LOGGER.warning("Timeout during get_total_bytes_sent")
|
||||||
|
|
||||||
async def async_get_total_packets_received(self):
|
async def async_get_total_packets_received(self):
|
||||||
"""Get total packets received."""
|
"""Get total packets received."""
|
||||||
return await self._igd_device.async_get_total_packets_received()
|
try:
|
||||||
|
return await self._igd_device.async_get_total_packets_received()
|
||||||
|
except asyncio.TimeoutError:
|
||||||
|
_LOGGER.warning("Timeout during get_total_packets_received")
|
||||||
|
|
||||||
async def async_get_total_packets_sent(self):
|
async def async_get_total_packets_sent(self):
|
||||||
"""Get total packets sent."""
|
"""Get total packets sent."""
|
||||||
return await self._igd_device.async_get_total_packets_sent()
|
try:
|
||||||
|
return await self._igd_device.async_get_total_packets_sent()
|
||||||
|
except asyncio.TimeoutError:
|
||||||
|
_LOGGER.warning("Timeout during get_total_packets_sent")
|
||||||
|
@ -5,5 +5,5 @@
|
|||||||
"documentation": "https://www.home-assistant.io/integrations/upnp",
|
"documentation": "https://www.home-assistant.io/integrations/upnp",
|
||||||
"requirements": ["async-upnp-client==0.14.12"],
|
"requirements": ["async-upnp-client==0.14.12"],
|
||||||
"dependencies": [],
|
"dependencies": [],
|
||||||
"codeowners": ["@robbiet480"]
|
"codeowners": ["@StevenLooman"]
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
"""Support for UPnP/IGD Sensors."""
|
"""Support for UPnP/IGD Sensors."""
|
||||||
|
from datetime import timedelta
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from homeassistant.const import DATA_BYTES, DATA_KIBIBYTES, TIME_SECONDS
|
from homeassistant.const import DATA_BYTES, DATA_KIBIBYTES, TIME_SECONDS
|
||||||
@ -7,6 +8,7 @@ from homeassistant.helpers import device_registry as dr
|
|||||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||||
from homeassistant.helpers.entity import Entity
|
from homeassistant.helpers.entity import Entity
|
||||||
from homeassistant.helpers.typing import HomeAssistantType
|
from homeassistant.helpers.typing import HomeAssistantType
|
||||||
|
from homeassistant.util import Throttle
|
||||||
import homeassistant.util.dt as dt_util
|
import homeassistant.util.dt as dt_util
|
||||||
|
|
||||||
from .const import DOMAIN as DOMAIN_UPNP, SIGNAL_REMOVE_SENSOR
|
from .const import DOMAIN as DOMAIN_UPNP, SIGNAL_REMOVE_SENSOR
|
||||||
@ -29,6 +31,8 @@ IN = "received"
|
|||||||
OUT = "sent"
|
OUT = "sent"
|
||||||
KIBIBYTE = 1024
|
KIBIBYTE = 1024
|
||||||
|
|
||||||
|
MIN_TIME_BETWEEN_UPDATES = timedelta(seconds=30)
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_platform(
|
async def async_setup_platform(
|
||||||
hass: HomeAssistantType, config, async_add_entities, discovery_info=None
|
hass: HomeAssistantType, config, async_add_entities, discovery_info=None
|
||||||
@ -142,6 +146,7 @@ class RawUPnPIGDSensor(UpnpSensor):
|
|||||||
"""Return the unit of measurement of this entity, if any."""
|
"""Return the unit of measurement of this entity, if any."""
|
||||||
return self._type["unit"]
|
return self._type["unit"]
|
||||||
|
|
||||||
|
@Throttle(MIN_TIME_BETWEEN_UPDATES)
|
||||||
async def async_update(self):
|
async def async_update(self):
|
||||||
"""Get the latest information from the IGD."""
|
"""Get the latest information from the IGD."""
|
||||||
if self._type_name == BYTES_RECEIVED:
|
if self._type_name == BYTES_RECEIVED:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user