From 51977c9fc29ba63799e39e32f72178758dad523e Mon Sep 17 00:00:00 2001 From: Jey Burrows <175012+jeyrb@users.noreply.github.com> Date: Wed, 25 Nov 2026 15:59:59 +0000 Subject: [PATCH] fix: register supernotify.* actions in async_setup (quality scale action-setup) The actions were registered when the config entry loaded and removed when it unloaded, so automations using them failed validation while Supernotify was starting or after a failed setup. They are now registered once from async_setup, and each looks up the loaded entry's engine when called, raising a translated ServiceValidationError when it isn't loaded. This was the one Bronze rule not met. enquire_configuration now reads the config from SupernotifyEngine.full_config. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 5 ++ custom_components/supernotify/__init__.py | 15 ++-- custom_components/supernotify/actions.py | 81 +++++++++---------- custom_components/supernotify/engine.py | 2 + .../supernotify/quality_scale.yaml | 14 ++-- .../supernotify/translations/de.json | 3 + .../supernotify/translations/en.json | 3 + .../supernotify/translations/es.json | 3 + .../supernotify/translations/fr.json | 3 + .../supernotify/translations/hi.json | 3 + .../supernotify/translations/it.json | 3 + .../supernotify/translations/ja.json | 3 + .../supernotify/translations/nl.json | 3 + .../supernotify/translations/pl.json | 3 + .../supernotify/translations/pt.json | 3 + .../supernotify/translations/zh-Hans.json | 3 + .../supernotify/test_config_entry_setup.py | 47 ++++++----- 17 files changed, 120 insertions(+), 77 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 20910004a..83a096e52 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,11 @@ [Camera Auto Notify](https://camera-autonotify.rhizomatics.org.uk/) automatic notifications from security cameras, so far supporting Frigate, OpenALPR and ANPR2MQTT. No blueprints, no automations, no YAML. +# v2.19.2 + +## 🐛 Bug fixes +- *Actions*: the `supernotify.*` actions, such as `supernotify.notify` and `supernotify.snooze`, are there from when Home Assistant starts, rather than only once Supernotify has loaded, so an automation using them no longer fails to validate while it starts, or if it failed to start. Until it has loaded, they say so with an error. Home Assistant's [action-setup](https://contributors.home-assistant.io/core/quality-scale/action-setup/) rule, needed for its Bronze quality level + # v2.19.1 ## ✨ Enhancements diff --git a/custom_components/supernotify/__init__.py b/custom_components/supernotify/__init__.py index 0334628b0..469070933 100644 --- a/custom_components/supernotify/__init__.py +++ b/custom_components/supernotify/__init__.py @@ -90,6 +90,10 @@ async def _async_reload(_call: ServiceCall) -> None: async_register_admin_service(hass, DOMAIN, SERVICE_RELOAD, _async_reload) + from .actions import async_setup_actions + + async_setup_actions(hass) + if not hass.config_entries.async_entries(DOMAIN): from homeassistant.config_entries import SOURCE_IMPORT @@ -301,7 +305,7 @@ def _async_remove_legacy_default_entities(hass: HomeAssistant) -> None: async def async_setup_entry(hass: HomeAssistant, entry: SupernotifyConfigEntry) -> bool: - from .actions import async_describe_configured_names, async_register_engine_actions + from .actions import async_describe_configured_names from .const import CONF_LLM_TOOLS, CONF_SENTENCE_COMMANDS from .engine import build_supernotify_engine from .notification import set_version @@ -328,6 +332,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: SupernotifyConfigEntry) translation_domain=DOMAIN, translation_key="setup_failed", translation_placeholders={"error": str(err)} ) from err + engine.full_config = full_config entry.runtime_data = engine # every recipient discovered gets a subentry, so all are listed and can be changed, and # switched off with `enabled` - before the update listener, as the engine has them already @@ -340,9 +345,8 @@ async def async_setup_entry(hass: HomeAssistant, entry: SupernotifyConfigEntry) # failure counter sensors (binary_sensor.py/sensor.py/switch.py) - see PLATFORMS above. await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS) - # Only once the counter sensors have restored their last values, so nothing is counted - # before then and lost - async_register_engine_actions(hass, engine, full_config) + # The supernotify.* actions only act once setup is complete and the entry is loaded, so after + # the counter sensors have restored their last values, and nothing is counted before then and lost await async_describe_configured_names(hass, engine) if entry.options.get(CONF_LLM_TOOLS, {}).get(CONF_SENTENCE_COMMANDS): @@ -384,11 +388,8 @@ async def _async_update_listener(hass: HomeAssistant, entry: SupernotifyConfigEn async def async_unload_entry(hass: HomeAssistant, entry: SupernotifyConfigEntry) -> bool: - from .actions import async_unregister_engine_actions - unload_ok = await hass.config_entries.async_unload_platforms(entry, PLATFORMS) engine: SupernotifyEngine | None = getattr(entry, "runtime_data", None) if engine is not None: engine.shutdown() - async_unregister_engine_actions(hass) return unload_ok diff --git a/custom_components/supernotify/actions.py b/custom_components/supernotify/actions.py index 37e6f7ed8..28367bb00 100644 --- a/custom_components/supernotify/actions.py +++ b/custom_components/supernotify/actions.py @@ -71,9 +71,10 @@ from .target import Target if TYPE_CHECKING: - from homeassistant.helpers.typing import ConfigType from homeassistant.util.json import JsonObjectType + from . import SupernotifyConfigEntry + _LOGGER = logging.getLogger(__name__) # what the schema fills in for fields a supernotify.notify call left out @@ -171,27 +172,15 @@ def merge_delivery_fields(data: dict[str, Any]) -> dict[str, Any]: extra=vol.ALLOW_EXTRA, ) -ACTION_NAMES: Final[tuple[str, ...]] = ( - "notify", - "enquire_archive", - "enquire_configuration", - "enquire_implicit_deliveries", - "enquire_deliveries_by_scenario", - "enquire_last_notification", - "enquire_active_scenarios", - "enquire_scenarios", - "enquire_occupancy", - "enquire_recipients", - "enquire_snoozes", - "clear_snoozes", - "snooze", - "silence", - "unsnooze", - "purge_archive", - "purge_media", - "refresh_entities", - "reset_overrides", -) + +def _loaded_engine(hass: HomeAssistant) -> SupernotifyEngine: + """The engine of the loaded config entry - there is only ever one - for an action to act on, + or a ServiceValidationError when it isn't loaded, such as while it starts or after a failed setup.""" + entries: list[SupernotifyConfigEntry] = hass.config_entries.async_loaded_entries(DOMAIN) + if not entries: + raise ServiceValidationError(translation_domain=DOMAIN, translation_key="not_loaded") + return entries[0].runtime_data + SNOOZE_MAX_MINUTES: Final[int] = 7 * 24 * 60 SNOOZE_REASON: Final[str] = "Action" @@ -235,20 +224,15 @@ def _json_safe(v: Any) -> Any: # ruff: ignore[any-type] @callback -def async_register_engine_actions(hass: HomeAssistant, engine: SupernotifyEngine, config: ConfigType) -> None: - """Register the domain-scoped supplemental/debugging/admin services. - - Shared by the legacy YAML platform (async_get_service, below) and the config-entry setup - (async_setup_entry in __init__.py), so both setup paths expose the same services. These - are DOMAIN-scoped, not per config entry, so registration is guarded against being run - twice - see ACTION_NAMES/async_unregister_engine_actions for the - matching teardown. - - enquire_configuration closes over the raw config dict rather than `service`, because - several of the fields it reports (delivery/transport/archive/dupe_check config, the full - set of configured scenarios/recipients) are either private on the registries after - initialize() or lossily reduced to derived values there - so `service` alone can't - reconstruct them. +def async_setup_actions(hass: HomeAssistant) -> None: + """Register the supernotify.* actions, once, from async_setup, so they exist whether or not the + config entry is loaded, and automations using them always validate. Each action looks up the + loaded entry's engine when called, see _loaded_engine(). + + enquire_configuration reports the raw config (SupernotifyEngine.full_config) rather than the + engine's state, because several of the fields it reports (delivery/transport/archive/dupe_check + config, the full set of configured scenarios/recipients) are either private on the registries + after initialize() or lossily reduced to derived values there. """ if hass.services.has_service(DOMAIN, "enquire_configuration"): return @@ -269,6 +253,7 @@ async def action_notify(call: ServiceCall) -> JsonObjectType | None: for it here. Requesting a response (supports_response=OPTIONAL) returns the notification's contents either way. """ + engine = _loaded_engine(hass) data = merge_delivery_fields(lift_legacy_nested_data(dict(call.data))) # extra_data is what Notification knows as `data`, and wins over any same-named key in a legacy `data` if extra_data := data.pop(ATTR_EXTRA_DATA, None): @@ -303,6 +288,7 @@ async def action_notify(call: ServiceCall) -> JsonObjectType | None: return notification.contents() if notification else None def supplemental_action_enquire_configuration(_call: ServiceCall) -> dict[str, Any]: + config = _loaded_engine(hass).full_config return redact_secrets( _json_safe({ CONF_DELIVERY: config.get(CONF_DELIVERY, {}), @@ -326,28 +312,34 @@ def supplemental_action_enquire_configuration(_call: ServiceCall) -> dict[str, A @callback def supplemental_action_refresh_entities(_call: ServiceCall) -> None: + engine = _loaded_engine(hass) # a callback, so run in the event loop - it writes entity state engine.refresh_entities() async def supplemental_action_reset_overrides(call: ServiceCall) -> dict[str, Any]: + engine = _loaded_engine(hass) # a coroutine, so run in the event loop - it writes entity state - and not a callback, as an # admin action gives no response from one kind: str | None = call.data.get(ATTR_KIND) return {"reset": engine.reset_overrides((kind,) if kind else OVERRIDE_KINDS, call.context)} def supplemental_action_enquire_implicit_deliveries(_call: ServiceCall) -> dict[str, Any]: + engine = _loaded_engine(hass) return engine.enquire_implicit_deliveries() def supplemental_action_enquire_deliveries_by_scenario(_call: ServiceCall) -> dict[str, Any]: + engine = _loaded_engine(hass) return engine.enquire_deliveries_by_scenario() def supplemental_action_enquire_last_notification(call: ServiceCall) -> dict[str, Any]: + engine = _loaded_engine(hass) diagnostics = call.data.get("diagnostics", False) if engine.last_notification is None: return {} return redact_secrets(engine.last_notification.contents(diagnostics=diagnostics)) async def supplemental_action_enquire_active_scenarios(call: ServiceCall) -> dict[str, Any]: + engine = _loaded_engine(hass) trace = call.data.get("trace", False) result: dict[str, Any] = {"scenarios": await engine.enquire_active_scenarios()} if trace: @@ -355,15 +347,19 @@ async def supplemental_action_enquire_active_scenarios(call: ServiceCall) -> dic return result def supplemental_action_enquire_scenarios(_call: ServiceCall) -> dict[str, Any]: + engine = _loaded_engine(hass) return {"scenarios": engine.enquire_scenarios()} async def supplemental_action_enquire_occupancy(_call: ServiceCall) -> dict[str, Any]: + engine = _loaded_engine(hass) return {"scenarios": await engine.enquire_occupancy()} def supplemental_action_enquire_snoozes(_call: ServiceCall) -> dict[str, Any]: + engine = _loaded_engine(hass) return {"snoozes": engine.enquire_snoozes()} def supplemental_action_clear_snoozes(_call: ServiceCall) -> dict[str, Any]: + engine = _loaded_engine(hass) return {"cleared": engine.clear_snoozes()} @callback @@ -372,6 +368,7 @@ def snooze_command(cmd: CommandType, call: ServiceCall) -> dict[str, Any]: unsnooze as a mobile action, voice sentence or the AI tool, for scripts, automations and dashboards, and open to any user, where firing the mobile action event over the API needs an admin. Run in the event loop like the others that change state.""" + engine = _loaded_engine(hass) scope = SNOOZE_SCOPES[call.data["scope"]] name: str | None = call.data.get("name") if isinstance(scope, QualifiedTargetType): @@ -402,9 +399,11 @@ def snooze_command(cmd: CommandType, call: ServiceCall) -> dict[str, Any]: return {"snoozes": engine.enquire_snoozes()} def supplemental_action_enquire_recipients(_call: ServiceCall) -> dict[str, Any]: + engine = _loaded_engine(hass) return {"recipients": engine.enquire_recipients()} async def supplemental_action_enquire_archive(call: ServiceCall) -> dict[str, Any]: + engine = _loaded_engine(hass) archive = engine.context.archive if not archive.enabled or not archive.archive_directory: raise ServiceValidationError( @@ -455,6 +454,7 @@ def at_verbosity(contents: dict[str, Any]) -> dict[str, Any]: return {"notifications": [at_verbosity(entry) for entry in entries], "count": len(entries)} async def supplemental_action_purge_archive(call: ServiceCall) -> dict[str, Any]: + engine = _loaded_engine(hass) days = call.data.get("days") if not engine.context.archive.enabled: raise ServiceValidationError( @@ -470,6 +470,7 @@ async def supplemental_action_purge_archive(call: ServiceCall) -> dict[str, Any] } async def supplemental_action_purge_media(call: ServiceCall) -> dict[str, Any]: + engine = _loaded_engine(hass) days = call.data.get("days") if not engine.context.media_storage.media_path: raise ServiceValidationError( @@ -631,11 +632,3 @@ async def async_describe_configured_names(hass: HomeAssistant, engine: Supernoti "select": {"options": scenarios, "multiple": True, "custom_value": True} } async_set_service_schema(hass, DOMAIN, "notify", notify) - - -@callback -def async_unregister_engine_actions(hass: HomeAssistant) -> None: - """Undo async_register_engine_actions.""" - for name in ACTION_NAMES: - if hass.services.has_service(DOMAIN, name): - hass.services.async_remove(DOMAIN, name) diff --git a/custom_components/supernotify/engine.py b/custom_components/supernotify/engine.py index 69ae5504f..85c4d120b 100644 --- a/custom_components/supernotify/engine.py +++ b/custom_components/supernotify/engine.py @@ -125,6 +125,8 @@ def __init__( ) -> None: """Initialize the service.""" self.last_notification: Notification | None = None + # the full configuration it was built from, for supernotify.enquire_configuration - set by async_setup_entry + self.full_config: dict[str, Any] = {} self.housekeeping: dict[str, Any] = housekeeping or {} # The counts live only in these entities, which restore their own value across restarts; # sensor.py hands them to Home Assistant once its platform loads diff --git a/custom_components/supernotify/quality_scale.yaml b/custom_components/supernotify/quality_scale.yaml index 433cef294..f04d41400 100644 --- a/custom_components/supernotify/quality_scale.yaml +++ b/custom_components/supernotify/quality_scale.yaml @@ -17,15 +17,13 @@ rules: # ================== action-setup: - status: todo + status: done comment: | - Only supernotify.reload is registered in async_setup (__init__.py). The supernotify.* - engine actions (actions.py async_register_engine_actions) are registered from - async_setup_entry and removed in async_unload_entry, so while the entry is not loaded - they don't exist and automations using them fail validation. The rule wants them - registered once in async_setup, looking up the loaded entry and raising a translated - ServiceValidationError when it isn't loaded. notify.supernotify itself is the legacy - notify service, which follows the entry. + actions.py async_setup_actions registers the supernotify.* actions once, from async_setup, + so they exist whether or not the config entry is loaded. Each looks up the loaded entry's + engine when called (_loaded_engine), raising a translated ServiceValidationError + (not_loaded) when there is none. notify.supernotify itself is the legacy notify service, + which follows the entry. appropriate-polling: status: exempt diff --git a/custom_components/supernotify/translations/de.json b/custom_components/supernotify/translations/de.json index 42dead7ac..3e85b9e7d 100644 --- a/custom_components/supernotify/translations/de.json +++ b/custom_components/supernotify/translations/de.json @@ -594,6 +594,9 @@ }, "setup_failed": { "message": "Supernotify konnte nicht gestartet werden und versucht es erneut: {error}" + }, + "not_loaded": { + "message": "Supernotify ist nicht geladen, daher kann diese Aktion erst nach dem Start ausgeführt werden" } }, "options": { diff --git a/custom_components/supernotify/translations/en.json b/custom_components/supernotify/translations/en.json index 47d35bc73..f8d0f3876 100644 --- a/custom_components/supernotify/translations/en.json +++ b/custom_components/supernotify/translations/en.json @@ -744,6 +744,9 @@ }, "setup_failed": { "message": "Supernotify failed to start, and will retry: {error}" + }, + "not_loaded": { + "message": "Supernotify isn't loaded, so this action can't run until it starts" } }, "selector": { diff --git a/custom_components/supernotify/translations/es.json b/custom_components/supernotify/translations/es.json index a5c986edd..54cd0192d 100644 --- a/custom_components/supernotify/translations/es.json +++ b/custom_components/supernotify/translations/es.json @@ -594,6 +594,9 @@ }, "setup_failed": { "message": "Supernotify no pudo iniciarse y lo volverá a intentar: {error}" + }, + "not_loaded": { + "message": "Supernotify no está cargado, así que esta acción no puede ejecutarse hasta que se inicie" } }, "options": { diff --git a/custom_components/supernotify/translations/fr.json b/custom_components/supernotify/translations/fr.json index 967234570..e364711e2 100644 --- a/custom_components/supernotify/translations/fr.json +++ b/custom_components/supernotify/translations/fr.json @@ -594,6 +594,9 @@ }, "setup_failed": { "message": "Supernotify n'a pas pu démarrer et va réessayer : {error}" + }, + "not_loaded": { + "message": "Supernotify n'est pas chargé, cette action ne peut donc pas s'exécuter avant son démarrage" } }, "options": { diff --git a/custom_components/supernotify/translations/hi.json b/custom_components/supernotify/translations/hi.json index 92bfed766..3c9f8bbca 100644 --- a/custom_components/supernotify/translations/hi.json +++ b/custom_components/supernotify/translations/hi.json @@ -594,6 +594,9 @@ }, "setup_failed": { "message": "Supernotify शुरू नहीं हो सका, और फिर से प्रयास करेगा: {error}" + }, + "not_loaded": { + "message": "Supernotify लोड नहीं है, इसलिए यह कार्रवाई उसके शुरू होने तक नहीं चल सकता" } }, "options": { diff --git a/custom_components/supernotify/translations/it.json b/custom_components/supernotify/translations/it.json index 79d00ace3..3e8bb734a 100644 --- a/custom_components/supernotify/translations/it.json +++ b/custom_components/supernotify/translations/it.json @@ -629,6 +629,9 @@ }, "setup_failed": { "message": "Supernotify non è riuscito ad avviarsi e riproverà: {error}" + }, + "not_loaded": { + "message": "Supernotify non è caricato, quindi questa azione non può essere eseguita finché non si avvia" } }, "options": { diff --git a/custom_components/supernotify/translations/ja.json b/custom_components/supernotify/translations/ja.json index c22b64738..94fb0c1cb 100644 --- a/custom_components/supernotify/translations/ja.json +++ b/custom_components/supernotify/translations/ja.json @@ -594,6 +594,9 @@ }, "setup_failed": { "message": "Supernotify の起動に失敗しました。再試行します: {error}" + }, + "not_loaded": { + "message": "Supernotify が読み込まれていないため、起動するまでこのアクションは実行できません" } }, "options": { diff --git a/custom_components/supernotify/translations/nl.json b/custom_components/supernotify/translations/nl.json index 1cd3647c2..3c96c45b9 100644 --- a/custom_components/supernotify/translations/nl.json +++ b/custom_components/supernotify/translations/nl.json @@ -594,6 +594,9 @@ }, "setup_failed": { "message": "Supernotify kon niet starten en probeert het opnieuw: {error}" + }, + "not_loaded": { + "message": "Supernotify is niet geladen, dus deze actie kan pas worden uitgevoerd als het is gestart" } }, "options": { diff --git a/custom_components/supernotify/translations/pl.json b/custom_components/supernotify/translations/pl.json index 84a2d827f..a1fe1c6ba 100644 --- a/custom_components/supernotify/translations/pl.json +++ b/custom_components/supernotify/translations/pl.json @@ -594,6 +594,9 @@ }, "setup_failed": { "message": "Nie udało się uruchomić Supernotify, nastąpi ponowna próba: {error}" + }, + "not_loaded": { + "message": "Supernotify nie jest załadowany, więc ta akcja nie może zostać wykonana, dopóki się nie uruchomi" } }, "options": { diff --git a/custom_components/supernotify/translations/pt.json b/custom_components/supernotify/translations/pt.json index b270a1c69..f3498ae3f 100644 --- a/custom_components/supernotify/translations/pt.json +++ b/custom_components/supernotify/translations/pt.json @@ -594,6 +594,9 @@ }, "setup_failed": { "message": "O Supernotify não conseguiu iniciar e vai tentar novamente: {error}" + }, + "not_loaded": { + "message": "O Supernotify não está carregado, por isso esta ação não pode ser executada até que seja iniciado" } }, "options": { diff --git a/custom_components/supernotify/translations/zh-Hans.json b/custom_components/supernotify/translations/zh-Hans.json index 8d2ec3354..60dea8176 100644 --- a/custom_components/supernotify/translations/zh-Hans.json +++ b/custom_components/supernotify/translations/zh-Hans.json @@ -594,6 +594,9 @@ }, "setup_failed": { "message": "Supernotify 启动失败,将重试:{error}" + }, + "not_loaded": { + "message": "Supernotify 尚未加载,因此在其启动之前无法运行此操作" } }, "options": { diff --git a/tests/components/supernotify/test_config_entry_setup.py b/tests/components/supernotify/test_config_entry_setup.py index 3e606734b..ee3d0be34 100644 --- a/tests/components/supernotify/test_config_entry_setup.py +++ b/tests/components/supernotify/test_config_entry_setup.py @@ -194,17 +194,36 @@ async def test_purge_media_removes_old_files(hass: HomeAssistant, tmp_path: Path assert new_file.exists() -async def test_unload_entry_removes_engine_actions(hass: HomeAssistant) -> None: +async def test_actions_registered_before_entry_loaded(hass: HomeAssistant) -> None: + """The supernotify.* actions are registered by async_setup, not the config entry, so that an + automation using them validates while the entry isn't loaded (Quality Scale action-setup)""" + entry = MockConfigEntry(domain=DOMAIN, data={}, options={}, disabled_by=ConfigEntryDisabler.USER) + entry.add_to_hass(hass) + assert await async_setup_component(hass, DOMAIN, {}) + await hass.async_block_till_done() + assert entry.state is ConfigEntryState.NOT_LOADED + + assert hass.services.has_service(DOMAIN, "notify") + assert hass.services.has_service(DOMAIN, "enquire_scenarios") + with pytest.raises(ServiceValidationError) as raised: + await hass.services.async_call(DOMAIN, "enquire_scenarios", blocking=True, return_response=True) + assert raised.value.translation_key == "not_loaded" + + +async def test_unload_entry_keeps_actions_unavailable(hass: HomeAssistant) -> None: entry = MockConfigEntry(domain=DOMAIN, data={}, options={}) entry.add_to_hass(hass) assert await hass.config_entries.async_setup(entry.entry_id) await hass.async_block_till_done() - assert hass.services.has_service(DOMAIN, "enquire_configuration") + assert await hass.services.async_call(DOMAIN, "enquire_scenarios", blocking=True, return_response=True) assert await hass.config_entries.async_unload(entry.entry_id) await hass.async_block_till_done() - assert not hass.services.has_service(DOMAIN, "enquire_configuration") + assert hass.services.has_service(DOMAIN, "enquire_scenarios") + with pytest.raises(ServiceValidationError) as raised: + await hass.services.async_call(DOMAIN, "enquire_scenarios", blocking=True, return_response=True) + assert raised.value.translation_key == "not_loaded" async def test_options_update_reloads_entry_with_new_archive_path(hass: HomeAssistant) -> None: @@ -555,19 +574,6 @@ async def test_notify_action_rejects_mapping_target_with_invalid_value(hass: Hom assert entry.runtime_data.last_notification is None -async def test_unload_entry_removes_notify_action(hass: HomeAssistant) -> None: - entry = MockConfigEntry(domain=DOMAIN, data={}, options={}) - entry.add_to_hass(hass) - assert await hass.config_entries.async_setup(entry.entry_id) - await hass.async_block_till_done() - assert hass.services.has_service(DOMAIN, "notify") - - assert await hass.config_entries.async_unload(entry.entry_id) - await hass.async_block_till_done() - - assert not hass.services.has_service(DOMAIN, "notify") - - async def test_disable_then_enable_entry_rewires_notify_service(hass: HomeAssistant) -> None: """Disabling from the UI unloads the entry same as any other unload (async_set_disabled_by -> async_reload -> async_unload_entry), then re-enabling sets it up again. Both @@ -584,7 +590,8 @@ async def test_disable_then_enable_entry_rewires_notify_service(hass: HomeAssist await hass.async_block_till_done() assert entry.state is ConfigEntryState.NOT_LOADED assert not hass.services.has_service("notify", "supernotify") - assert not hass.services.has_service(DOMAIN, "enquire_configuration") + # registered by async_setup, so still there, but with nothing to act on + assert hass.services.has_service(DOMAIN, "enquire_configuration") await hass.config_entries.async_set_disabled_by(entry.entry_id, None) await hass.async_block_till_done() @@ -613,7 +620,8 @@ async def test_remove_then_readd_entry_recreates_notify_service(hass: HomeAssist await hass.config_entries.async_remove(entry.entry_id) await hass.async_block_till_done() assert not hass.services.has_service("notify", "supernotify") - assert not hass.services.has_service(DOMAIN, "enquire_configuration") + # registered by async_setup, so still there, but with nothing to act on + assert hass.services.has_service(DOMAIN, "enquire_configuration") new_entry = MockConfigEntry(domain=DOMAIN, data={}, options={}) new_entry.add_to_hass(hass) @@ -625,6 +633,9 @@ async def test_remove_then_readd_entry_recreates_notify_service(hass: HomeAssist await hass.async_block_till_done() assert new_entry.runtime_data.last_notification is not None assert new_entry.runtime_data.last_notification.message == "post re-add check" + # and the supernotify.* actions act on the new entry's engine + await hass.services.async_call(DOMAIN, "notify", {"message": "action re-add check"}, blocking=True) + assert new_entry.runtime_data.last_notification.message == "action re-add check" async def test_ha_shutdown_unsubscribes_engine_listeners(hass: HomeAssistant) -> None: