-
-
Notifications
You must be signed in to change notification settings - Fork 28.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cancel timer on enphase_envoy config entry unload #111406
Conversation
Hey there @bdraco, @cgarwood, @dgomes, @joostlek, mind taking a look at this pull request as it has been labeled with an integration ( Code owner commandsCode owners of
|
I just realized the timer is marked |
Tested with a cleanup method added to coordinator which executes the self._cancel_token_refresh callback if existing and called from __init__.async_unload_entry. That solves the lingering timer warnings. No need anymore for the patch of this first attempt. Haven't committed it yet as it still may be hidden the potential structural problem in the test tooling you refer too. It is called on reload as well, not on system restart. __init__ 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() coordinator,py async def async_cleanup(self) -> None:
"""Cleanup coordinator."""
if self._cancel_token_refresh:
self._cancel_token_refresh()
self._cancel_token_refresh = None |
Implemented envoy coordinator.async_cleanup called from async_uncload_entry to cancel token check timer and reverted the envoy_mock change. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks @catsmanac 👍
Suggested cleanup diff --git a/homeassistant/components/enphase_envoy/__init__.py b/homeassistant/components/enphase_envoy/__init__.py
index 2cdba43453e..322f909437a 100644
--- a/homeassistant/components/enphase_envoy/__init__.py
+++ b/homeassistant/components/enphase_envoy/__init__.py
@@ -46,8 +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()
+ coordinator: EnphaseUpdateCoordinator = hass.data[DOMAIN][entry.entry_id]
+ coordinator.async_cancel_token_refresh()
unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
if unload_ok:
hass.data[DOMAIN].pop(entry.entry_id)
diff --git a/homeassistant/components/enphase_envoy/coordinator.py b/homeassistant/components/enphase_envoy/coordinator.py
index c0852fca807..04f93098ad9 100644
--- a/homeassistant/components/enphase_envoy/coordinator.py
+++ b/homeassistant/components/enphase_envoy/coordinator.py
@@ -83,9 +83,7 @@ class EnphaseUpdateCoordinator(DataUpdateCoordinator[dict[str, Any]]):
def _async_mark_setup_complete(self) -> None:
"""Mark setup as complete and setup token refresh if needed."""
self._setup_complete = True
- if self._cancel_token_refresh:
- self._cancel_token_refresh()
- self._cancel_token_refresh = None
+ self.async_cancel_token_refresh()
if not isinstance(self.envoy.auth, EnvoyTokenAuth):
return
self._cancel_token_refresh = async_track_time_interval(
@@ -160,8 +158,9 @@ class EnphaseUpdateCoordinator(DataUpdateCoordinator[dict[str, Any]]):
raise RuntimeError("Unreachable code in _async_update_data") # pragma: no cover
- async def async_cleanup(self) -> None:
- """Cleanup coordinator."""
+ @callback
+ def async_cancel_token_refresh(self) -> None:
+ """Cancel token refresh."""
if self._cancel_token_refresh:
self._cancel_token_refresh()
self._cancel_token_refresh = None
|
Proposed change
Cancel timer on enphase_envoy config entry unload
Type of change
Additional information
Checklist
ruff format homeassistant tests
)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest
.requirements_all.txt
.Updated by running
python3 -m script.gen_requirements_all
..coveragerc
.To help with the load of incoming pull requests: