Skip to content

Commit 4846118

Browse files
sergeykadSergey
andauthored
refactor(c901): tools_search.py below C901 threshold (#1665)
* refactor(c901): tools_search.py below C901 threshold Migrates the 5 closure-nested functions inside `register_search_tools` to a `SearchTools` class, then decomposes the four over-threshold methods into focused helpers: - `_ha_search_entities` (80→<10): 4 branch helpers (`_search_area_with_query`, `_search_area_only`, `_search_area_only_populated`, `_search_domain_only`, `_search_regular`) - `ha_get_state` (24→<10): `_get_single_entity_state`, `_get_bulk_entity_states`, `_accumulate_state_results` - `ha_get_overview` (19→<10): `_fetch_system_info`, `_fetch_notifications`, `_fetch_repairs` - `ha_search` (13→<10): `_apply_search_outcome` extracted - `_exact_match_search` (13→<10): `_build_hidden_ids` extracted - `_merge_payload_metadata` (12→<10): `_merge_list_key`, `_merge_partial_reason` extracted Removes `tools_search.py` from the C901 per-file ignore in `pyproject.toml` (3 files remain: dashboards, entities, registry). * fix: resolve CodeQL findings and expand AST harvest coverage - Remove redundant search_type assignment in _search_regular (py/multiple-definition) - Add return None after raise_tool_error in _ha_search_entities except-ValueError block (py/mixed-returns) - Add return None after exception_to_structured_error in _get_single_entity_state (py/mixed-returns) - Expand test_entities_branch_emissions to scan _exact_match_search and _normalize_regular_search_result for complete key coverage --------- Co-authored-by: Sergey <sergey@example.com>
1 parent 5c6c97a commit 4846118

8 files changed

Lines changed: 1193 additions & 1132 deletions

pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,6 @@ ignore = [
152152
"src/ha_mcp/tools/tools_config_dashboards.py" = ["C901"]
153153
"src/ha_mcp/tools/tools_entities.py" = ["C901"]
154154
"src/ha_mcp/tools/tools_registry.py" = ["C901"]
155-
"src/ha_mcp/tools/tools_search.py" = ["C901"]
156155

157156
[tool.pytest.ini_options]
158157
testpaths = ["tests"]

0 commit comments

Comments
 (0)