Repository: home-assistant/core
File: homeassistant/config_entries.py (Python)

Code before:
                        for domain, keys in entry["discovery_keys"].items()
                    }
                ),
                domain=entry["domain"],
                entry_id=entry_id,
                minor_version=entry["minor_version"],
                modified_at=datetime.fromisoformat(entry["modified_at"]),
                options=entry["options"],
                pref_disable_new_entities=entry["pref_disable_new_entities"],
                pref_disable_polling=entry["pref_disable_polling"],
                source=entry["source"],
                subentries_data=entry["subentries"],
                title=entry["title"],
                unique_id=entry["unique_id"],
                version=entry["version"],
            )
            entries[entry_id] = config_entry

        self._entries = entries
        self.async_update_issues()

        self.hass.bus.async_listen_once(
            EVENT_HOMEASSISTANT_STARTED, self._async_scan_orphan_ignored_entries
        )

    async def _async_scan_orphan_ignored_entries(self, event: Event) -> None:
        """Scan for ignored entries that can be removed.

        Orphaned ignored entries are entries that are in ignored state
        for integrations that are no longer available.
        """
        remove_candidates = [
            entry
            for entry in self.async_entries(
                include_ignore=True,
                include_disabled=False,
            )
            if entry.source == SOURCE_IGNORE
        ]

        if not remove_candidates:
            return

        for entry in remove_candidates:
            try:
                await loader.async_get_integration(self.hass, entry.domain)
            except loader.IntegrationNotFound:
                _LOGGER.info(
                    "Integration for ignored config entry %s not found. Creating repair issue",
                    entry,
                )

Review comment (refactor):
Event is abstract so we can add the event data type for the event in the type annotation.


```suggestion
    async def _async_scan_orphan_ignored_entries(self, event: Event[NoEventData]) -> None:
```

Code after:
        """Clean up after an entry."""
        entry_id = entry.entry_id

        dev_reg = dr.async_get(self.hass)
        ent_reg = er.async_get(self.hass)

        dev_reg.async_clear_config_entry(entry_id)
        ent_reg.async_clear_config_entry(entry_id)

        # If the configuration entry is removed during reauth, it should
        # abort any reauth flow that is active for the removed entry and
        # linked issues.
        _abort_reauth_flows(self.hass, entry.domain, entry_id)

        self._async_dispatch(ConfigEntryChange.REMOVED, entry)

    @callback
    def _async_shutdown(self, event: Event) -> None:
        """Call when Home Assistant is stopping."""
        for entry in self._entries.values():
            entry.async_shutdown()
        self.flow.async_shutdown()

    async def async_initialize(self) -> None:
        """Initialize config entry config."""
        config = await self._store.async_load()

        self.hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, self._async_shutdown)

        if config is None:
            self._entries = ConfigEntryItems(self.hass)
            return

        entries: ConfigEntryItems = ConfigEntryItems(self.hass)
        for entry in config["entries"]:
            entry_id = entry["entry_id"]

            config_entry = ConfigEntry(
                created_at=datetime.fromisoformat(entry["created_at"]),
                data=entry["data"],
                disabled_by=try_parse_enum(ConfigEntryDisabler, entry["disabled_by"]),
                discovery_keys=MappingProxyType(
                    {
                        domain: tuple(DiscoveryKey.from_json_dict(key) for key in keys)
                        for domain, keys in entry["discovery_keys"].items()
                    }
                ),
                domain=entry["domain"],
                entry_id=entry_id,
                minor_version=entry["minor_version"],
                modified_at=datetime.fromisoformat(entry["modified_at"]),