From 4f1ea142126459c50e87fb42008de50c0265f194 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Tue, 4 Jul 2023 09:54:32 -0500 Subject: [PATCH 1/3] Fix reload in cert_expiry Switches async_listen_once to async_listen since its wrapped in entry.async_on_unload and the listener will fail to be removed on reload once the started event has fired because it was a one time listener --- homeassistant/components/cert_expiry/__init__.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/homeassistant/components/cert_expiry/__init__.py b/homeassistant/components/cert_expiry/__init__.py index 5f6152b7bc79be..0ac569f58c25c9 100644 --- a/homeassistant/components/cert_expiry/__init__.py +++ b/homeassistant/components/cert_expiry/__init__.py @@ -46,9 +46,7 @@ async def async_finish_startup(_): await async_finish_startup(None) else: entry.async_on_unload( - hass.bus.async_listen_once( - EVENT_HOMEASSISTANT_STARTED, async_finish_startup - ) + hass.bus.async_listen(EVENT_HOMEASSISTANT_STARTED, async_finish_startup) ) return True From 4558f1462614f13b4ec447ed26a79bd5c5c381ac Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Tue, 4 Jul 2023 12:03:20 -0500 Subject: [PATCH 2/3] async_at_started --- homeassistant/components/cert_expiry/__init__.py | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/homeassistant/components/cert_expiry/__init__.py b/homeassistant/components/cert_expiry/__init__.py index 0ac569f58c25c9..d99bf86ab32647 100644 --- a/homeassistant/components/cert_expiry/__init__.py +++ b/homeassistant/components/cert_expiry/__init__.py @@ -8,10 +8,10 @@ from homeassistant.const import ( CONF_HOST, CONF_PORT, - EVENT_HOMEASSISTANT_STARTED, Platform, ) -from homeassistant.core import CoreState, HomeAssistant +from homeassistant.core import HomeAssistant +from homeassistant.helpers.start import async_at_started from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed from .const import DEFAULT_PORT, DOMAIN @@ -42,13 +42,7 @@ async def async_finish_startup(_): await coordinator.async_refresh() await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS) - if hass.state == CoreState.running: - await async_finish_startup(None) - else: - entry.async_on_unload( - hass.bus.async_listen(EVENT_HOMEASSISTANT_STARTED, async_finish_startup) - ) - + async_at_started(hass, async_finish_startup) return True From 2d73acf373471fee7ba6ebf620678afc5dfe3591 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Tue, 4 Jul 2023 12:03:28 -0500 Subject: [PATCH 3/3] async_at_started --- homeassistant/components/cert_expiry/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/cert_expiry/__init__.py b/homeassistant/components/cert_expiry/__init__.py index d99bf86ab32647..4fc89bc918b790 100644 --- a/homeassistant/components/cert_expiry/__init__.py +++ b/homeassistant/components/cert_expiry/__init__.py @@ -38,11 +38,11 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool: if entry.unique_id is None: hass.config_entries.async_update_entry(entry, unique_id=f"{host}:{port}") - async def async_finish_startup(_): + async def _async_finish_startup(_): await coordinator.async_refresh() await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS) - async_at_started(hass, async_finish_startup) + async_at_started(hass, _async_finish_startup) return True