Fix ConnectTimeout during wolflink start (#43418)

This commit is contained in:
Adam Król 2020-11-21 11:10:11 +01:00 committed by GitHub
parent 45618f8054
commit cccd4d734c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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