Handle more pushover exceptions during setup (#115802)
Co-authored-by: Franck Nijhof <frenck@frenck.nl>
This commit is contained in:
parent
959298d121
commit
6937aed9fe
2 changed files with 19 additions and 1 deletions
|
@ -3,6 +3,8 @@
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from pushover_complete import BadAPIRequestError, PushoverAPI
|
from pushover_complete import BadAPIRequestError, PushoverAPI
|
||||||
|
from requests.exceptions import RequestException
|
||||||
|
from urllib3.exceptions import HTTPError
|
||||||
|
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import CONF_API_KEY, CONF_NAME, Platform
|
from homeassistant.const import CONF_API_KEY, CONF_NAME, Platform
|
||||||
|
@ -38,7 +40,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
pushover_api.validate, entry.data[CONF_USER_KEY]
|
pushover_api.validate, entry.data[CONF_USER_KEY]
|
||||||
)
|
)
|
||||||
|
|
||||||
except (BadAPIRequestError, ValueError) as err:
|
except (BadAPIRequestError, ValueError, RequestException, HTTPError) as err:
|
||||||
if "application token is invalid" in str(err):
|
if "application token is invalid" in str(err):
|
||||||
raise ConfigEntryAuthFailed(err) from err
|
raise ConfigEntryAuthFailed(err) from err
|
||||||
raise ConfigEntryNotReady(err) from err
|
raise ConfigEntryNotReady(err) from err
|
||||||
|
|
|
@ -5,6 +5,7 @@ from unittest.mock import MagicMock, patch
|
||||||
from pushover_complete import BadAPIRequestError
|
from pushover_complete import BadAPIRequestError
|
||||||
import pytest
|
import pytest
|
||||||
import requests_mock
|
import requests_mock
|
||||||
|
from urllib3.exceptions import MaxRetryError
|
||||||
|
|
||||||
from homeassistant.components.pushover.const import DOMAIN
|
from homeassistant.components.pushover.const import DOMAIN
|
||||||
from homeassistant.config_entries import ConfigEntryState
|
from homeassistant.config_entries import ConfigEntryState
|
||||||
|
@ -93,3 +94,18 @@ async def test_async_setup_entry_failed_json_error(
|
||||||
await hass.config_entries.async_setup(entry.entry_id)
|
await hass.config_entries.async_setup(entry.entry_id)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
assert entry.state is ConfigEntryState.SETUP_RETRY
|
assert entry.state is ConfigEntryState.SETUP_RETRY
|
||||||
|
|
||||||
|
|
||||||
|
async def test_async_setup_entry_failed_urrlib3_error(
|
||||||
|
hass: HomeAssistant, mock_pushover: MagicMock
|
||||||
|
) -> None:
|
||||||
|
"""Test pushover failed setup due to conn error."""
|
||||||
|
entry = MockConfigEntry(
|
||||||
|
domain=DOMAIN,
|
||||||
|
data=MOCK_CONFIG,
|
||||||
|
)
|
||||||
|
entry.add_to_hass(hass)
|
||||||
|
mock_pushover.side_effect = MaxRetryError(MagicMock(), MagicMock())
|
||||||
|
await hass.config_entries.async_setup(entry.entry_id)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
assert entry.state is ConfigEntryState.SETUP_RETRY
|
||||||
|
|
Loading…
Add table
Reference in a new issue