From cccd4d734cd71d2c7d1dc257dd4d788055641785 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Adam=20Kr=C3=B3l?= <adam.krol93@gmail.com>
Date: Sat, 21 Nov 2020 11:10:11 +0100
Subject: [PATCH] Fix ConnectTimeout during wolflink start (#43418)

---
 homeassistant/components/wolflink/__init__.py | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/homeassistant/components/wolflink/__init__.py b/homeassistant/components/wolflink/__init__.py
index d04cd7a56d4..1bfae6cb900 100644
--- a/homeassistant/components/wolflink/__init__.py
+++ b/homeassistant/components/wolflink/__init__.py
@@ -2,13 +2,14 @@
 from datetime import timedelta
 import logging
 
-from httpcore import ConnectError, ConnectTimeout
+from httpx import ConnectError, ConnectTimeout
 from wolf_smartset.token_auth import InvalidAuth
 from wolf_smartset.wolf_client import FetchFailed, WolfClient
 
 from homeassistant.config_entries import ConfigEntry
 from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
 from homeassistant.core import HomeAssistant
+from homeassistant.exceptions import ConfigEntryNotReady
 from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed
 
 from .const import (
@@ -45,7 +46,11 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry):
 
     wolf_client = WolfClient(username, password)
 
-    parameters = await fetch_parameters(wolf_client, gateway_id, device_id)
+    try:
+        parameters = await fetch_parameters(wolf_client, gateway_id, device_id)
+    except InvalidAuth:
+        _LOGGER.debug("Authentication failed")
+        return False
 
     async def async_update_data():
         """Update all stored entities for Wolf SmartSet."""
@@ -103,7 +108,7 @@ async def fetch_parameters(client: WolfClient, gateway_id: int, device_id: int):
     try:
         fetched_parameters = await client.fetch_parameters(gateway_id, device_id)
         return [param for param in fetched_parameters if param.name != "Reglertyp"]
-    except (ConnectError, ConnectTimeout) as exception:
-        raise UpdateFailed(f"Error communicating with API: {exception}") from exception
-    except InvalidAuth as exception:
-        raise UpdateFailed("Invalid authentication during update") from exception
+    except (ConnectError, ConnectTimeout, FetchFailed) as exception:
+        raise ConfigEntryNotReady(
+            f"Error communicating with API: {exception}"
+        ) from exception