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 timeoutpull/32932/head
parent
1b622925a1
commit
0788bbd629
|
@ -386,7 +386,7 @@ homeassistant/components/unifiled/* @florisvdk
|
|||
homeassistant/components/upc_connect/* @pvizeli
|
||||
homeassistant/components/upcloud/* @scop
|
||||
homeassistant/components/updater/* @home-assistant/core
|
||||
homeassistant/components/upnp/* @robbiet480
|
||||
homeassistant/components/upnp/* @StevenLooman
|
||||
homeassistant/components/uptimerobot/* @ludeeus
|
||||
homeassistant/components/usgs_earthquakes_feed/* @exxamalte
|
||||
homeassistant/components/utility_meter/* @dgomes
|
||||
|
|
|
@ -142,16 +142,28 @@ class Device:
|
|||
|
||||
async def async_get_total_bytes_received(self):
|
||||
"""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):
|
||||
"""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):
|
||||
"""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):
|
||||
"""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",
|
||||
"requirements": ["async-upnp-client==0.14.12"],
|
||||
"dependencies": [],
|
||||
"codeowners": ["@robbiet480"]
|
||||
"codeowners": ["@StevenLooman"]
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
"""Support for UPnP/IGD Sensors."""
|
||||
from datetime import timedelta
|
||||
import logging
|
||||
|
||||
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.entity import Entity
|
||||
from homeassistant.helpers.typing import HomeAssistantType
|
||||
from homeassistant.util import Throttle
|
||||
import homeassistant.util.dt as dt_util
|
||||
|
||||
from .const import DOMAIN as DOMAIN_UPNP, SIGNAL_REMOVE_SENSOR
|
||||
|
@ -29,6 +31,8 @@ IN = "received"
|
|||
OUT = "sent"
|
||||
KIBIBYTE = 1024
|
||||
|
||||
MIN_TIME_BETWEEN_UPDATES = timedelta(seconds=30)
|
||||
|
||||
|
||||
async def async_setup_platform(
|
||||
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 self._type["unit"]
|
||||
|
||||
@Throttle(MIN_TIME_BETWEEN_UPDATES)
|
||||
async def async_update(self):
|
||||
"""Get the latest information from the IGD."""
|
||||
if self._type_name == BYTES_RECEIVED:
|
||||
|
|
Loading…
Reference in New Issue