Fix reload not triggered on DisabledError in HomeWizard (#128636)
* Fix reload not triggered on DisabledError in HomeWizard * Update homeassistant/components/homewizard/coordinator.py Co-authored-by: epenet <6771947+epenet@users.noreply.github.com> * Use helper and fix merge issue * Add test to detect reload on DisabledError * Wait until next update instead of a direct call to update * Add doc why we reload --------- Co-authored-by: epenet <6771947+epenet@users.noreply.github.com>
This commit is contained in:
parent
94506c3c90
commit
1f8fd52103
2 changed files with 40 additions and 2 deletions
|
@ -74,7 +74,8 @@ class HWEnergyDeviceUpdateCoordinator(DataUpdateCoordinator[DeviceResponseEntry]
|
||||||
|
|
||||||
# Do not reload when performing first refresh
|
# Do not reload when performing first refresh
|
||||||
if self.data is not None:
|
if self.data is not None:
|
||||||
await self.hass.config_entries.async_reload(
|
# Reload config entry to let init flow handle retrying and trigger repair flow
|
||||||
|
self.hass.config_entries.async_schedule_reload(
|
||||||
self.config_entry.entry_id
|
self.config_entry.entry_id
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
"""Tests for the homewizard component."""
|
"""Tests for the homewizard component."""
|
||||||
|
|
||||||
|
from datetime import timedelta
|
||||||
from unittest.mock import MagicMock
|
from unittest.mock import MagicMock
|
||||||
|
|
||||||
|
from freezegun.api import FrozenDateTimeFactory
|
||||||
from homewizard_energy.errors import DisabledError
|
from homewizard_energy.errors import DisabledError
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
@ -9,7 +11,7 @@ from homeassistant.components.homewizard.const import DOMAIN
|
||||||
from homeassistant.config_entries import SOURCE_REAUTH, ConfigEntryState
|
from homeassistant.config_entries import SOURCE_REAUTH, ConfigEntryState
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
|
|
||||||
from tests.common import MockConfigEntry
|
from tests.common import MockConfigEntry, async_fire_time_changed
|
||||||
|
|
||||||
|
|
||||||
async def test_load_unload(
|
async def test_load_unload(
|
||||||
|
@ -93,3 +95,38 @@ async def test_load_removes_reauth_flow(
|
||||||
# Flow should be removed
|
# Flow should be removed
|
||||||
flows = hass.config_entries.flow.async_progress_by_handler(DOMAIN)
|
flows = hass.config_entries.flow.async_progress_by_handler(DOMAIN)
|
||||||
assert len(flows) == 0
|
assert len(flows) == 0
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.usefixtures("mock_homewizardenergy")
|
||||||
|
async def test_disablederror_reloads_integration(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
mock_config_entry: MockConfigEntry,
|
||||||
|
mock_homewizardenergy: MagicMock,
|
||||||
|
freezer: FrozenDateTimeFactory,
|
||||||
|
) -> None:
|
||||||
|
"""Test DisabledError reloads integration."""
|
||||||
|
mock_config_entry.add_to_hass(hass)
|
||||||
|
await hass.config_entries.async_setup(mock_config_entry.entry_id)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
# Make sure current state is loaded and not reauth flow is active
|
||||||
|
assert mock_config_entry.state is ConfigEntryState.LOADED
|
||||||
|
flows = hass.config_entries.flow.async_progress_by_handler(DOMAIN)
|
||||||
|
assert len(flows) == 0
|
||||||
|
|
||||||
|
# Simulate DisabledError and wait for next update
|
||||||
|
mock_homewizardenergy.device.side_effect = DisabledError()
|
||||||
|
|
||||||
|
freezer.tick(timedelta(seconds=5))
|
||||||
|
async_fire_time_changed(hass)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
# State should be setup retry and reauth flow should be active
|
||||||
|
assert mock_config_entry.state is ConfigEntryState.SETUP_RETRY
|
||||||
|
|
||||||
|
flows = hass.config_entries.flow.async_progress_by_handler(DOMAIN)
|
||||||
|
assert len(flows) == 1
|
||||||
|
|
||||||
|
flow = flows[0]
|
||||||
|
assert flow.get("step_id") == "reauth_confirm"
|
||||||
|
assert flow.get("handler") == DOMAIN
|
||||||
|
|
Loading…
Add table
Reference in a new issue