|
| 1 | +--- |
| 2 | +name: homeassistant-yaml-dry-verifier |
| 3 | +description: "Verify Home Assistant YAML for DRY and efficiency issues by detecting redundant trigger/condition/action/sequence structures and repeated blocks across automations, scripts, and packages. Use when creating, reviewing, or refactoring YAML in config/packages, config/automations, config/scripts, or dashboard-related YAML where duplication risk is high." |
| 4 | +--- |
| 5 | + |
| 6 | +# Home Assistant YAML DRY Verifier |
| 7 | + |
| 8 | +Use this skill to lint Home Assistant YAML for repeat logic before or after edits, then refactor repeated blocks into reusable helpers. |
| 9 | + |
| 10 | +## Quick Start |
| 11 | + |
| 12 | +1. Run the verifier script on the file(s) you edited. |
| 13 | +2. Review repeated block findings first (highest confidence). |
| 14 | +3. Refactor into shared scripts/helpers/templates where appropriate. |
| 15 | +4. Re-run the verifier and then run your normal Home Assistant config check. |
| 16 | + |
| 17 | +```bash |
| 18 | +python codex_skills/homeassistant-yaml-dry-verifier/scripts/verify_ha_yaml_dry.py config/packages/life360.yaml --strict |
| 19 | +``` |
| 20 | + |
| 21 | +Scan a full directory when doing wider cleanup: |
| 22 | + |
| 23 | +```bash |
| 24 | +python codex_skills/homeassistant-yaml-dry-verifier/scripts/verify_ha_yaml_dry.py config/packages config/automations |
| 25 | +``` |
| 26 | + |
| 27 | +## Workflow |
| 28 | + |
| 29 | +1. Identify target YAML: |
| 30 | +- Prefer changed files first. |
| 31 | +- Include adjacent package/script files when the change might duplicate existing logic. |
| 32 | + |
| 33 | +2. Run verifier: |
| 34 | +- Use `--min-occurrences 2` (default) for normal checks. |
| 35 | +- Use `--strict` when you want non-zero exit if duplication is found. |
| 36 | + |
| 37 | +3. Prioritize findings in this order: |
| 38 | +- `FULL_BLOCK`: repeated full trigger/condition/action/sequence blocks. |
| 39 | +- `ENTRY`: repeated individual entries inside those blocks. |
| 40 | +- `INTRA`: duplicate entries inside a single block. |
| 41 | + |
| 42 | +4. Refactor with intent: |
| 43 | +- Repeated actions/sequence: move to a reusable `script.*`, pass variables. |
| 44 | +- Repeated conditions: extract to template binary sensors or helper entities. |
| 45 | +- Repeated triggers: consolidate where behavior is equivalent, or split by intent if readability improves. |
| 46 | + |
| 47 | +5. Validate after edits: |
| 48 | +- Re-run this verifier. |
| 49 | +- Run Home Assistant config validation before reload/restart. |
| 50 | + |
| 51 | +## Dashboard Designer Integration |
| 52 | + |
| 53 | +When dashboard or automation work includes YAML edits beyond card layout, use this verifier after generation to catch duplicated logic that may have been introduced during fast refactors. |
| 54 | + |
| 55 | +## Output Contract |
| 56 | + |
| 57 | +Always report: |
| 58 | +- Total files scanned. |
| 59 | +- Parse errors (if any). |
| 60 | +- Duplicate groups by kind (`trigger`, `condition`, `action`, `sequence`). |
| 61 | +- Concrete refactor recommendation per group. |
| 62 | + |
| 63 | +## References |
| 64 | + |
| 65 | +- Read `references/refactor_playbook.md` for concise DRY refactor patterns. |
0 commit comments