diff --git a/.claude/skills/ha-integration-knowledge/SKILL.md b/.claude/skills/ha-integration-knowledge/SKILL.md index 6523cc5393a..cd25d3127ef 100644 --- a/.claude/skills/ha-integration-knowledge/SKILL.md +++ b/.claude/skills/ha-integration-knowledge/SKILL.md @@ -15,6 +15,7 @@ description: Everything you need to know to build, test and review Home Assistan - For entity actions and entity services, avoid requesting redundant defensive checks for fields already enforced by Home Assistant validation schemas and entity filters; only request extra guards when values bypass validation or are transformed unsafely. - When validation guarantees a key is present, prefer direct dictionary indexing (`data["key"]`) over `.get("key")` so invalid assumptions fail fast. - Integrations should be thin wrappers. Protocol parsing, device state machines, or other domain logic belong in a separate PyPI library, not in the integration itself. If unsure, ask before inlining. +- Integrations should not implement fixes or workarounds for limitations in libraries. Instead, the library should be updated to fix the issue. The following platforms have extra guidelines: - **Diagnostics**: [`platform-diagnostics.md`](platform-diagnostics.md) for diagnostic data collection diff --git a/.github/copilot-instructions.md b/.github/copilot-instructions.md index 07fcd4dc52d..44393a78a3e 100644 --- a/.github/copilot-instructions.md +++ b/.github/copilot-instructions.md @@ -6,6 +6,7 @@ - Start review comments with a short, one-sentence summary of the suggested fix. - Do not comment on code style, formatting or linting issues. +- A Pull Request with a dependency version bump should only contain changes required for the version bump. If the PR includes other changes, request that they are removed from the PR. # GitHub Copilot & Claude Code Instructions @@ -27,12 +28,14 @@ This repository contains the core of Home Assistant, a Python 3 based home autom ## Testing -When writing or modifying tests, ensure all test function parameters have type annotations. -Prefer concrete types (for example, `HomeAssistant`, `MockConfigEntry`, etc.) over `Any`. +- When writing or modifying tests, ensure all test function parameters have type annotations. +- Prefer concrete types (for example, `HomeAssistant`, `MockConfigEntry`, etc.) over `Any`. +- Avoid using conditions/branching in tests. Instead, either split tests or adjust the test parametrization to cover all cases without branching. +- If multiple tests share most of their code, use `pytest.mark.parametrize` to merge them into a single parameterized test instead of duplicating the body. ## Good practices -Integrations with Platinum or Gold level in the Integration Quality Scale reflect a high standard of code quality and maintainability. When looking for examples of something, these are good places to start. The level is indicated in the manifest.json of the integration. - -When reviewing entity actions, do not suggest extra defensive checks for input fields that are already validated by Home Assistant's service/action schemas and entity selection filters. Suggest additional guards only when data bypasses those validators or is transformed into a less-safe form. -When validation guarantees a dict key exists, prefer direct key access (`data["key"]`) instead of `.get("key")` so contract violations are surfaced instead of silently masked. +- Integrations with Platinum or Gold level in the Integration Quality Scale reflect a high standard of code quality and maintainability. When looking for examples of something, these are good places to start. The level is indicated in the manifest.json of the integration. +- When reviewing entity actions, do not suggest extra defensive checks for input fields that are already validated by Home Assistant's service/action schemas and entity selection filters. Suggest additional guards only when data bypasses those validators or is transformed into a less-safe form. +- When validation guarantees a dict key exists, prefer direct key access (`data["key"]`) instead of `.get("key")` so contract violations are surfaced instead of silently masked. +- Do not add comments that just restate the code on the following line(s) (e.g. `# Check if initialized` above `if self.initialized:`). Comments should only explain why — non-obvious constraints, surprising behavior, or workarounds — never what. diff --git a/.github/instructions/integrations.instructions.md b/.github/instructions/integrations.instructions.md index 0d3422cc969..4cbe4e0f18b 100644 --- a/.github/instructions/integrations.instructions.md +++ b/.github/instructions/integrations.instructions.md @@ -18,6 +18,7 @@ excludeAgent: "cloud-agent" - For entity actions and entity services, avoid requesting redundant defensive checks for fields already enforced by Home Assistant validation schemas and entity filters; only request extra guards when values bypass validation or are transformed unsafely. - When validation guarantees a key is present, prefer direct dictionary indexing (`data["key"]`) over `.get("key")` so invalid assumptions fail fast. - Integrations should be thin wrappers. Protocol parsing, device state machines, or other domain logic belong in a separate PyPI library, not in the integration itself. If unsure, ask before inlining. +- Integrations should not implement fixes or workarounds for limitations in libraries. Instead, the library should be updated to fix the issue. The following platforms have extra guidelines: - **Diagnostics**: [`platform-diagnostics.md`](platform-diagnostics.md) for diagnostic data collection diff --git a/AGENTS.md b/AGENTS.md index 596710023bd..bfcddefa342 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -18,12 +18,14 @@ This repository contains the core of Home Assistant, a Python 3 based home autom ## Testing -When writing or modifying tests, ensure all test function parameters have type annotations. -Prefer concrete types (for example, `HomeAssistant`, `MockConfigEntry`, etc.) over `Any`. +- When writing or modifying tests, ensure all test function parameters have type annotations. +- Prefer concrete types (for example, `HomeAssistant`, `MockConfigEntry`, etc.) over `Any`. +- Avoid using conditions/branching in tests. Instead, either split tests or adjust the test parametrization to cover all cases without branching. +- If multiple tests share most of their code, use `pytest.mark.parametrize` to merge them into a single parameterized test instead of duplicating the body. ## Good practices -Integrations with Platinum or Gold level in the Integration Quality Scale reflect a high standard of code quality and maintainability. When looking for examples of something, these are good places to start. The level is indicated in the manifest.json of the integration. - -When reviewing entity actions, do not suggest extra defensive checks for input fields that are already validated by Home Assistant's service/action schemas and entity selection filters. Suggest additional guards only when data bypasses those validators or is transformed into a less-safe form. -When validation guarantees a dict key exists, prefer direct key access (`data["key"]`) instead of `.get("key")` so contract violations are surfaced instead of silently masked. +- Integrations with Platinum or Gold level in the Integration Quality Scale reflect a high standard of code quality and maintainability. When looking for examples of something, these are good places to start. The level is indicated in the manifest.json of the integration. +- When reviewing entity actions, do not suggest extra defensive checks for input fields that are already validated by Home Assistant's service/action schemas and entity selection filters. Suggest additional guards only when data bypasses those validators or is transformed into a less-safe form. +- When validation guarantees a dict key exists, prefer direct key access (`data["key"]`) instead of `.get("key")` so contract violations are surfaced instead of silently masked. +- Do not add comments that just restate the code on the following line(s) (e.g. `# Check if initialized` above `if self.initialized:`). Comments should only explain why — non-obvious constraints, surprising behavior, or workarounds — never what. diff --git a/script/gen_copilot_instructions.py b/script/gen_copilot_instructions.py index a057de587bb..8c8379ab18e 100755 --- a/script/gen_copilot_instructions.py +++ b/script/gen_copilot_instructions.py @@ -25,6 +25,7 @@ COPILOT_SPECIFIC_INSTRUCTIONS = """ - Start review comments with a short, one-sentence summary of the suggested fix. - Do not comment on code style, formatting or linting issues. +- A Pull Request with a dependency version bump should only contain changes required for the version bump. If the PR includes other changes, request that they are removed from the PR. """ INTEGRATION_PATH_SPECIFIC_INSTRUCTIONS = """---