Cancel timer on enphase_envoy config entry unload (#111406)
* lingeringtimer * Add async_cleanup to enphase_envoy_coordinator and call from unload_entry
This commit is contained in:
parent
c9ff618ef0
commit
bbaa0c16cc
3 changed files with 9 additions and 1 deletions
|
@ -46,6 +46,8 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
|
|
||||||
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
"""Unload a config entry."""
|
"""Unload a config entry."""
|
||||||
|
coordinator = hass.data[DOMAIN][entry.entry_id]
|
||||||
|
await coordinator.async_cleanup()
|
||||||
unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
|
||||||
if unload_ok:
|
if unload_ok:
|
||||||
hass.data[DOMAIN].pop(entry.entry_id)
|
hass.data[DOMAIN].pop(entry.entry_id)
|
||||||
|
|
|
@ -159,3 +159,9 @@ class EnphaseUpdateCoordinator(DataUpdateCoordinator[dict[str, Any]]):
|
||||||
return envoy_data.raw
|
return envoy_data.raw
|
||||||
|
|
||||||
raise RuntimeError("Unreachable code in _async_update_data") # pragma: no cover
|
raise RuntimeError("Unreachable code in _async_update_data") # pragma: no cover
|
||||||
|
|
||||||
|
async def async_cleanup(self) -> None:
|
||||||
|
"""Cleanup coordinator."""
|
||||||
|
if self._cancel_token_refresh:
|
||||||
|
self._cancel_token_refresh()
|
||||||
|
self._cancel_token_refresh = None
|
||||||
|
|
|
@ -343,7 +343,7 @@ def mock_envoy_fixture(
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(name="setup_enphase_envoy")
|
@pytest.fixture(name="setup_enphase_envoy")
|
||||||
async def setup_enphase_envoy_fixture(hass, config, mock_envoy):
|
async def setup_enphase_envoy_fixture(hass: HomeAssistant, config, mock_envoy):
|
||||||
"""Define a fixture to set up Enphase Envoy."""
|
"""Define a fixture to set up Enphase Envoy."""
|
||||||
with (
|
with (
|
||||||
patch(
|
patch(
|
||||||
|
|
Loading…
Add table
Reference in a new issue