Commit 48b030a
authored
* fix(tools): modernize stale HA API field names in docstring examples
Audit of all 83 tool docstrings for inline JSON/dict examples referencing HA
API field names renamed in recent releases (issue #1540; follow-on to #1539's
service:->action: fix).
- ha_get_state: the attribute_keys example used "color_temp", which HA removed
from the light state-attribute set in 2026.3 (now "color_temp_kelvin").
attribute_keys silently drops unknown keys, so a model copying the example
gets nothing back for that key on a modern light.
- ha_config_set_automation: the create-from-scratch examples used the
pre-2024.10 singular root keys (trigger/action/condition) and per-trigger
"platform:". Updated to the 2024.10+ canonical plural roots
(triggers/actions/conditions) and per-trigger "trigger:". Both forms remain
accepted by HA; this teaches the current canonical shape.
The python_transform examples intentionally keep the singular root + "platform:"
form -- they operate on the fetched, round-trip-normalized config -- now with a
clarifying note. Corrected the _normalize_automation_config and
_normalize_trigger_keys docstrings that claimed "the API expects singular forms":
HA accepts both; the tool normalizes to singular internally for round-trip and
downstream-validator stability.
Docstring/comment only; no behavior change. ruff and automation unit tests pass.
* refactor(automations): canonicalize automation config to HA 2024.10+ plural shape
Flip the tool's internal wire convention from the legacy singular root keys +
per-trigger 'platform:' to HA's 2024.10+ canonical form: plural root list keys
('triggers'/'actions'/'conditions') and per-trigger 'trigger:'. Both forms are
still accepted by HA; this makes ha_config_get_automation return the modern
shape and the SET path send it.
- _normalize_automation_config: canonicalize root list keys singular -> plural
(only at root; deeper discriminators/service calls untouched, issue #498). The
choose/if/compound 'conditions' lists are already plural and pass through.
- _normalize_trigger_keys: flip platform -> trigger (modern per-trigger key).
- _normalize_config_for_roundtrip: produce plural roots + 'trigger:' keys.
- Internal validators (_validate_required_fields, _check_scene_create_misroute,
_validate_condition_platform) read the plural keys (they run post-normalize).
- best_practice_checker.check_automation_config reads the canonical plural keys
but tolerates the singular aliases too (it may see raw user input), mirroring
its existing platform/trigger tolerance.
- Rewrote test_automation_normalization for the plural contract + added
round-trip tests; updated test_config_automation_validation inputs to the
normalized plural shape.
ruff clean; all automation/best-practice/normalization unit tests pass.
* test(automations): update python_transform e2e for canonical plural config shape
ha_config_get_automation now returns HA's 2024.10+ plural root keys, and
python_transform operates on that fetched (now plural) config. Update the
transform expressions (config['action'] -> config['actions']) and GET-output
assertions accordingly. Inputs stay legacy-singular on purpose — they exercise
the tool's backward-compat acceptance of the singular aliases.
* fix(tools): drop removed fan `speed`/`set_speed` for current 2026.6 services
Codebase-wide sweep for stale HA API field/service names (issue #1540, 2026.6
currency). HA removed the legacy fan `speed` param and `fan.set_speed` service
in the 2021-2022 percentage migration (verified absent in HA core 2026.6.0).
- domain_handlers.py: drop "speed" from the fan domain's suggested `parameters`
(kept percentage / preset_mode / direction, the current fan.* services).
- tools_service.py: replace the dead "set_speed" entry in _STATE_CHANGING_SERVICES
with its state-changing successors "set_percentage" / "set_preset_mode" so fan
speed changes are still correctly awaited.
The rest of the codebase verified clean against 2026.6 (lights already emit
color_temp_kelvin, calendar uses get_events, climate/cover/media_player/todo/
energy/scripts/scenes all current; capability-concept flags like supports_speed
left as-is — not HA API fields).
* refactor(automations): address PR review (trigger-key hardening, stale strings, coverage)
Verified findings from the multi-agent PR review + Gemini:
- _normalize_trigger_keys: guard non-dict items (defensive against malformed
LLM trigger lists) and drop the legacy 'platform' alias when 'trigger' is also
present, so HA's strict schema doesn't reject the config (Gemini).
- Fix the stale singular field name in the ha_config_set_automation failure
suggestion ("alias, trigger, action" -> "alias, triggers, actions") — the one
model-facing site the plural sweep missed (code-reviewer).
- Fix the stale "triggers -> trigger" comment at the set-path normalize call to
match the new singular -> plural direction (type-design + comment review).
- Soften the best_practice_checker tolerance comment (the internal pipeline
always pre-normalizes; the singular fallback is defensive for public callers).
- Note the sequences -> sequence transform in _normalize_config_for_roundtrip's
docstring.
- tests/AGENTS.md: flip the "HA API uses singular field names" guidance to the
2024.10+ plural canonical (it's inverted by this PR).
- Tests: pin the new trigger-key behavior (drop platform / non-dict passthrough)
and add TestPluralKeyTolerance so the plural-first reads in
check_automation_config are exercised (they were only hit via singular fallback).
ruff clean; 195 affected unit tests pass.
* fix(automations): warn instead of silently dropping a conflicting root-key alias
Addresses the PR-review silent-failure finding. When a config carries BOTH a
singular alias and its canonical plural root key with different values (e.g. a
python_transform that sets singular config['trigger'] on a fetched plural
config), _normalize_automation_config keeps the plural and drops the singular —
previously with no signal.
Add _detect_conflicting_root_keys(), run it on the pre-normalization config in
both the full-config and python_transform paths, and surface a top-level
warnings[] entry ("Config contains both 'trigger' and 'triggers' ... using
'triggers' and ignoring 'trigger'.") so the discarded change is visible.
Unit tests for the detector added (all three pairs, equal-values no-op, single
form, non-dict). mypy + ruff clean; affected unit suites pass.
---------
Co-authored-by: kingpanther13 <kingpanther13@users.noreply.github.com>
1 parent 148f506 commit 48b030a
10 files changed
Lines changed: 560 additions & 344 deletions
File tree
- src/ha_mcp
- tools
- utils
- tests
- src
- e2e/workflows/automation
- unit
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
197 | 197 | | |
198 | 198 | | |
199 | 199 | | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
200 | 204 | | |
201 | | - | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
202 | 208 | | |
203 | 209 | | |
204 | | - | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
205 | 213 | | |
206 | 214 | | |
207 | | - | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
208 | 218 | | |
209 | 219 | | |
210 | 220 | | |
| |||
738 | 748 | | |
739 | 749 | | |
740 | 750 | | |
741 | | - | |
| 751 | + | |
742 | 752 | | |
743 | 753 | | |
744 | 754 | | |
| |||
750 | 760 | | |
751 | 761 | | |
752 | 762 | | |
753 | | - | |
| 763 | + | |
754 | 764 | | |
755 | 765 | | |
756 | 766 | | |
| |||
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2331 | 2331 | | |
2332 | 2332 | | |
2333 | 2333 | | |
2334 | | - | |
| 2334 | + | |
2335 | 2335 | | |
2336 | 2336 | | |
2337 | 2337 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
81 | 81 | | |
82 | 82 | | |
83 | 83 | | |
84 | | - | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
85 | 88 | | |
86 | 89 | | |
87 | 90 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
74 | 74 | | |
75 | 75 | | |
76 | 76 | | |
77 | | - | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
78 | 81 | | |
79 | 82 | | |
80 | 83 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
28 | | - | |
| 28 | + | |
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
| |||
Lines changed: 17 additions & 16 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
43 | | - | |
| 43 | + | |
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
| |||
51 | 51 | | |
52 | 52 | | |
53 | 53 | | |
54 | | - | |
| 54 | + | |
55 | 55 | | |
56 | 56 | | |
57 | 57 | | |
| |||
101 | 101 | | |
102 | 102 | | |
103 | 103 | | |
104 | | - | |
| 104 | + | |
105 | 105 | | |
106 | 106 | | |
107 | 107 | | |
| |||
113 | 113 | | |
114 | 114 | | |
115 | 115 | | |
116 | | - | |
| 116 | + | |
117 | 117 | | |
118 | 118 | | |
119 | 119 | | |
| |||
142 | 142 | | |
143 | 143 | | |
144 | 144 | | |
145 | | - | |
| 145 | + | |
146 | 146 | | |
147 | 147 | | |
148 | 148 | | |
| |||
158 | 158 | | |
159 | 159 | | |
160 | 160 | | |
161 | | - | |
| 161 | + | |
162 | 162 | | |
163 | 163 | | |
164 | 164 | | |
| |||
175 | 175 | | |
176 | 176 | | |
177 | 177 | | |
178 | | - | |
| 178 | + | |
179 | 179 | | |
180 | 180 | | |
181 | 181 | | |
| |||
225 | 225 | | |
226 | 226 | | |
227 | 227 | | |
228 | | - | |
| 228 | + | |
229 | 229 | | |
230 | 230 | | |
231 | 231 | | |
| |||
301 | 301 | | |
302 | 302 | | |
303 | 303 | | |
304 | | - | |
| 304 | + | |
305 | 305 | | |
306 | 306 | | |
307 | 307 | | |
| |||
312 | 312 | | |
313 | 313 | | |
314 | 314 | | |
315 | | - | |
| 315 | + | |
316 | 316 | | |
317 | 317 | | |
318 | 318 | | |
| |||
386 | 386 | | |
387 | 387 | | |
388 | 388 | | |
389 | | - | |
| 389 | + | |
390 | 390 | | |
391 | 391 | | |
392 | 392 | | |
| |||
427 | 427 | | |
428 | 428 | | |
429 | 429 | | |
430 | | - | |
| 430 | + | |
431 | 431 | | |
432 | | - | |
433 | | - | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
434 | 435 | | |
435 | 436 | | |
436 | 437 | | |
| |||
614 | 615 | | |
615 | 616 | | |
616 | 617 | | |
617 | | - | |
| 618 | + | |
618 | 619 | | |
619 | 620 | | |
620 | 621 | | |
621 | 622 | | |
622 | 623 | | |
623 | 624 | | |
624 | 625 | | |
625 | | - | |
| 626 | + | |
626 | 627 | | |
0 commit comments