Skip to content
Merged
Changes from 16 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 28 additions & 4 deletions homeassistant/components/asuswrt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
)
from homeassistant.helpers import config_validation as cv
from homeassistant.helpers.discovery import async_load_platform
from homeassistant.helpers.event import async_call_later

_LOGGER = logging.getLogger(__name__)

Expand All @@ -31,6 +32,9 @@
DEFAULT_INTERFACE = "eth0"
DEFAULT_DNSMASQ = "/var/lib/misc"

FIRST_RETRY_TIME = 60
MAX_RETRY_TIME = 900

SECRET_GROUP = "Password or SSH Key"
SENSOR_TYPES = ["upload_speed", "download_speed", "download", "upload"]

Expand Down Expand Up @@ -59,7 +63,7 @@
)


async def async_setup(hass, config):
async def async_setup(hass, config, retry_delay=FIRST_RETRY_TIME):
"""Set up the asuswrt component."""

conf = config[DOMAIN]
Expand All @@ -77,10 +81,30 @@ async def async_setup(hass, config):
dnsmasq=conf[CONF_DNSMASQ],
)

await api.connection.async_connect()
try:
await api.connection.async_connect()
except OSError as ex:
Comment thread
MartinHjelmare marked this conversation as resolved.
_LOGGER.warning(ex)
pass
Comment thread
MartinHjelmare marked this conversation as resolved.
Outdated

if not api.is_connected:
_LOGGER.error("Unable to setup component")
return False

_LOGGER.warning(
"Error connecting %s to %s. Will retry in %s seconds...",
DOMAIN,
conf[CONF_HOST],
retry_delay,
)

async def retry_setup(now):
"""Retry setup if a eroor happens on asuswrt API."""
Comment thread
MartinHjelmare marked this conversation as resolved.
Outdated
await async_setup(
hass, config, retry_delay=min(2 * retry_delay, MAX_RETRY_TIME)
)

async_call_later(hass, retry_delay, retry_setup)

return True

hass.data[DATA_ASUSWRT] = api

Expand Down