| 
16 | 16 |     label_registry as lr,  | 
17 | 17 | )  | 
18 | 18 | from homeassistant.helpers.service import _load_services_file, async_set_service_schema  | 
19 |  | -from homeassistant.loader import async_get_integration  | 
 | 19 | +from homeassistant.loader import IntegrationNotFound, async_get_integration  | 
20 | 20 | 
 
  | 
21 | 21 | from ....services import AbstractSpookService  | 
22 | 22 | 
 
  | 
@@ -63,7 +63,7 @@ async def _on_started_set_schema(self, _event: Event) -> None:  | 
63 | 63 |             integration = None  | 
64 | 64 |             try:  | 
65 | 65 |                 integration = await async_get_integration(self.hass, d)  | 
66 |  | -            except (LookupError, ValueError, RuntimeError):  # pragma: no cover  | 
 | 66 | +            except IntegrationNotFound:  # pragma: no cover  | 
67 | 67 |                 integration = None  | 
68 | 68 |             if integration is not None and getattr(integration, "name", None):  | 
69 | 69 |                 label = integration.name  | 
@@ -123,13 +123,10 @@ def _collect_live_integration_domains(self) -> set[str]:  | 
123 | 123 |             platform = getattr(entry, "platform", None)  | 
124 | 124 |             if isinstance(platform, str) and platform:  | 
125 | 125 |                 domains.add(platform)  | 
126 |  | -        if hasattr(self.hass, "config_entries") and hasattr(  | 
127 |  | -            self.hass.config_entries, "async_entries"  | 
128 |  | -        ):  | 
129 |  | -            for cfg in self.hass.config_entries.async_entries():  # type: ignore[attr-defined]  | 
130 |  | -                dom = getattr(cfg, "domain", None)  | 
131 |  | -                if isinstance(dom, str) and dom:  | 
132 |  | -                    domains.add(dom)  | 
 | 126 | +        for cfg in self.hass.config_entries.async_entries():  | 
 | 127 | +            dom = getattr(cfg, "domain", None)  | 
 | 128 | +            if isinstance(dom, str) and dom:  | 
 | 129 | +                domains.add(dom)  | 
133 | 130 |         return domains  | 
134 | 131 | 
 
  | 
135 | 132 |     def _inject_integration_options(  | 
@@ -333,10 +330,9 @@ def _get_integration_name(self, entity_entry: er.RegistryEntry) -> str | None:  | 
333 | 330 |         if not entity_entry.config_entry_id:  | 
334 | 331 |             return None  | 
335 | 332 | 
 
  | 
336 |  | -        config_entries = self.hass.config_entries  | 
337 |  | -        config_entry = None  | 
338 |  | -        if hasattr(config_entries, "async_get_entry"):  | 
339 |  | -            config_entry = config_entries.async_get_entry(entity_entry.config_entry_id)  | 
 | 333 | +        config_entry = self.hass.config_entries.async_get_entry(  | 
 | 334 | +            entity_entry.config_entry_id  | 
 | 335 | +        )  | 
340 | 336 | 
 
  | 
341 | 337 |         return config_entry.title if config_entry else None  | 
342 | 338 | 
 
  | 
@@ -538,14 +534,13 @@ def _format_response(  | 
538 | 534 |         self, matching_entities: list[str | dict[str, Any]], limit: int  | 
539 | 535 |     ) -> ServiceResponse:  | 
540 | 536 |         """Format the final service response."""  | 
541 |  | -        if matching_entities and isinstance(matching_entities[0], dict):  | 
542 |  | -            dict_entities = [e for e in matching_entities if isinstance(e, dict)]  | 
543 |  | -            dict_entities.sort(key=lambda entity: str(entity.get("entity_id", "")))  | 
544 |  | -            matching_entities[:] = dict_entities  | 
545 |  | -        else:  | 
546 |  | -            string_entities = [e for e in matching_entities if isinstance(e, str)]  | 
547 |  | -            string_entities.sort()  | 
548 |  | -            matching_entities[:] = string_entities  | 
 | 537 | +        if matching_entities:  | 
 | 538 | +            if isinstance(matching_entities[0], dict):  | 
 | 539 | +                matching_entities.sort(  | 
 | 540 | +                    key=lambda entity: str(entity.get("entity_id", ""))  | 
 | 541 | +                )  | 
 | 542 | +            else:  | 
 | 543 | +                matching_entities.sort()  | 
549 | 544 | 
 
  | 
550 | 545 |         # Apply limit post-sort for deterministic results  | 
551 | 546 |         if limit is not None:  | 
 | 
0 commit comments