mirror of
https://github.com/home-assistant/core.git
synced 2025-07-09 14:27:07 +00:00
Reduce duplicate code in enphase_envoy (#116107)
Also converts a coro to a callback function since nothing was being awaited
This commit is contained in:
parent
169b9b0bfe
commit
e47e62cbbf
@ -46,8 +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]
|
coordinator: EnphaseUpdateCoordinator = hass.data[DOMAIN][entry.entry_id]
|
||||||
await coordinator.async_cleanup()
|
coordinator.async_cancel_token_refresh()
|
||||||
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)
|
||||||
|
@ -83,9 +83,7 @@ class EnphaseUpdateCoordinator(DataUpdateCoordinator[dict[str, Any]]):
|
|||||||
def _async_mark_setup_complete(self) -> None:
|
def _async_mark_setup_complete(self) -> None:
|
||||||
"""Mark setup as complete and setup token refresh if needed."""
|
"""Mark setup as complete and setup token refresh if needed."""
|
||||||
self._setup_complete = True
|
self._setup_complete = True
|
||||||
if self._cancel_token_refresh:
|
self.async_cancel_token_refresh()
|
||||||
self._cancel_token_refresh()
|
|
||||||
self._cancel_token_refresh = None
|
|
||||||
if not isinstance(self.envoy.auth, EnvoyTokenAuth):
|
if not isinstance(self.envoy.auth, EnvoyTokenAuth):
|
||||||
return
|
return
|
||||||
self._cancel_token_refresh = async_track_time_interval(
|
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
|
raise RuntimeError("Unreachable code in _async_update_data") # pragma: no cover
|
||||||
|
|
||||||
async def async_cleanup(self) -> None:
|
@callback
|
||||||
"""Cleanup coordinator."""
|
def async_cancel_token_refresh(self) -> None:
|
||||||
|
"""Cancel token refresh."""
|
||||||
if self._cancel_token_refresh:
|
if self._cancel_token_refresh:
|
||||||
self._cancel_token_refresh()
|
self._cancel_token_refresh()
|
||||||
self._cancel_token_refresh = None
|
self._cancel_token_refresh = None
|
||||||
|
Loading…
x
Reference in New Issue
Block a user