1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-24 21:06:19 +00:00

Improve HomeWizard request issue reporting (#82366)

* Trigger reauth flow when HomeWizard API was disabled

* Add tests for reauth flow

* Fix typo in test

* Add parallel updates constant

* Improve error message when device in unreachable during config

* Set quality scale

* Remove quality scale

* Throw error instead of abort when setup fails

* Adjust test for new setup behaviour

* Trigger reauth flow when API is disabled and continue retrying

* Reload entry and raise AuthFailed during init

* Abort running config flow

* Listen for coordinator updates to trigger reload

* Use build-in backoff system

* Fix failing test

* Test reauth flow is active after disable-api init

* Test reauth flow removal
This commit is contained in:
Duco Sebel
2022-12-16 16:53:54 +01:00
committed by GitHub
parent f5a8ce4aca
commit b41d0be952
8 changed files with 243 additions and 66 deletions

View File

@@ -6,7 +6,7 @@ from homewizard_energy.errors import DisabledError, HomeWizardEnergyException
from homeassistant import config_entries
from homeassistant.components.homewizard.const import DOMAIN
from homeassistant.config_entries import ConfigEntryState
from homeassistant.config_entries import SOURCE_REAUTH, ConfigEntryState
from homeassistant.const import CONF_IP_ADDRESS
from homeassistant.helpers import entity_registry as er
@@ -187,6 +187,52 @@ async def test_load_detect_api_disabled(aioclient_mock, hass):
assert entry.state is ConfigEntryState.SETUP_RETRY
flows = hass.config_entries.flow.async_progress()
assert len(flows) == 1
flow = flows[0]
assert flow.get("step_id") == "reauth_confirm"
assert flow.get("handler") == DOMAIN
assert "context" in flow
assert flow["context"].get("source") == SOURCE_REAUTH
assert flow["context"].get("entry_id") == entry.entry_id
async def test_load_removes_reauth_flow(aioclient_mock, hass):
"""Test setup removes reauth flow when API is enabled."""
device = get_mock_device()
entry = MockConfigEntry(
domain=DOMAIN,
data={CONF_IP_ADDRESS: "1.1.1.1"},
unique_id=DOMAIN,
)
entry.add_to_hass(hass)
# Add reauth flow from 'previously' failed init
entry.async_start_reauth(hass)
await hass.async_block_till_done()
flows = hass.config_entries.flow.async_progress_by_handler(DOMAIN)
assert len(flows) == 1
# Initialize entry
with patch(
"homeassistant.components.homewizard.coordinator.HomeWizardEnergy",
return_value=device,
):
await hass.config_entries.async_setup(entry.entry_id)
await hass.async_block_till_done()
assert entry.state is ConfigEntryState.LOADED
# Flow should be removed
flows = hass.config_entries.flow.async_progress_by_handler(DOMAIN)
assert len(flows) == 0
async def test_load_handles_homewizardenergy_exception(aioclient_mock, hass):
"""Test setup handles exception from API."""