Commit 6630341
authored
fix: correct Tools-tab group master + LLM API toggle rendering (#1859)
* fix: show settings-UI group master toggle as on for all-mandatory groups
The per-group master switch in the Tools tab derived its checked state
from `anyEnabled`, computed only over *toggleable* tools (non-mandatory,
non-env-pinned, non-feature-gated). For a group whose tools are all
mandatory — e.g. Search & Discovery (ha_search, ha_get_overview,
ha_get_state) — that set is empty, so `anyEnabled` was always false and
the switch rendered unchecked+disabled: it read as "the whole group is
off" while the count beside it said "3/3 enabled" and the tools cannot be
disabled at all.
Compute the checked state from the group's real enabled status
(`groupEnabled`) when there are no toggleable tools, keeping the existing
`anyEnabled` bulk semantics for the interactive case. An all-mandatory
group now shows on+disabled; a mixed group keeps its interactive master.
Add JSDOM regression tests covering all-mandatory, all-disabled
toggleable, and mixed groups.
* fix: hide LLM API tool toggle on non-embedded install methods
The per-tool "LLM API" toggle offers a tool to Home Assistant
conversation agents through the LLM API surface that the ha_mcp_tools
custom component registers. That surface only exists on the in-process
(embedded) custom-component server; on the add-on, Docker, and
standalone servers nothing consumes it, so the toggle was a no-op there
yet still rendered for every tool.
The /api/settings/tools response now reports `llm_api_available`
(= is_embedded()), and the Tools tab renders the LLM API toggle column
only when it is true — other install methods drop the column entirely.
Add JSDOM coverage (toggle hidden when the flag is absent) and a
server-side test that the flag is true under HA_MCP_EMBEDDED.
* fix: group master switch reflects fully-enabled state, not any-enabled
The non-toggleable branch of the group master switch used
`groupEnabled > 0` ("any tool enabled") while the intended invariant is
"fully enabled, matching the N/N count". They diverge for a fully-locked
group that is only partially enabled — reachable via DISABLED_TOOLS or
feature gating (e.g. a mandatory tool beside an env-pinned-off one): the
switch rendered checked while the count read "1/2 enabled", the same
contradiction this PR fixes, inverted. Use `groupEnabled === tools.length`
— identical for every uniform case (all-mandatory, all-env-pinned) and
correct for the mixed case.
Also tidy the surrounding change:
- Extract the LLM API toggle fragment into an `llmToggleHtml` const,
matching the gatedNote/envPinnedNote/readOnlyNote idiom in render().
- Drop a duplicated comment and stray RST backticks on llmApiAvailable.
- Add regression tests: a partially-enabled locked group (unchecked,
fails on `> 0`) and an all-env-pinned-on group (checked); assert the
hidden-LLM test against `llm_api_available: False` and the absent key.
---------
Co-authored-by: kingpanther13 <kingpanther13@users.noreply.github.com>1 parent 294650a commit 6630341
4 files changed
Lines changed: 357 additions & 9 deletions
File tree
- src/ha_mcp/settings_ui
- tests/src/unit
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1446 | 1446 | | |
1447 | 1447 | | |
1448 | 1448 | | |
| 1449 | + | |
| 1450 | + | |
| 1451 | + | |
| 1452 | + | |
| 1453 | + | |
| 1454 | + | |
1449 | 1455 | | |
1450 | 1456 | | |
1451 | 1457 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
36 | 42 | | |
37 | 43 | | |
38 | 44 | | |
| |||
169 | 175 | | |
170 | 176 | | |
171 | 177 | | |
| 178 | + | |
172 | 179 | | |
173 | 180 | | |
174 | 181 | | |
| |||
598 | 605 | | |
599 | 606 | | |
600 | 607 | | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
601 | 621 | | |
602 | 622 | | |
603 | 623 | | |
| |||
606 | 626 | | |
607 | 627 | | |
608 | 628 | | |
609 | | - | |
| 629 | + | |
610 | 630 | | |
611 | 631 | | |
612 | 632 | | |
| |||
717 | 737 | | |
718 | 738 | | |
719 | 739 | | |
| 740 | + | |
| 741 | + | |
| 742 | + | |
| 743 | + | |
| 744 | + | |
| 745 | + | |
| 746 | + | |
| 747 | + | |
| 748 | + | |
| 749 | + | |
| 750 | + | |
| 751 | + | |
| 752 | + | |
720 | 753 | | |
721 | 754 | | |
722 | 755 | | |
| |||
750 | 783 | | |
751 | 784 | | |
752 | 785 | | |
753 | | - | |
754 | | - | |
755 | | - | |
756 | | - | |
757 | | - | |
758 | | - | |
759 | | - | |
760 | | - | |
| 786 | + | |
761 | 787 | | |
762 | 788 | | |
763 | 789 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2577 | 2577 | | |
2578 | 2578 | | |
2579 | 2579 | | |
| 2580 | + | |
| 2581 | + | |
| 2582 | + | |
| 2583 | + | |
| 2584 | + | |
| 2585 | + | |
| 2586 | + | |
| 2587 | + | |
| 2588 | + | |
| 2589 | + | |
| 2590 | + | |
| 2591 | + | |
| 2592 | + | |
| 2593 | + | |
| 2594 | + | |
| 2595 | + | |
| 2596 | + | |
| 2597 | + | |
| 2598 | + | |
| 2599 | + | |
| 2600 | + | |
| 2601 | + | |
| 2602 | + | |
| 2603 | + | |
| 2604 | + | |
| 2605 | + | |
| 2606 | + | |
| 2607 | + | |
| 2608 | + | |
| 2609 | + | |
| 2610 | + | |
| 2611 | + | |
| 2612 | + | |
| 2613 | + | |
| 2614 | + | |
| 2615 | + | |
| 2616 | + | |
| 2617 | + | |
| 2618 | + | |
| 2619 | + | |
| 2620 | + | |
2580 | 2621 | | |
2581 | 2622 | | |
2582 | 2623 | | |
| |||
0 commit comments