-
Notifications
You must be signed in to change notification settings - Fork 200
Expand file tree
/
Copy path__init__.py
More file actions
61 lines (48 loc) · 2 KB
/
Copy path__init__.py
File metadata and controls
61 lines (48 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
"""Smart search tools for Home Assistant MCP server.
The implementation is split across sibling modules to keep each unit
focused (see issue #925):
- ``_search_config``: shared constants and pure helpers
- ``_search_base``: attributes shared across mixins + registry-list helper
- ``_search_deep``: ``deep_search`` (config-definition search)
- ``_search_overview``: ``get_system_overview``
- ``_search_entities``: ``smart_entity_search`` + ``get_entities_by_area``
"""
import logging
from ...client.rest_client import HomeAssistantClient
from ...config import get_global_settings
from ...utils.fuzzy_search import create_fuzzy_searcher
# Re-export shared constants so existing ``smart_search.<CONST>`` references
# keep resolving.
from ._config import (
AUTOMATION_CONFIG_TIME_BUDGET,
DEFAULT_CONCURRENCY_LIMIT,
ENTITY_REGISTRY_TIMEOUT,
INDIVIDUAL_CONFIG_TIMEOUT,
INDIVIDUAL_FETCH_BATCH_SIZE,
SCENE_CONFIG_TIME_BUDGET,
SCRIPT_CONFIG_TIME_BUDGET,
)
from ._deep import DeepSearchMixin
from ._entities import EntitySearchMixin
from ._overview import SystemOverviewMixin
logger = logging.getLogger(__name__)
class SmartSearchTools(DeepSearchMixin, SystemOverviewMixin, EntitySearchMixin):
"""Smart search tools with fuzzy matching and AI optimization."""
def __init__(
self, client: HomeAssistantClient | None = None, fuzzy_threshold: int = 60
):
"""Initialize with Home Assistant client."""
# Always load settings for configuration access
self.settings = get_global_settings()
# Use provided client or create new one
if client is None:
self.client = HomeAssistantClient()
fuzzy_threshold = self.settings.fuzzy_threshold
else:
self.client = client
self.fuzzy_searcher = create_fuzzy_searcher(threshold=fuzzy_threshold)
def create_smart_search_tools(
client: HomeAssistantClient | None = None,
) -> SmartSearchTools:
"""Create smart search tools instance."""
return SmartSearchTools(client)