Add category filter and pagination to the search integrations LLM tool (#193206)

Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
Paulus Schoutsen
2026-11-21 19:18:57 -08:00
committed by GitHub
co-authored by Claude
parent 5c111084fd
commit 12ed26f2e7
6 changed files with 303 additions and 75 deletions
+31 -3
View File
@@ -1,11 +1,13 @@
"""Generate the integration_categories.json file."""
"""Generate the integration_categories.json and integration_categories.py files."""
import json
from pathlib import Path
from hassfest.model import Config, Integration
from hassfest.serializer import format_python_namespace
PATH = "homeassistant/generated/integration_categories.json"
PYTHON_PATH = "homeassistant/generated/integration_categories.py"
def _generate(integration_path: Path) -> str:
@@ -43,9 +45,21 @@ def _generate(integration_path: Path) -> str:
return json.dumps(categories, indent=2)
def _generate_python(categories_json: str) -> str:
"""Generate the slugs of the top-level categories, for code that needs them."""
return format_python_namespace(
{
"INTEGRATION_CATEGORIES": [
category["slug"] for category in json.loads(categories_json)
]
}
)
def validate(integrations: dict[str, Integration], config: Config) -> None:
"""Validate integration_categories.json."""
"""Validate integration_categories.json and integration_categories.py."""
path = config.root / PATH
python_path = config.root / PYTHON_PATH
integration = integrations["homeassistant"]
# The json, translations and icons plugins report invalid strings and icons,
@@ -63,8 +77,22 @@ def validate(integrations: dict[str, Integration], config: Config) -> None:
fixable=True,
)
config.cache["integration_categories_python"] = python_content = _generate_python(
content
)
if not python_path.is_file() or python_path.read_text() != python_content:
config.add_error(
"integration_categories",
"File integration_categories.py is not up to date. "
"Run python3 -m script.hassfest",
fixable=True,
)
def generate(integrations: dict[str, Integration], config: Config) -> None:
"""Generate integration_categories.json."""
"""Generate integration_categories.json and integration_categories.py."""
path = config.root / PATH
path.write_text(f"{config.cache['integration_categories']}\n")
python_path = config.root / PYTHON_PATH
python_path.write_text(config.cache["integration_categories_python"])