diff --git a/CODEOWNERS b/CODEOWNERS index 97b347b8415..19bb89ff51e 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -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 diff --git a/homeassistant/components/upnp/device.py b/homeassistant/components/upnp/device.py index b144d2b96ed..474170050c3 100644 --- a/homeassistant/components/upnp/device.py +++ b/homeassistant/components/upnp/device.py @@ -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") diff --git a/homeassistant/components/upnp/manifest.json b/homeassistant/components/upnp/manifest.json index 1e55d60f95e..47ad465eb36 100644 --- a/homeassistant/components/upnp/manifest.json +++ b/homeassistant/components/upnp/manifest.json @@ -5,5 +5,5 @@ "documentation": "https://www.home-assistant.io/integrations/upnp", "requirements": ["async-upnp-client==0.14.12"], "dependencies": [], - "codeowners": ["@robbiet480"] + "codeowners": ["@StevenLooman"] } diff --git a/homeassistant/components/upnp/sensor.py b/homeassistant/components/upnp/sensor.py index c77a1b6279f..9632997ac1b 100644 --- a/homeassistant/components/upnp/sensor.py +++ b/homeassistant/components/upnp/sensor.py @@ -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: