Commit fc99c51
refactor(c901): tools_entities.py below C901 threshold (#1692)
* refactor(c901): tools_entities.py below C901 threshold
- Convert closure pattern to EntityTools class; register_entity_tools
becomes a 1-liner calling register_tool_methods(mcp, EntityTools(client))
- Extract 10 module-level pure helpers and 9 async class methods so all
functions stay below McCabe complexity 10
- Remove "src/ha_mcp/tools/tools_entities.py" = ["C901"] exemption from
pyproject.toml
- Fix bulk categories bug: old code hardcoded None for categories in
gather; new code passes parsed_categories matching docstring and validation
- Fix updates_applied in Phase-4 error context: expose_to= and device_name
entries are now appended after their WS phases run, not pre-appended
- Unify _parse_aliases_param/_parse_labels_param into _parse_string_list_field
- Flatten double-nested if in _validate_enabled_constraint
- Update test fixtures from mcp.tool capture to mcp.add_tool capture
- Add test_bulk_categories_set regression test
* fix: address Gemini review on PR #1692
- Guard all result.get("result", {}) calls with `or {}` so a null
"result" key from HA never produces an AttributeError on .get()
- Change expose_to entity-entry fetch guard from has_registry_updates
to `not entity_entry` — avoids redundant WS round-trip when options
or device_rename already populated entity_entry
---------
Co-authored-by: Sergey <sergey@example.com>1 parent e74031e commit fc99c51
4 files changed
Lines changed: 883 additions & 700 deletions
File tree
- src/ha_mcp/tools
- tests/src/unit
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
150 | 150 | | |
151 | 151 | | |
152 | 152 | | |
153 | | - | |
154 | 153 | | |
155 | 154 | | |
156 | 155 | | |
| |||
0 commit comments