Commit 156e67e
fix: persist cleared override fields in the in-process server options flow (#1834)
* fix: persist cleared override fields in the in-process server options flow
The server entry's options flow pre-filled its optional text fields
(pip-spec / server-URL / external-URL / webhook-id / secret-path) with a
voluptuous schema `default` equal to the saved value. HA's frontend drops
an emptied optional field from the submitted payload, so the flow manager
re-applied that default and clearing never stuck: the "Developer: ha-mcp
package override" field kept re-installing the old build and re-appeared
populated on reopen. Typing the default dist name ("ha-mcp") was the only
way to clear it, because `_normalize` collapses the default to empty.
Pre-fill via `description={"suggested_value": ...}` instead. It shows the
same value but is not re-injected on an empty submit, so a cleared field
stays cleared while an untouched field is still submitted unchanged.
`ha_dev_manage_server("update_source")` drives the same flow with a partial
submit and relied on those defaults to preserve the fields it does not
change. With the defaults gone, resend the user's current overrides
(reading `description.suggested_value` first) so a channel or pip-spec
change no longer blanks the server URL or connect secrets.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* fix: address review — normalize server_url, doc accuracy, CodeQL, tests
- config_flow: normalize server_url in _normalize (strip + trim trailing slash,
drop when blank) so a whitespace-only Home Assistant URL can't be stored
verbatim and bypass the empty->loopback fallback (Gemini review).
- config_flow: correct the stale _normalize docstring (the pip-spec field is
pre-filled with the saved override or blank, not DEFAULT_PIP_SPEC) and the
misquoted "Leave empty" help text.
- tools_dev: fix the _field_prefill / find_server_config_entry docstrings (the
component sets suggested_value directly; note the value fallback), shorten the
update_source comment, and log a rejected deferred self-restart at warning.
- tests: split pop() out of the assert in test_form_prefills_* to clear the
CodeQL py/side-effect-in-assert findings; add server_url whitespace / trailing-
slash tests and a dev-tool test that a caller pip_spec wins over the preserved
pin.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: kingpanther13 <kingpanther13@users.noreply.github.com>
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>1 parent c4a367a commit 156e67e
4 files changed
Lines changed: 258 additions & 28 deletions
File tree
- custom_components/ha_mcp_tools
- src/ha_mcp/tools
- tests/src/unit
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
262 | 262 | | |
263 | 263 | | |
264 | 264 | | |
265 | | - | |
266 | | - | |
267 | | - | |
268 | | - | |
269 | | - | |
270 | | - | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
271 | 278 | | |
272 | 279 | | |
273 | 280 | | |
274 | | - | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
275 | 286 | | |
276 | 287 | | |
277 | 288 | | |
| |||
301 | 312 | | |
302 | 313 | | |
303 | 314 | | |
| 315 | + | |
| 316 | + | |
304 | 317 | | |
305 | 318 | | |
306 | | - | |
| 319 | + | |
307 | 320 | | |
308 | 321 | | |
309 | 322 | | |
310 | | - | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
311 | 326 | | |
312 | 327 | | |
313 | 328 | | |
314 | | - | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
315 | 332 | | |
316 | 333 | | |
317 | 334 | | |
| |||
343 | 360 | | |
344 | 361 | | |
345 | 362 | | |
346 | | - | |
347 | | - | |
348 | | - | |
349 | | - | |
350 | | - | |
351 | | - | |
352 | | - | |
353 | | - | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
354 | 373 | | |
355 | 374 | | |
356 | 375 | | |
| |||
362 | 381 | | |
363 | 382 | | |
364 | 383 | | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
365 | 393 | | |
366 | 394 | | |
367 | 395 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
47 | 51 | | |
48 | 52 | | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
49 | 66 | | |
50 | 67 | | |
51 | 68 | | |
| |||
85 | 102 | | |
86 | 103 | | |
87 | 104 | | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
88 | 122 | | |
89 | 123 | | |
90 | 124 | | |
| |||
95 | 129 | | |
96 | 130 | | |
97 | 131 | | |
98 | | - | |
99 | | - | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
100 | 135 | | |
101 | 136 | | |
102 | 137 | | |
| |||
131 | 166 | | |
132 | 167 | | |
133 | 168 | | |
134 | | - | |
| 169 | + | |
135 | 170 | | |
136 | 171 | | |
137 | 172 | | |
| |||
400 | 435 | | |
401 | 436 | | |
402 | 437 | | |
403 | | - | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
404 | 448 | | |
405 | 449 | | |
406 | 450 | | |
| |||
819 | 863 | | |
820 | 864 | | |
821 | 865 | | |
822 | | - | |
| 866 | + | |
| 867 | + | |
| 868 | + | |
| 869 | + | |
| 870 | + | |
| 871 | + | |
823 | 872 | | |
824 | 873 | | |
825 | 874 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
307 | 307 | | |
308 | 308 | | |
309 | 309 | | |
310 | | - | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
311 | 314 | | |
312 | 315 | | |
313 | 316 | | |
| |||
328 | 331 | | |
329 | 332 | | |
330 | 333 | | |
331 | | - | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
332 | 351 | | |
333 | 352 | | |
334 | | - | |
| 353 | + | |
| 354 | + | |
335 | 355 | | |
336 | 356 | | |
337 | 357 | | |
| |||
340 | 360 | | |
341 | 361 | | |
342 | 362 | | |
343 | | - | |
| 363 | + | |
344 | 364 | | |
345 | 365 | | |
346 | 366 | | |
| |||
380 | 400 | | |
381 | 401 | | |
382 | 402 | | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
383 | 428 | | |
384 | 429 | | |
385 | 430 | | |
| |||
391 | 436 | | |
392 | 437 | | |
393 | 438 | | |
394 | | - | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
395 | 473 | | |
396 | 474 | | |
397 | 475 | | |
| |||
0 commit comments