Commit 73e8858
fix: join entity registry in ha_config_list_helpers so renamed helpers show current entity_id/name (#1818)
* fix: join entity registry in ha_config_list_helpers so renamed helpers show current entity_id/name
ha_config_list_helpers returned the {type}/list storage-collection response
verbatim, which carries the immutable id (unique_id) and creation-time name and
never consults the entity registry. After a UI rename the id/name go stale, and
because ha_config_set_helper resolves a helper by constructing an entity_id from
the passed id and reading the registry, feeding a stale id back in fails with
ENTITY_NOT_FOUND – the current entity_id is the working key (#1794).
Join config/entity_registry/list by unique_id + platform onto each record: add
the current entity_id, move the storage name to original_name, and set name to
the current display name (registry name, falling back to original_name). The
storage id is kept for reference. Types without a matching entity (e.g. tag) and
platform mismatches are left untouched; a failed registry read degrades open
with a warning rather than dropping the list.
The list now runs the {type}/list response through _flatten_helper_list_result
first: person/list returns {"storage": [...], "config": [...]} rather than a
flat list, which previously made the person count wrong (len of the two keys)
and would have left the enrichment iterating dict keys. Other types are
unaffected (a flat list flattens to itself).
- unit: rename, null-name fallback, no-match, platform-mismatch, registry-failure, malformed-read, person-dict-flatten
- e2e: the input_boolean list lifecycle now asserts the current entity_id is surfaced
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* fix: harden list_helpers registry join per review
Addresses the review on #1818:
- Degrade-open the whole enrichment body, not just the WS call: the join
lookups now run under a broad `except Exception` (mirroring
`_get_entities_for_config_entry`), so an unexpected registry shape
(e.g. a non-hashable id) flags the result instead of failing the list.
Drops the unreachable `(HomeAssistantAPIError, ConnectionError,
TimeoutError)` tuple — `send_websocket_message` returns
`{"success": false}` rather than raising.
- Add unit cases for the branch production takes (`{"success": false}`)
and the unexpected-shape degrade (non-hashable id).
- Add a dedicated e2e that renames the entity_id + name, then asserts the
list surfaces the current registry values while storage keeps the
creation-time id/original_name, and round-trips set_helper with the
surfaced entity_id.
- Point the stale-registry warning at ha_search (find by name) instead of
ha_get_entity, which needs the entity_id the warning says is missing.
- Log the malformed-response branch, and mark entity_id/original_name as
conditional in the tool docstring (absent for tag and when the read
degrades).
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* test: reconcile registry join with component routing after rebase
Rebasing onto master pulled in #1812's component-backed helpers_list path,
which sits ahead of the legacy {type}/list body this PR enriches. Two
test-side adjustments so the legacy join is exercised deterministically:
- test_helper_list_registry_join: the mock client leaves base_url/token
unset so get_component_caps returns None via its no-credentials guard and
the tool takes the legacy path (rather than the component path
short-circuiting the join under test).
- test_ha_config_list_helpers_component_routing: the RoutingClient spy now
serves config/entity_registry/list (the join's read) with a registry
matching the canned rename shape, so the legacy path enriches to the same
record the component path emits — keeping the two paths parity-equal — and
the registry read is not tallied as a {type}/list fetch.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* fix: surface original_name on the component helpers_list path
The rebase onto #1812 exposed a shape divergence: on component installs
ha_config_list_helpers is served by the component path, whose shaped record
carried id/entity_id/current name but not original_name — the field the
legacy join adds and the tool docstring now promises. The new #1794 rename
e2e caught it on the four E2E Validation lanes (component serves the list
there), and the routing suite already asserts the two paths stay parity-equal.
_shape_collection_helper_record starts from the storage body (config), whose
name is the creation-time name (a rename updates the registry, not the body —
#1794), then overrides name with the current display name. Preserve the body
name as original_name before that override, mirroring the legacy join's
additive shape, so both serving paths carry the same fields. Fixed at the
shaper rather than the component because the creation name is already present
in the body — no component change or version bump needed.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>1 parent 96eb04e commit 73e8858
4 files changed
Lines changed: 576 additions & 8 deletions
File tree
- src/ha_mcp/tools
- tests/src
- e2e/workflows/config
- unit
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1399 | 1399 | | |
1400 | 1400 | | |
1401 | 1401 | | |
| 1402 | + | |
| 1403 | + | |
| 1404 | + | |
| 1405 | + | |
| 1406 | + | |
| 1407 | + | |
| 1408 | + | |
| 1409 | + | |
| 1410 | + | |
| 1411 | + | |
| 1412 | + | |
| 1413 | + | |
| 1414 | + | |
| 1415 | + | |
| 1416 | + | |
| 1417 | + | |
| 1418 | + | |
| 1419 | + | |
| 1420 | + | |
| 1421 | + | |
| 1422 | + | |
| 1423 | + | |
| 1424 | + | |
| 1425 | + | |
| 1426 | + | |
| 1427 | + | |
| 1428 | + | |
| 1429 | + | |
| 1430 | + | |
| 1431 | + | |
| 1432 | + | |
| 1433 | + | |
| 1434 | + | |
| 1435 | + | |
| 1436 | + | |
| 1437 | + | |
| 1438 | + | |
| 1439 | + | |
| 1440 | + | |
| 1441 | + | |
| 1442 | + | |
| 1443 | + | |
| 1444 | + | |
| 1445 | + | |
| 1446 | + | |
| 1447 | + | |
| 1448 | + | |
| 1449 | + | |
| 1450 | + | |
| 1451 | + | |
| 1452 | + | |
| 1453 | + | |
| 1454 | + | |
| 1455 | + | |
| 1456 | + | |
| 1457 | + | |
| 1458 | + | |
| 1459 | + | |
| 1460 | + | |
| 1461 | + | |
| 1462 | + | |
| 1463 | + | |
| 1464 | + | |
| 1465 | + | |
| 1466 | + | |
| 1467 | + | |
| 1468 | + | |
| 1469 | + | |
| 1470 | + | |
| 1471 | + | |
| 1472 | + | |
| 1473 | + | |
| 1474 | + | |
| 1475 | + | |
| 1476 | + | |
| 1477 | + | |
| 1478 | + | |
| 1479 | + | |
| 1480 | + | |
1402 | 1481 | | |
1403 | 1482 | | |
1404 | 1483 | | |
| |||
3391 | 3470 | | |
3392 | 3471 | | |
3393 | 3472 | | |
| 3473 | + | |
| 3474 | + | |
| 3475 | + | |
| 3476 | + | |
| 3477 | + | |
| 3478 | + | |
| 3479 | + | |
| 3480 | + | |
3394 | 3481 | | |
3395 | 3482 | | |
3396 | 3483 | | |
| |||
3538 | 3625 | | |
3539 | 3626 | | |
3540 | 3627 | | |
3541 | | - | |
3542 | | - | |
| 3628 | + | |
| 3629 | + | |
| 3630 | + | |
3543 | 3631 | | |
3544 | 3632 | | |
3545 | 3633 | | |
| 3634 | + | |
| 3635 | + | |
| 3636 | + | |
| 3637 | + | |
| 3638 | + | |
| 3639 | + | |
| 3640 | + | |
3546 | 3641 | | |
3547 | 3642 | | |
3548 | 3643 | | |
| |||
3602 | 3697 | | |
3603 | 3698 | | |
3604 | 3699 | | |
3605 | | - | |
3606 | | - | |
| 3700 | + | |
| 3701 | + | |
| 3702 | + | |
| 3703 | + | |
| 3704 | + | |
| 3705 | + | |
| 3706 | + | |
| 3707 | + | |
| 3708 | + | |
| 3709 | + | |
3607 | 3710 | | |
3608 | 3711 | | |
3609 | 3712 | | |
3610 | 3713 | | |
3611 | 3714 | | |
3612 | 3715 | | |
| 3716 | + | |
| 3717 | + | |
| 3718 | + | |
3613 | 3719 | | |
3614 | 3720 | | |
3615 | 3721 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
97 | 97 | | |
98 | 98 | | |
99 | 99 | | |
100 | | - | |
| 100 | + | |
101 | 101 | | |
102 | 102 | | |
103 | | - | |
| 103 | + | |
104 | 104 | | |
105 | | - | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
106 | 111 | | |
107 | 112 | | |
108 | 113 | | |
| |||
143 | 148 | | |
144 | 149 | | |
145 | 150 | | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
146 | 252 | | |
147 | 253 | | |
148 | 254 | | |
| |||
Lines changed: 21 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
55 | 55 | | |
56 | 56 | | |
57 | 57 | | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
58 | 73 | | |
59 | 74 | | |
60 | 75 | | |
| |||
106 | 121 | | |
107 | 122 | | |
108 | 123 | | |
109 | | - | |
110 | 124 | | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
111 | 131 | | |
112 | 132 | | |
113 | 133 | | |
| |||
0 commit comments