Commit b2106cf
authored
refactor(complexity): reduce C901 violations in tools/ — batch 4 (#1408)
* refactor(complexity): reduce C901 violations in tools/ batch 4 (#925)
- Extract _check_control_flow_actions() in best_practice_checker.py
- Extract _parse_event_data() in tools_service.py
- Extract _try_raw_cdn() in tools_updates.py
- Extract _process_menu_flow_result(), _build_flow_error_context(),
_submit_step() in tools_config_entry_flow.py
- Migrate tools_yaml_config.py to class-based pattern (YamlConfigTools)
- Migrate tools_bug_report.py to class-based pattern (BugReportTools),
extracting _build_formatted_report()
- Add defensive guard in _process_menu_flow_result for empty intro_flow_id
- Add tests for _try_raw_cdn loop behavior and _submit_step error propagation
- Update test fixtures in test_tools_bug_report and test_yaml_config_tool
to use mcp.add_tool() (class-based registration pattern)
* fixup: ruff format + address Gemini review comments
- ruff format all changed files (CI enforces ruff format --check)
- _process_menu_flow_result: str | None type hint for intro_flow_id
- _process_menu_flow_result: narrow except to (HomeAssistantAPIError, TimeoutError)
- fetch_helper_flow_info: remove `and intro_flow_id` guard from MENU branch
(restores menu_options surfacing when intro_flow_id is absent)
- _try_raw_cdn: narrow except to httpx.RequestError
- test_tools_updates: use httpx.ConnectError in exception-continue test
* chore(hooks): add ruff-format to pre-commit hook
Mirrors the CI ruff format --check gate locally so formatting
issues are caught and auto-fixed before push.
* Potential fix for pull request finding 'Implicit string concatenation in a list'
Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com>
* fix: join implicit string concatenation in suggestions list
* refactor(complexity): fix C901 violations in tools_config_automations and util_helpers
- tools_config_automations: extract _scene_create_in_choose, _check_scene_create_misroute,
_validate_condition_platform, _run_python_transform, _run_config_update helpers
- util_helpers: extract _parse_json_to_str_list, _sample_state_change,
_discover_automation_sample, _automation_event_filter, _fetch_raw_diagnostics,
_apply_data_path_resolution, _ws_subscribe_all, _ws_post_subscribe_check,
_ws_run_wait_loop, _ws_cleanup, _apply_truncation_cap helpers
- pyproject.toml: remove util_helpers.py from C901 per-file-ignores
* refactor(service): extract _parse_json_dict_param to deduplicate JSON dict validation
_parse_event_data and _parse_service_data shared identical parse-validate-raise
logic differing only in the type error message. Extract into a single helper.1 parent e6cc7a1 commit b2106cf
14 files changed
Lines changed: 1459 additions & 1144 deletions
File tree
- src/ha_mcp/tools
- tests/src/unit
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
10 | 14 | | |
11 | 15 | | |
12 | 16 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
147 | 147 | | |
148 | 148 | | |
149 | 149 | | |
150 | | - | |
151 | 150 | | |
152 | 151 | | |
153 | 152 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
279 | 279 | | |
280 | 280 | | |
281 | 281 | | |
282 | | - | |
283 | | - | |
284 | | - | |
285 | | - | |
| 282 | + | |
286 | 283 | | |
287 | 284 | | |
288 | 285 | | |
| |||
304 | 301 | | |
305 | 302 | | |
306 | 303 | | |
307 | | - | |
308 | | - | |
309 | | - | |
| 304 | + | |
310 | 305 | | |
311 | 306 | | |
312 | 307 | | |
| |||
317 | 312 | | |
318 | 313 | | |
319 | 314 | | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
320 | 340 | | |
321 | 341 | | |
322 | 342 | | |
| |||
359 | 379 | | |
360 | 380 | | |
361 | 381 | | |
362 | | - | |
363 | | - | |
364 | | - | |
365 | | - | |
366 | | - | |
367 | | - | |
368 | | - | |
369 | | - | |
370 | | - | |
371 | | - | |
372 | | - | |
373 | | - | |
374 | | - | |
375 | | - | |
376 | | - | |
377 | | - | |
378 | | - | |
379 | | - | |
380 | | - | |
381 | | - | |
| 382 | + | |
382 | 383 | | |
383 | 384 | | |
384 | 385 | | |
| |||
439 | 440 | | |
440 | 441 | | |
441 | 442 | | |
442 | | - | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
443 | 446 | | |
444 | 447 | | |
445 | 448 | | |
446 | 449 | | |
447 | 450 | | |
448 | 451 | | |
449 | 452 | | |
450 | | - | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
451 | 456 | | |
452 | 457 | | |
453 | 458 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| 19 | + | |
19 | 20 | | |
20 | 21 | | |
21 | 22 | | |
| |||
28 | 29 | | |
29 | 30 | | |
30 | 31 | | |
31 | | - | |
| 32 | + | |
32 | 33 | | |
33 | 34 | | |
34 | 35 | | |
| |||
388 | 389 | | |
389 | 390 | | |
390 | 391 | | |
391 | | - | |
392 | | - | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 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 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
393 | 445 | | |
394 | | - | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
395 | 452 | | |
396 | 453 | | |
397 | 454 | | |
| |||
401 | 458 | | |
402 | 459 | | |
403 | 460 | | |
| 461 | + | |
404 | 462 | | |
405 | 463 | | |
406 | 464 | | |
| |||
476 | 534 | | |
477 | 535 | | |
478 | 536 | | |
479 | | - | |
| 537 | + | |
480 | 538 | | |
481 | 539 | | |
482 | 540 | | |
| |||
487 | 545 | | |
488 | 546 | | |
489 | 547 | | |
490 | | - | |
| 548 | + | |
491 | 549 | | |
492 | 550 | | |
493 | 551 | | |
| |||
511 | 569 | | |
512 | 570 | | |
513 | 571 | | |
514 | | - | |
515 | | - | |
516 | | - | |
517 | | - | |
518 | | - | |
519 | | - | |
520 | | - | |
521 | | - | |
522 | | - | |
523 | | - | |
524 | | - | |
525 | | - | |
526 | | - | |
527 | | - | |
528 | | - | |
529 | | - | |
530 | | - | |
531 | | - | |
532 | | - | |
533 | | - | |
534 | | - | |
535 | | - | |
536 | | - | |
537 | | - | |
538 | | - | |
539 | | - | |
540 | | - | |
541 | | - | |
542 | | - | |
543 | | - | |
544 | | - | |
545 | | - | |
546 | | - | |
547 | | - | |
548 | | - | |
549 | | - | |
550 | | - | |
551 | | - | |
552 | | - | |
553 | | - | |
554 | | - | |
555 | | - | |
556 | | - | |
557 | | - | |
558 | | - | |
559 | | - | |
560 | | - | |
561 | | - | |
562 | | - | |
563 | | - | |
564 | | - | |
565 | | - | |
566 | | - | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
567 | 584 | | |
568 | 585 | | |
569 | 586 | | |
| |||
673 | 690 | | |
674 | 691 | | |
675 | 692 | | |
| 693 | + | |
| 694 | + | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
676 | 698 | | |
677 | 699 | | |
678 | 700 | | |
| |||
0 commit comments