Skip to content

Commit

Permalink
Retry connecting if setup fails.
Browse files Browse the repository at this point in the history
  • Loading branch information
giachello committed Jan 22, 2023
1 parent 24e106d commit 6641a60
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions custom_components/mlgw/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

import voluptuous as vol

from homeassistant.config_entries import ConfigEntry
from homeassistant.config_entries import ConfigEntry, ConfigEntryNotReady
from homeassistant.const import (
CONF_HOST,
CONF_PASSWORD,
Expand Down Expand Up @@ -260,15 +260,23 @@ def send_all_standby(service: ServiceDataType):

async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
"""Set up MasterLink Gateway from a config entry."""
from requests.exceptions import RequestException

host = entry.data.get(CONF_HOST)
password = entry.data.get(CONF_PASSWORD)
username = entry.data.get(CONF_USERNAME)
use_mllog = entry.data.get(CONF_MLGW_USE_MLLOG)

mlgw_configurationdata = await hass.async_add_executor_job(
try:
mlgw_configurationdata = await hass.async_add_executor_job(
get_mlgw_configuration_data, host, username, password
)
except (RequestException) as ex:
# this will cause Home Assistant to retry setting up the integration later.
raise ConfigEntryNotReady(
f"Cannot connect to {host}, is it on?"
) from ex


if mlgw_configurationdata is None:
return False
Expand Down

0 comments on commit 6641a60

Please sign in to comment.