Skip to content

Commit

Permalink
Add log message on timeout and update less often for upnp devices (ho…
Browse files Browse the repository at this point in the history
…me-assistant#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
  • Loading branch information
StevenLooman authored Mar 15, 2020
1 parent f9634f0 commit b6e69cd
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 6 deletions.
2 changes: 1 addition & 1 deletion CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,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
Expand Down
20 changes: 16 additions & 4 deletions homeassistant/components/upnp/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,16 +142,28 @@ async def _async_delete_port_mapping(self, external_port):

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")
2 changes: 1 addition & 1 deletion homeassistant/components/upnp/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
"documentation": "https://www.home-assistant.io/integrations/upnp",
"requirements": ["async-upnp-client==0.14.12"],
"dependencies": [],
"codeowners": ["@robbiet480"]
"codeowners": ["@StevenLooman"]
}
5 changes: 5 additions & 0 deletions homeassistant/components/upnp/sensor.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -7,6 +8,7 @@
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
Expand All @@ -29,6 +31,8 @@
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
Expand Down Expand Up @@ -142,6 +146,7 @@ def unit_of_measurement(self) -> str:
"""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:
Expand Down

0 comments on commit b6e69cd

Please sign in to comment.