Commit 4846118
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
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
152 | 152 | | |
153 | 153 | | |
154 | 154 | | |
155 | | - | |
156 | 155 | | |
157 | 156 | | |
158 | 157 | | |
| |||
0 commit comments