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:
Arie Catsman 2024-04-24 16:33:14 +02:00 committed by GitHub
parent c9ff618ef0
commit bbaa0c16cc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 9 additions and 1 deletions

View File

@ -46,6 +46,8 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""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)
if unload_ok:
hass.data[DOMAIN].pop(entry.entry_id)

View File

@ -159,3 +159,9 @@ class EnphaseUpdateCoordinator(DataUpdateCoordinator[dict[str, Any]]):
return envoy_data.raw
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

View File

@ -343,7 +343,7 @@ def mock_envoy_fixture(
@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."""
with (
patch(