mirror of
https://github.com/home-assistant/core.git
synced 2026-06-30 18:45:58 +02:00
Compare commits
12 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 1d42402735 | |||
| a0d96a2c62 | |||
| eb9ebd17b6 | |||
| 5ea38fcc07 | |||
| 15ef228cfa | |||
| e815c9f0cc | |||
| 434b3ca309 | |||
| a557e96c53 | |||
| 324c95140b | |||
| 1186f153cb | |||
| bc9c270117 | |||
| 8922131056 |
@@ -0,0 +1,98 @@
|
||||
---
|
||||
name: bump-dependency
|
||||
description: Bumps a Python package dependency across Home Assistant Core integrations, regenerates core requirement files, runs verification tests and prek lint, and prepares a pull request with proper release/compare links.
|
||||
---
|
||||
|
||||
# Bump Python Package Dependency in Home Assistant Core
|
||||
|
||||
Follow these systematic steps to successfully bump a python package requirement in the repository, regenerate necessary derivative files, verify the integration, and raise a pull request.
|
||||
|
||||
## Gotchas & Non-Obvious Constraints
|
||||
|
||||
- **PR Template Integrity**: Follow Home Assistant's Pull Request template (`.github/PULL_REQUEST_TEMPLATE.md`) exactly as written, including any instructions inside the template itself. Preserve all sections, comments, and unchecked checkboxes unless the template explicitly says otherwise; the only allowed removal is the **Breaking change** section when the template instructs you to remove it if not applicable.
|
||||
- **GitHub Tag Volatility**: Release tags on GitHub are highly inconsistent (e.g., `v1.2.3` vs `1.2.3` vs `release-1.2.3`). Always use the automated resolver `resolve_dependency.py` to check HEAD status for correct tags before hardcoding comparison URLs.
|
||||
|
||||
## Step-by-Step Workflow Checklist
|
||||
|
||||
### Phase A: Research and Plan
|
||||
- [ ] **1. Identify Targets**: Note the requested target package and target version to bump.
|
||||
- [ ] **2. Discover Codebase References**: Search the codebase to find all `manifest.json` and requirements files referencing the package.
|
||||
- [ ] **3. Resolve Version/Tag Details**: Run the integrated validation helper script to resolve version details, GitHub repo, release tag format, and formatted PR links:
|
||||
```bash
|
||||
uv run python3 ./.claude/skills/bump-dependency/scripts/resolve_dependency.py <package> <old_version> [--new-version <new_version>]
|
||||
```
|
||||
- [ ] **4. Plan-Validate-Execute (Draft Plan)**: Before modifying any files, write a brief, structured plan outlining the integrations to change, old version, new version, and the resolved comparison link. Show this draft plan to the user.
|
||||
|
||||
### Phase B: Execute and Validate (Local Changes)
|
||||
- [ ] **5. Check Uncommitted Changes**: Check for any uncommitted changes in the repository. If they exist, ask the user whether to stash, commit, or discard them before proceeding.
|
||||
- [ ] **6. Git Branch Setup**: Create a clean branch starting from the latest `upstream/dev`:
|
||||
```bash
|
||||
git fetch upstream dev
|
||||
git checkout -b bump-<package>-to-<version> upstream/dev
|
||||
```
|
||||
- [ ] **7. Apply Bump to manifests**: Update the version constraint string in all identified `manifest.json` files (e.g., change `"package==1.0.0"` to `"package==1.1.0"`).
|
||||
- [ ] **8. Regenerate Core Requirements**: Run the requirements generator to update all derivative requirements and constraint files:
|
||||
```bash
|
||||
uv run python3 -m script.gen_requirements_all
|
||||
```
|
||||
- [ ] **9. Validate Requirements**: Check `git diff` to ensure that only the targeted `manifest.json` files and `requirements_all.txt` (and potentially standard constraints) were modified. No unrelated files must be affected.
|
||||
- [ ] **10. Local Venv Verification**: Install the exact targeted package version directly inside the virtual environment:
|
||||
```bash
|
||||
uv pip install "<package>==<version>"
|
||||
```
|
||||
|
||||
### Phase C: Validation Loop (Tests & Lint)
|
||||
- [ ] **11. Run Integration Tests**: Execute the pytest suite for all integrations that consume the bumped package:
|
||||
```bash
|
||||
uv run pytest tests/components/<integration_name>
|
||||
```
|
||||
- *Validation Loop*: If tests fail, analyze the error, apply appropriate fixes, and re-run pytest until all tests pass cleanly.
|
||||
- [ ] **12. Run prek Lint Checks**: Run the local prek hooks on modified files:
|
||||
```bash
|
||||
uv run prek run
|
||||
```
|
||||
- *Validation Loop*: If prek checks report any formatting or linting violations, fix them and repeat `uv run prek run` until it passes completely without errors.
|
||||
|
||||
### Phase D: User Confirmation & PR Creation
|
||||
- [ ] **13. Commit Changes**: Commit the clean changes:
|
||||
```bash
|
||||
git add <modified_files>
|
||||
git commit -m "Bump <package> to <version>"
|
||||
```
|
||||
- [ ] **14. Push Branch**: Push the local branch to your origin remote:
|
||||
```bash
|
||||
git push origin bump-<package>-to-<version>
|
||||
```
|
||||
- [ ] **15. PR Description Preparation**: Generate the pull request body from `.github/PULL_REQUEST_TEMPLATE.md`:
|
||||
- **Proposed change**: Describe the package, old version, new version, target/source branches, and insert the resolved PyPI, changelog, and comparison diff links.
|
||||
- **Type of change**: Check only 1 box in this section, and mark the `Dependency upgrade` checkbox as checked: `[x] Dependency upgrade`.
|
||||
- **Breaking change**: You may remove the "Breaking change" section entirely from the template.
|
||||
- **Validation checklists**: Mark `The code change is tested` checkbox as checked: `[x] The code change is tested`.
|
||||
- **Keep remaining template intact**: Do NOT remove any other commented-out blocks, headers, or unchecked checkboxes in the template.
|
||||
- [ ] **16. Mandatory Review Presentation**: Format the PR proposal using the **PR Presentation Template** below and display it to the user. **Stop and wait for the user to review and explicitly confirm/approve the PR template and draft details before creating the PR.**
|
||||
- [ ] **17. Raise Pull Request**: Once the user approves, create the Pull Request using the GitHub CLI:
|
||||
```bash
|
||||
gh pr create --repo home-assistant/core --base dev --head <username>:bump-<package>-to-<version> --title "Bump <package> to <version>" --body-file <pr_body_file>
|
||||
```
|
||||
|
||||
## PR Presentation Template
|
||||
|
||||
```markdown
|
||||
### 🚀 Dependency Bump Pull Request Draft Review
|
||||
|
||||
- **Package**: `<package_name>` (`<old_version>` → `<new_version>`)
|
||||
- **PR Title**: `Bump <package_name> to <new_version>`
|
||||
- **Target Branch**: `dev`
|
||||
- **Head Branch**: `<fork_username>:bump-<package_name>-to-<new_version>`
|
||||
|
||||
#### 🔗 PyPI & GitHub Links
|
||||
- **PyPI Release**: https://pypi.org/project/<package_name>/<new_version>/
|
||||
- **Changelog Link**: `<changelog_url>`
|
||||
- **Comparison Diff**: `<compare_url>`
|
||||
|
||||
#### 📁 Modified Files
|
||||
- `<list_of_modified_files>`
|
||||
|
||||
#### 📝 Proposed PR Body
|
||||
<render the complete filled PR template body here, showing all checks and modifications for user approval>
|
||||
```
|
||||
@@ -0,0 +1,205 @@
|
||||
#!/usr/bin/env python3
|
||||
# ruff: noqa: T201, D103, BLE001
|
||||
"""Helper script to resolve package details, GitHub repo, release tags, and diff links from PyPI."""
|
||||
|
||||
import argparse
|
||||
import json
|
||||
import re
|
||||
import sys
|
||||
import urllib.error
|
||||
import urllib.parse
|
||||
import urllib.request
|
||||
|
||||
from packaging.version import Version
|
||||
|
||||
_VERSION_MATCH = r"^[a-zA-Z0-9_\-\.\+\!\*]+$"
|
||||
_REPO_MATCH = r"https?://(?:www\.)?github\.com/([^/]+)/([^/]+)"
|
||||
# Project owner or repo name
|
||||
_NAME_MATCH = r"^[a-zA-Z0-9_\-\.]+$"
|
||||
|
||||
|
||||
def get_pypi_data(package_name):
|
||||
# Sanitize and URL-quote the package name to prevent URL path injection
|
||||
safe_package_name = urllib.parse.quote(package_name)
|
||||
url = f"https://pypi.org/pypi/{safe_package_name}/json"
|
||||
req = urllib.request.Request(
|
||||
url,
|
||||
headers={
|
||||
"User-Agent": "HomeAssistant-Skill-Resolver/1.0",
|
||||
"Accept": "application/json",
|
||||
},
|
||||
)
|
||||
try:
|
||||
with urllib.request.urlopen(req, timeout=10) as response:
|
||||
return json.loads(response.read().decode())
|
||||
except urllib.error.HTTPError as e:
|
||||
print(f"Error fetching PyPI data (HTTP {e.code}): {e.reason}", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
except urllib.error.URLError as e:
|
||||
print(f"Network error fetching PyPI data: {e.reason}", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
except Exception as e:
|
||||
print(f"Unexpected error fetching PyPI data: {e}", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
def find_github_repo(info):
|
||||
urls = []
|
||||
if info.get("home_page"):
|
||||
urls.append(info["home_page"])
|
||||
if info.get("project_urls"):
|
||||
urls.extend(info["project_urls"].values())
|
||||
|
||||
for u in urls:
|
||||
if not u:
|
||||
continue
|
||||
cleaned_url = u.replace("git+", "")
|
||||
m = re.search(_REPO_MATCH, cleaned_url, re.IGNORECASE)
|
||||
if m:
|
||||
owner, repo = m.groups()
|
||||
# Strip query parameters, hashes, trailing slashes, and .git extension
|
||||
repo = repo.split("?")[0].split("#")[0].split("/")[0]
|
||||
repo = repo.removesuffix(".git")
|
||||
# Validate that the owner and repo name conform to valid formats,
|
||||
# preventing prompt injection payloads embedded in repository URLs.
|
||||
if re.match(_NAME_MATCH, owner) and re.match(_NAME_MATCH, repo):
|
||||
return f"https://github.com/{owner}/{repo}"
|
||||
return None
|
||||
|
||||
|
||||
def check_github_tag(repo_url, version):
|
||||
# Try with 'v' prefix, without prefix, and with 'release-' prefix
|
||||
tag_options = [f"v{version}", version, f"release-{version}"]
|
||||
for tag in tag_options:
|
||||
# Check both tree and releases paths on GitHub
|
||||
for path_template in [f"tree/{tag}", f"releases/tag/{tag}"]:
|
||||
url = f"{repo_url}/{path_template}"
|
||||
try:
|
||||
req = urllib.request.Request(
|
||||
url,
|
||||
method="HEAD",
|
||||
headers={"User-Agent": "HomeAssistant-Skill-Resolver/1.0"},
|
||||
)
|
||||
with urllib.request.urlopen(req, timeout=10) as resp:
|
||||
if resp.status == 200:
|
||||
return tag
|
||||
except urllib.error.HTTPError as e:
|
||||
# If it's a 404, we continue checking other tag/path options
|
||||
if e.code == 404:
|
||||
continue
|
||||
# For non-404 HTTP errors (like 403 Forbidden/429 rate limit), exit with error to avoid false reports
|
||||
print(
|
||||
f"\n[ERROR] HTTP error contacting GitHub ({e.code} {e.reason}) for tag '{tag}'",
|
||||
file=sys.stderr,
|
||||
)
|
||||
sys.exit(1)
|
||||
except urllib.error.URLError as e:
|
||||
# Connection or timeout error
|
||||
print(
|
||||
f"\n[ERROR] Network error contacting GitHub: {e.reason}",
|
||||
file=sys.stderr,
|
||||
)
|
||||
sys.exit(1)
|
||||
except Exception as e:
|
||||
# Unexpected exceptions
|
||||
print(
|
||||
f"\n[ERROR] Unexpected error verifying tag '{tag}': {e}",
|
||||
file=sys.stderr,
|
||||
)
|
||||
sys.exit(1)
|
||||
return None
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(
|
||||
description="Resolve PyPI package info and GitHub release diffs."
|
||||
)
|
||||
parser.add_argument("package", help="Name of the PyPI package")
|
||||
parser.add_argument(
|
||||
"old_version", help="Current version installed in Home Assistant"
|
||||
)
|
||||
parser.add_argument(
|
||||
"--new-version", help="Target version to bump to (defaults to latest on PyPI)"
|
||||
)
|
||||
args = parser.parse_args()
|
||||
|
||||
if not re.match(_NAME_MATCH, args.package):
|
||||
print(f"[ERROR] Invalid package name format: '{args.package}'", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
if not re.match(_VERSION_MATCH, args.old_version):
|
||||
print(
|
||||
f"[ERROR] Invalid old version format: '{args.old_version}'", file=sys.stderr
|
||||
)
|
||||
sys.exit(1)
|
||||
|
||||
if args.new_version and not re.match(_VERSION_MATCH, args.new_version):
|
||||
print(
|
||||
f"[ERROR] Invalid target version format: '{args.new_version}'",
|
||||
file=sys.stderr,
|
||||
)
|
||||
sys.exit(1)
|
||||
|
||||
data = get_pypi_data(args.package)
|
||||
info = data.get("info", {})
|
||||
|
||||
# Filter out pre-releases from the releases list to identify the latest stable version
|
||||
stable_versions = []
|
||||
for v in data.get("releases", {}):
|
||||
try:
|
||||
ver = Version(v)
|
||||
if not ver.is_prerelease:
|
||||
stable_versions.append(ver)
|
||||
except Exception:
|
||||
continue
|
||||
latest = str(max(stable_versions)) if stable_versions else info.get("version")
|
||||
|
||||
if latest and not re.match(_VERSION_MATCH, latest):
|
||||
print("[ERROR] Invalid latest version resolved from PyPI.", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
target_version = args.new_version or latest
|
||||
if not target_version:
|
||||
print("[ERROR] Could not resolve a target version from PyPI.", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
github_repo = find_github_repo(info)
|
||||
|
||||
print("--- RESOLVED DEPENDENCY DETAILS ---")
|
||||
print(f"Package: {args.package}")
|
||||
print(f"Current Version: {args.old_version}")
|
||||
print(f"Latest (PyPI): {latest}")
|
||||
print(f"Target Version: {target_version}")
|
||||
|
||||
if github_repo:
|
||||
print(f"GitHub Repository: {github_repo}")
|
||||
|
||||
# Verify tag formats on GitHub
|
||||
old_tag = check_github_tag(github_repo, args.old_version)
|
||||
new_tag = check_github_tag(github_repo, target_version)
|
||||
|
||||
if not old_tag or not new_tag:
|
||||
missing_tags = []
|
||||
if not old_tag:
|
||||
missing_tags.append(args.old_version)
|
||||
if not new_tag:
|
||||
missing_tags.append(target_version)
|
||||
print(
|
||||
f"\n[ERROR] Could not resolve GitHub release tag for version(s): {', '.join(missing_tags)}",
|
||||
file=sys.stderr,
|
||||
)
|
||||
sys.exit(1)
|
||||
|
||||
changelog_url = f"{github_repo}/releases/tag/{new_tag}"
|
||||
compare_url = f"{github_repo}/compare/{old_tag}...{new_tag}"
|
||||
|
||||
print("\n--- PR DOCUMENTATION LINKS ---")
|
||||
print(f"Changelog Link: {changelog_url}")
|
||||
print(f"Comparison Diff Link: {compare_url}")
|
||||
else:
|
||||
print("\n[WARNING] GitHub repository could not be resolved from PyPI metadata.")
|
||||
print("Please resolve the release notes and diff links manually.")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -14,7 +14,7 @@ env:
|
||||
UV_HTTP_TIMEOUT: 60
|
||||
UV_SYSTEM_PYTHON: "true"
|
||||
# Base image version from https://github.com/home-assistant/docker
|
||||
BASE_IMAGE_VERSION: "2026.05.0"
|
||||
BASE_IMAGE_VERSION: "2026.07.0"
|
||||
ARCHITECTURES: '["amd64", "aarch64"]'
|
||||
|
||||
permissions: {}
|
||||
@@ -43,7 +43,7 @@ jobs:
|
||||
persist-credentials: false
|
||||
|
||||
- name: Set up Python
|
||||
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
|
||||
uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 # v6.3.0
|
||||
with:
|
||||
python-version-file: ".python-version"
|
||||
|
||||
@@ -130,7 +130,7 @@ jobs:
|
||||
|
||||
- name: Set up Python
|
||||
if: needs.init.outputs.channel == 'dev'
|
||||
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
|
||||
uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 # v6.3.0
|
||||
with:
|
||||
python-version-file: ".python-version"
|
||||
|
||||
@@ -474,7 +474,7 @@ jobs:
|
||||
persist-credentials: false
|
||||
|
||||
- name: Set up Python
|
||||
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
|
||||
uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 # v6.3.0
|
||||
with:
|
||||
python-version-file: ".python-version"
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ jobs:
|
||||
with:
|
||||
persist-credentials: false
|
||||
- name: Set up Python
|
||||
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
|
||||
uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 # v6.3.0
|
||||
with:
|
||||
python-version-file: ".python-version"
|
||||
check-latest: true
|
||||
|
||||
+13
-13
@@ -346,7 +346,7 @@ jobs:
|
||||
persist-credentials: false
|
||||
- name: Set up Python ${{ matrix.python-version }}
|
||||
id: python
|
||||
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
|
||||
uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 # v6.3.0
|
||||
with:
|
||||
python-version: ${{ matrix.python-version }}
|
||||
check-latest: true
|
||||
@@ -480,7 +480,7 @@ jobs:
|
||||
version: ${{ env.APT_CACHE_VERSION }}
|
||||
- name: Set up Python
|
||||
id: python
|
||||
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
|
||||
uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 # v6.3.0
|
||||
with:
|
||||
python-version-file: ".python-version"
|
||||
check-latest: true
|
||||
@@ -517,7 +517,7 @@ jobs:
|
||||
persist-credentials: false
|
||||
- name: Set up Python
|
||||
id: python
|
||||
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
|
||||
uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 # v6.3.0
|
||||
with:
|
||||
python-version-file: ".python-version"
|
||||
check-latest: true
|
||||
@@ -553,7 +553,7 @@ jobs:
|
||||
persist-credentials: false
|
||||
- name: Set up Python
|
||||
id: python
|
||||
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
|
||||
uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 # v6.3.0
|
||||
with:
|
||||
python-version-file: ".python-version"
|
||||
check-latest: true
|
||||
@@ -608,7 +608,7 @@ jobs:
|
||||
persist-credentials: false
|
||||
- name: Set up Python ${{ matrix.python-version }}
|
||||
id: python
|
||||
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
|
||||
uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 # v6.3.0
|
||||
with:
|
||||
python-version: ${{ matrix.python-version }}
|
||||
check-latest: true
|
||||
@@ -659,7 +659,7 @@ jobs:
|
||||
persist-credentials: false
|
||||
- name: Set up Python
|
||||
id: python
|
||||
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
|
||||
uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 # v6.3.0
|
||||
with:
|
||||
python-version-file: ".python-version"
|
||||
check-latest: true
|
||||
@@ -712,7 +712,7 @@ jobs:
|
||||
persist-credentials: false
|
||||
- name: Set up Python
|
||||
id: python
|
||||
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
|
||||
uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 # v6.3.0
|
||||
with:
|
||||
python-version-file: ".python-version"
|
||||
check-latest: true
|
||||
@@ -763,7 +763,7 @@ jobs:
|
||||
persist-credentials: false
|
||||
- name: Set up Python
|
||||
id: python
|
||||
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
|
||||
uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 # v6.3.0
|
||||
with:
|
||||
python-version-file: ".python-version"
|
||||
check-latest: true
|
||||
@@ -840,7 +840,7 @@ jobs:
|
||||
execute_install_scripts: true
|
||||
- name: Set up Python
|
||||
id: python
|
||||
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
|
||||
uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 # v6.3.0
|
||||
with:
|
||||
python-version-file: ".python-version"
|
||||
check-latest: true
|
||||
@@ -905,7 +905,7 @@ jobs:
|
||||
execute_install_scripts: true
|
||||
- name: Set up Python ${{ matrix.python-version }}
|
||||
id: python
|
||||
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
|
||||
uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 # v6.3.0
|
||||
with:
|
||||
python-version: ${{ matrix.python-version }}
|
||||
check-latest: true
|
||||
@@ -1047,7 +1047,7 @@ jobs:
|
||||
execute_install_scripts: true
|
||||
- name: Set up Python ${{ matrix.python-version }}
|
||||
id: python
|
||||
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
|
||||
uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 # v6.3.0
|
||||
with:
|
||||
python-version: ${{ matrix.python-version }}
|
||||
check-latest: true
|
||||
@@ -1203,7 +1203,7 @@ jobs:
|
||||
version: ${{ env.APT_CACHE_VERSION }}
|
||||
- name: Set up Python ${{ matrix.python-version }}
|
||||
id: python
|
||||
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
|
||||
uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 # v6.3.0
|
||||
with:
|
||||
python-version: ${{ matrix.python-version }}
|
||||
check-latest: true
|
||||
@@ -1371,7 +1371,7 @@ jobs:
|
||||
execute_install_scripts: true
|
||||
- name: Set up Python ${{ matrix.python-version }}
|
||||
id: python
|
||||
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
|
||||
uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 # v6.3.0
|
||||
with:
|
||||
python-version: ${{ matrix.python-version }}
|
||||
check-latest: true
|
||||
|
||||
@@ -27,7 +27,7 @@ jobs:
|
||||
persist-credentials: false
|
||||
|
||||
- name: Set up Python
|
||||
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
|
||||
uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 # v6.3.0
|
||||
with:
|
||||
python-version-file: ".python-version"
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ jobs:
|
||||
|
||||
- name: Set up Python
|
||||
id: python
|
||||
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
|
||||
uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 # v6.3.0
|
||||
with:
|
||||
python-version-file: ".python-version"
|
||||
check-latest: true
|
||||
@@ -137,7 +137,7 @@ jobs:
|
||||
sed -i "/uv/d" requirements_diff.txt
|
||||
|
||||
- name: Build wheels
|
||||
uses: home-assistant/wheels@34957438948e0b3dcde73c77750643dadae594f5 # 2026.06.0
|
||||
uses: home-assistant/wheels@9e17ab1ed5c4c79d8b61e29fa63de25ca2710716 # 2026.07.0
|
||||
with:
|
||||
abi: ${{ matrix.abi }}
|
||||
tag: musllinux_1_2
|
||||
@@ -195,7 +195,7 @@ jobs:
|
||||
sed -i "/uv/d" requirements_diff.txt
|
||||
|
||||
- name: Build wheels
|
||||
uses: home-assistant/wheels@34957438948e0b3dcde73c77750643dadae594f5 # 2026.06.0
|
||||
uses: home-assistant/wheels@9e17ab1ed5c4c79d8b61e29fa63de25ca2710716 # 2026.07.0
|
||||
with:
|
||||
abi: ${{ matrix.abi }}
|
||||
tag: musllinux_1_2
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
"iot_class": "local_polling",
|
||||
"loggers": ["pyenphase"],
|
||||
"quality_scale": "platinum",
|
||||
"requirements": ["pyenphase==3.0.0"],
|
||||
"requirements": ["pyenphase==3.0.1"],
|
||||
"zeroconf": [
|
||||
{
|
||||
"type": "_enphase-envoy._tcp.local."
|
||||
|
||||
@@ -27,25 +27,6 @@
|
||||
"state": {
|
||||
"2d_fix": "2D Fix",
|
||||
"3d_fix": "3D Fix"
|
||||
},
|
||||
"state_attributes": {
|
||||
"climb": {
|
||||
"name": "[%key:component::gpsd::entity::sensor::climb::name%]"
|
||||
},
|
||||
"elevation": {
|
||||
"name": "[%key:common::config_flow::data::elevation%]"
|
||||
},
|
||||
"gps_time": {
|
||||
"name": "[%key:component::time_date::selector::display_options::options::time%]"
|
||||
},
|
||||
"latitude": { "name": "[%key:common::config_flow::data::latitude%]" },
|
||||
"longitude": {
|
||||
"name": "[%key:common::config_flow::data::longitude%]"
|
||||
},
|
||||
"mode": { "name": "[%key:common::config_flow::data::mode%]" },
|
||||
"speed": {
|
||||
"name": "[%key:component::sensor::entity_component::speed::name%]"
|
||||
}
|
||||
}
|
||||
},
|
||||
"time": {
|
||||
|
||||
@@ -227,8 +227,8 @@ class MikrotikData:
|
||||
_LOGGER.debug("Running command %s", cmd)
|
||||
try:
|
||||
if params:
|
||||
return list(self.api(cmd=cmd, **params))
|
||||
return list(self.api(cmd=cmd))
|
||||
return list(self.api(cmd, **params))
|
||||
return list(self.api(cmd))
|
||||
except (
|
||||
librouteros.exceptions.ConnectionClosed,
|
||||
OSError,
|
||||
@@ -318,8 +318,7 @@ def get_api(entry: dict[str, Any]) -> librouteros.Api:
|
||||
"""Connect to Mikrotik hub."""
|
||||
_LOGGER.debug("Connecting to Mikrotik hub [%s]", entry[CONF_HOST])
|
||||
|
||||
_login_method = (login_plain, login_token)
|
||||
kwargs = {"login_methods": _login_method, "port": entry["port"], "encoding": "utf8"}
|
||||
kwargs = {"port": entry["port"], "encoding": "utf8"}
|
||||
|
||||
if entry[CONF_VERIFY_SSL]:
|
||||
ssl_context = ssl.create_default_context()
|
||||
@@ -328,22 +327,30 @@ def get_api(entry: dict[str, Any]) -> librouteros.Api:
|
||||
_ssl_wrapper = ssl_context.wrap_socket
|
||||
kwargs["ssl_wrapper"] = _ssl_wrapper
|
||||
|
||||
try:
|
||||
api = librouteros.connect(
|
||||
entry[CONF_HOST],
|
||||
entry[CONF_USERNAME],
|
||||
entry[CONF_PASSWORD],
|
||||
**kwargs,
|
||||
)
|
||||
except (
|
||||
librouteros.exceptions.LibRouterosError,
|
||||
OSError,
|
||||
TimeoutError,
|
||||
) as api_error:
|
||||
_LOGGER.error("Mikrotik %s error: %s", entry[CONF_HOST], api_error)
|
||||
if "invalid user name or password" in str(api_error):
|
||||
raise LoginError from api_error
|
||||
raise CannotConnect from api_error
|
||||
_error: Exception | None = None
|
||||
for method in (login_plain, login_token):
|
||||
try:
|
||||
kwargs["login_method"] = method
|
||||
api = librouteros.connect(
|
||||
entry[CONF_HOST],
|
||||
entry[CONF_USERNAME],
|
||||
entry[CONF_PASSWORD],
|
||||
**kwargs,
|
||||
)
|
||||
_error = None
|
||||
break
|
||||
except (
|
||||
librouteros.exceptions.LibRouterosError,
|
||||
OSError,
|
||||
TimeoutError,
|
||||
) as api_error:
|
||||
_error = api_error
|
||||
|
||||
if _error is not None:
|
||||
_LOGGER.error("Mikrotik %s error: %s", entry[CONF_HOST], _error)
|
||||
if "invalid user name or password" in str(_error):
|
||||
raise LoginError from _error
|
||||
raise CannotConnect from _error
|
||||
|
||||
_LOGGER.debug("Connected to %s successfully", entry[CONF_HOST])
|
||||
return api
|
||||
|
||||
@@ -7,5 +7,5 @@
|
||||
"integration_type": "device",
|
||||
"iot_class": "local_polling",
|
||||
"loggers": ["librouteros"],
|
||||
"requirements": ["librouteros==3.2.1"]
|
||||
"requirements": ["librouteros==4.1.1"]
|
||||
}
|
||||
|
||||
@@ -71,7 +71,6 @@ from .const import (
|
||||
DEFAULT_QOS,
|
||||
DEFAULT_TRANSPORT,
|
||||
DEFAULT_WILL,
|
||||
DEFAULT_WS_HEADERS,
|
||||
DEFAULT_WS_PATH,
|
||||
DOMAIN,
|
||||
MQTT_CONNECTION_STATE,
|
||||
@@ -414,7 +413,7 @@ class MqttClientSetup:
|
||||
tls_insecure = config.get(CONF_TLS_INSECURE)
|
||||
if transport == TRANSPORT_WEBSOCKETS:
|
||||
ws_path: str = config.get(CONF_WS_PATH, DEFAULT_WS_PATH)
|
||||
ws_headers: dict[str, str] = config.get(CONF_WS_HEADERS, DEFAULT_WS_HEADERS)
|
||||
ws_headers: dict[str, str] = config.get(CONF_WS_HEADERS, {})
|
||||
self._client.ws_set_options(ws_path, ws_headers)
|
||||
if certificate is not None:
|
||||
self._client.tls_set(
|
||||
|
||||
@@ -373,7 +373,6 @@ from .const import (
|
||||
DEFAULT_CLIMATE_INITIAL_TEMPERATURE,
|
||||
DEFAULT_DISCOVERY,
|
||||
DEFAULT_ENCODING,
|
||||
DEFAULT_KEEPALIVE,
|
||||
DEFAULT_ON_COMMAND_TYPE,
|
||||
DEFAULT_PAYLOAD_ARM_AWAY,
|
||||
DEFAULT_PAYLOAD_ARM_CUSTOM_BYPASS,
|
||||
@@ -414,7 +413,6 @@ from .const import (
|
||||
DEFAULT_TILT_OPEN_POSITION,
|
||||
DEFAULT_TRANSPORT,
|
||||
DEFAULT_WILL,
|
||||
DEFAULT_WS_PATH,
|
||||
DOMAIN,
|
||||
REMOTE_CODE,
|
||||
REMOTE_CODE_TEXT,
|
||||
@@ -441,7 +439,7 @@ ADDON_SETUP_TIMEOUT_ROUNDS = 5
|
||||
|
||||
CONF_CLIENT_KEY_PASSWORD = "client_key_password"
|
||||
|
||||
ADVANCED_OPTIONS = "advanced_options"
|
||||
OTHER_SETTINGS = "other_settings"
|
||||
SET_CA_CERT = "set_ca_cert"
|
||||
SET_CLIENT_CERT = "set_client_cert"
|
||||
|
||||
@@ -1124,7 +1122,7 @@ def validate_light_platform_config(user_data: dict[str, Any]) -> dict[str, str]:
|
||||
if user_data.get(CONF_MIN_KELVIN, DEFAULT_MIN_KELVIN) >= user_data.get(
|
||||
CONF_MAX_KELVIN, DEFAULT_MAX_KELVIN
|
||||
):
|
||||
errors["other_settings"] = "max_below_min_kelvin"
|
||||
errors[OTHER_SETTINGS] = "max_below_min_kelvin"
|
||||
return errors
|
||||
|
||||
|
||||
@@ -1506,7 +1504,7 @@ PLATFORM_ENTITY_FIELDS: dict[Platform, dict[str, PlatformField]] = {
|
||||
selector=SUGGESTED_DISPLAY_PRECISION_SELECTOR,
|
||||
required=False,
|
||||
validator=cv.positive_int,
|
||||
section="other_settings",
|
||||
section=OTHER_SETTINGS,
|
||||
),
|
||||
CONF_OPTIONS: PlatformField(
|
||||
selector=OPTIONS_SELECTOR,
|
||||
@@ -1678,13 +1676,13 @@ PLATFORM_MQTT_FIELDS: dict[Platform, dict[str, PlatformField]] = {
|
||||
selector=TIMEOUT_SELECTOR,
|
||||
required=False,
|
||||
validator=cv.positive_int,
|
||||
section="other_settings",
|
||||
section=OTHER_SETTINGS,
|
||||
),
|
||||
CONF_OFF_DELAY: PlatformField(
|
||||
selector=TIMEOUT_SELECTOR,
|
||||
required=False,
|
||||
validator=cv.positive_int,
|
||||
section="other_settings",
|
||||
section=OTHER_SETTINGS,
|
||||
),
|
||||
},
|
||||
Platform.BUTTON: {
|
||||
@@ -3125,7 +3123,7 @@ PLATFORM_MQTT_FIELDS: dict[Platform, dict[str, PlatformField]] = {
|
||||
default=False,
|
||||
validator=cv.boolean,
|
||||
conditions=({CONF_SCHEMA: "json"},),
|
||||
section="other_settings",
|
||||
section=OTHER_SETTINGS,
|
||||
),
|
||||
CONF_FLASH_TIME_SHORT: PlatformField(
|
||||
selector=FLASH_TIME_SELECTOR,
|
||||
@@ -3133,7 +3131,7 @@ PLATFORM_MQTT_FIELDS: dict[Platform, dict[str, PlatformField]] = {
|
||||
validator=cv.positive_int,
|
||||
default=2,
|
||||
conditions=({CONF_SCHEMA: "json"},),
|
||||
section="other_settings",
|
||||
section=OTHER_SETTINGS,
|
||||
),
|
||||
CONF_FLASH_TIME_LONG: PlatformField(
|
||||
selector=FLASH_TIME_SELECTOR,
|
||||
@@ -3141,7 +3139,7 @@ PLATFORM_MQTT_FIELDS: dict[Platform, dict[str, PlatformField]] = {
|
||||
validator=cv.positive_int,
|
||||
default=10,
|
||||
conditions=({CONF_SCHEMA: "json"},),
|
||||
section="other_settings",
|
||||
section=OTHER_SETTINGS,
|
||||
),
|
||||
CONF_TRANSITION: PlatformField(
|
||||
selector=BOOLEAN_SELECTOR,
|
||||
@@ -3149,21 +3147,21 @@ PLATFORM_MQTT_FIELDS: dict[Platform, dict[str, PlatformField]] = {
|
||||
default=False,
|
||||
validator=cv.boolean,
|
||||
conditions=({CONF_SCHEMA: "json"},),
|
||||
section="other_settings",
|
||||
section=OTHER_SETTINGS,
|
||||
),
|
||||
CONF_MAX_KELVIN: PlatformField(
|
||||
selector=KELVIN_SELECTOR,
|
||||
required=False,
|
||||
validator=cv.positive_int,
|
||||
default=DEFAULT_MAX_KELVIN,
|
||||
section="other_settings",
|
||||
section=OTHER_SETTINGS,
|
||||
),
|
||||
CONF_MIN_KELVIN: PlatformField(
|
||||
selector=KELVIN_SELECTOR,
|
||||
required=False,
|
||||
validator=cv.positive_int,
|
||||
default=DEFAULT_MIN_KELVIN,
|
||||
section="other_settings",
|
||||
section=OTHER_SETTINGS,
|
||||
),
|
||||
},
|
||||
Platform.LOCK: {
|
||||
@@ -3372,7 +3370,7 @@ PLATFORM_MQTT_FIELDS: dict[Platform, dict[str, PlatformField]] = {
|
||||
selector=TIMEOUT_SELECTOR,
|
||||
required=False,
|
||||
validator=cv.positive_int,
|
||||
section="other_settings",
|
||||
section=OTHER_SETTINGS,
|
||||
),
|
||||
},
|
||||
Platform.SIREN: {
|
||||
@@ -3798,10 +3796,10 @@ PLATFORM_MQTT_FIELDS: dict[Platform, dict[str, PlatformField]] = {
|
||||
MQTT_DEVICE_PLATFORM_FIELDS = {
|
||||
CONF_NAME: PlatformField(selector=TEXT_SELECTOR, required=True),
|
||||
CONF_SW_VERSION: PlatformField(
|
||||
selector=TEXT_SELECTOR, required=False, section="other_settings"
|
||||
selector=TEXT_SELECTOR, required=False, section=OTHER_SETTINGS
|
||||
),
|
||||
CONF_HW_VERSION: PlatformField(
|
||||
selector=TEXT_SELECTOR, required=False, section="other_settings"
|
||||
selector=TEXT_SELECTOR, required=False, section=OTHER_SETTINGS
|
||||
),
|
||||
CONF_MODEL: PlatformField(selector=TEXT_SELECTOR, required=False),
|
||||
CONF_MODEL_ID: PlatformField(selector=TEXT_SELECTOR, required=False),
|
||||
@@ -4036,24 +4034,22 @@ def subentry_schema_default_data_from_fields(
|
||||
@callback
|
||||
def update_password_from_user_input(
|
||||
entry_password: str | None, user_input: dict[str, Any]
|
||||
) -> dict[str, Any]:
|
||||
) -> None:
|
||||
"""Update the password if the entry has been updated.
|
||||
|
||||
As we want to avoid reflecting the stored password in the UI,
|
||||
we replace the suggested value in the UI with a sentitel,
|
||||
and we change it back here if it was changed.
|
||||
"""
|
||||
substituted_used_data = dict(user_input)
|
||||
# Take out the password submitted
|
||||
user_password: str | None = substituted_used_data.pop(CONF_PASSWORD, None)
|
||||
user_password: str | None = user_input.pop(CONF_PASSWORD, None)
|
||||
# Only add the password if it has changed.
|
||||
# If the sentinel password is submitted, we replace that with our current
|
||||
# password from the config entry data.
|
||||
password_changed = user_password is not None and user_password != PWD_NOT_CHANGED
|
||||
password = user_password if password_changed else entry_password
|
||||
if password is not None:
|
||||
substituted_used_data[CONF_PASSWORD] = password
|
||||
return substituted_used_data
|
||||
user_input[CONF_PASSWORD] = password
|
||||
|
||||
|
||||
REAUTH_SCHEMA = vol.Schema(
|
||||
@@ -4063,6 +4059,35 @@ REAUTH_SCHEMA = vol.Schema(
|
||||
}
|
||||
)
|
||||
|
||||
OTHER_SETTINGS_SCHEMA = vol.Schema(
|
||||
{
|
||||
vol.Optional(CONF_CLIENT_ID): TEXT_SELECTOR,
|
||||
vol.Optional(CONF_KEEPALIVE): KEEPALIVE_SELECTOR,
|
||||
vol.Required(SET_CLIENT_CERT): BOOLEAN_SELECTOR,
|
||||
vol.Optional(CONF_CLIENT_CERT): CERT_UPLOAD_SELECTOR,
|
||||
vol.Optional(CONF_CLIENT_KEY): CERT_KEY_UPLOAD_SELECTOR,
|
||||
vol.Optional(CONF_CLIENT_KEY_PASSWORD): PASSWORD_SELECTOR,
|
||||
vol.Required(SET_CA_CERT): BROKER_VERIFICATION_SELECTOR,
|
||||
vol.Optional(CONF_CERTIFICATE): CA_CERT_UPLOAD_SELECTOR,
|
||||
vol.Optional(CONF_TLS_INSECURE): BOOLEAN_SELECTOR,
|
||||
vol.Required(CONF_TRANSPORT, default=DEFAULT_TRANSPORT): TRANSPORT_SELECTOR,
|
||||
vol.Optional(CONF_WS_PATH): TEXT_SELECTOR,
|
||||
vol.Optional(CONF_WS_HEADERS): WS_HEADERS_SELECTOR,
|
||||
}
|
||||
)
|
||||
CONFIG_DATAFLOW_SCHEMA = vol.Schema(
|
||||
{
|
||||
vol.Required(CONF_BROKER): TEXT_SELECTOR,
|
||||
vol.Required(CONF_PORT, default=DEFAULT_PORT): PORT_SELECTOR,
|
||||
vol.Required(CONF_PROTOCOL, default=DEFAULT_PROTOCOL): PROTOCOL_SELECTOR,
|
||||
vol.Optional(CONF_USERNAME): TEXT_SELECTOR,
|
||||
vol.Optional(CONF_PASSWORD): PASSWORD_SELECTOR,
|
||||
vol.Required(OTHER_SETTINGS): section(
|
||||
OTHER_SETTINGS_SCHEMA, SectionConfig({"collapsed": True})
|
||||
),
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
class FlowHandler(ConfigFlow, domain=DOMAIN):
|
||||
"""Handle a config flow."""
|
||||
@@ -4072,24 +4097,26 @@ class FlowHandler(ConfigFlow, domain=DOMAIN):
|
||||
|
||||
_hassio_discovery: dict[str, Any] | None = None
|
||||
_addon_manager: AddonManager
|
||||
last_uploaded: dict[str, Any]
|
||||
|
||||
def __init__(self) -> None:
|
||||
"""Set up flow instance."""
|
||||
self.install_task: asyncio.Task | None = None
|
||||
self.start_task: asyncio.Task | None = None
|
||||
self.last_uploaded = {}
|
||||
|
||||
@override
|
||||
@classmethod
|
||||
@callback
|
||||
@override
|
||||
def async_get_supported_subentry_types(
|
||||
cls, config_entry: ConfigEntry
|
||||
) -> dict[str, type[ConfigSubentryFlow]]:
|
||||
"""Return subentries supported by this handler."""
|
||||
return {CONF_DEVICE: MQTTSubentryFlowHandler}
|
||||
|
||||
@override
|
||||
@staticmethod
|
||||
@callback
|
||||
@override
|
||||
def async_get_options_flow(
|
||||
config_entry: ConfigEntry,
|
||||
) -> MQTTOptionsFlowHandler:
|
||||
@@ -4310,8 +4337,9 @@ class FlowHandler(ConfigFlow, domain=DOMAIN):
|
||||
|
||||
reauth_entry = self._get_reauth_entry()
|
||||
if user_input:
|
||||
substituted_used_data = update_password_from_user_input(
|
||||
reauth_entry.data.get(CONF_PASSWORD), user_input
|
||||
substituted_used_data = deepcopy(user_input)
|
||||
update_password_from_user_input(
|
||||
reauth_entry.data.get(CONF_PASSWORD), substituted_used_data
|
||||
)
|
||||
new_entry_data = {**reauth_entry.data, **substituted_used_data}
|
||||
if await self.hass.async_add_executor_job(
|
||||
@@ -4335,49 +4363,76 @@ class FlowHandler(ConfigFlow, domain=DOMAIN):
|
||||
errors=errors,
|
||||
)
|
||||
|
||||
@callback
|
||||
def async_get_entry_defaults(self) -> dict[str, Any]:
|
||||
"""Load the default settings from the entry."""
|
||||
data = self._get_reconfigure_entry().data
|
||||
other_settings: dict[str, Any] = {
|
||||
key.schema: data[key.schema]
|
||||
for key in OTHER_SETTINGS_SCHEMA.schema
|
||||
if key in data
|
||||
}
|
||||
other_settings[SET_CLIENT_CERT] = (CONF_CLIENT_CERT in other_settings) and (
|
||||
CONF_CLIENT_KEY in other_settings
|
||||
)
|
||||
other_settings.pop(CONF_CLIENT_CERT, None)
|
||||
other_settings.pop(CONF_CLIENT_KEY, None)
|
||||
conf_cert = other_settings.pop(CONF_CERTIFICATE, None)
|
||||
other_settings[SET_CA_CERT] = (
|
||||
"auto"
|
||||
if conf_cert == "auto"
|
||||
else "custom"
|
||||
if conf_cert is not None
|
||||
else "off"
|
||||
)
|
||||
if CONF_WS_HEADERS in other_settings:
|
||||
other_settings[CONF_WS_HEADERS] = json_dumps(
|
||||
other_settings.pop(CONF_WS_HEADERS)
|
||||
)
|
||||
|
||||
settings: dict[str, Any] = {
|
||||
key.schema: data[key.schema]
|
||||
for key in CONFIG_DATAFLOW_SCHEMA.schema
|
||||
if key in data
|
||||
}
|
||||
settings[OTHER_SETTINGS] = other_settings
|
||||
if CONF_PASSWORD in settings:
|
||||
# Hide entry password
|
||||
settings[CONF_PASSWORD] = PWD_NOT_CHANGED
|
||||
return settings
|
||||
|
||||
async def async_step_broker(
|
||||
self, user_input: dict[str, Any] | None = None
|
||||
) -> ConfigFlowResult:
|
||||
"""Confirm the setup."""
|
||||
errors: dict[str, str] = {}
|
||||
fields: OrderedDict[Any, Any] = OrderedDict()
|
||||
validated_user_input: dict[str, Any] = {}
|
||||
schema = CONFIG_DATAFLOW_SCHEMA
|
||||
entry_config_update: dict[str, Any] = {}
|
||||
entry_defaults: dict[str, Any] | None = None
|
||||
if is_reconfigure := (self.source == SOURCE_RECONFIGURE):
|
||||
reconfigure_entry = self._get_reconfigure_entry()
|
||||
if await async_get_broker_settings(
|
||||
entry_defaults = self.async_get_entry_defaults()
|
||||
if await async_validate_broker_settings(
|
||||
self,
|
||||
fields,
|
||||
reconfigure_entry.data if is_reconfigure else None,
|
||||
user_input,
|
||||
validated_user_input,
|
||||
entry_config_update,
|
||||
errors,
|
||||
):
|
||||
if is_reconfigure:
|
||||
validated_user_input = update_password_from_user_input(
|
||||
reconfigure_entry.data.get(CONF_PASSWORD), validated_user_input
|
||||
return self.async_update_and_abort(
|
||||
reconfigure_entry,
|
||||
data=entry_config_update,
|
||||
)
|
||||
|
||||
can_connect = await self.hass.async_add_executor_job(
|
||||
try_connection,
|
||||
validated_user_input,
|
||||
return self.async_create_entry(
|
||||
title=entry_config_update[CONF_BROKER],
|
||||
data=entry_config_update,
|
||||
)
|
||||
|
||||
if can_connect:
|
||||
if is_reconfigure:
|
||||
return self.async_update_and_abort(
|
||||
reconfigure_entry,
|
||||
data=validated_user_input,
|
||||
)
|
||||
return self.async_create_entry(
|
||||
title=validated_user_input[CONF_BROKER],
|
||||
data=validated_user_input,
|
||||
)
|
||||
|
||||
errors["base"] = "cannot_connect"
|
||||
|
||||
return self.async_show_form(
|
||||
step_id="broker", data_schema=vol.Schema(fields), errors=errors
|
||||
schema = self.add_suggested_values_to_schema(
|
||||
schema, (entry_defaults or {}) | (user_input or {})
|
||||
)
|
||||
return self.async_show_form(step_id="broker", data_schema=schema, errors=errors)
|
||||
|
||||
async def async_step_reconfigure(
|
||||
self, user_input: dict[str, Any] | None = None
|
||||
@@ -4688,8 +4743,8 @@ class MQTTSubentryFlowHandler(ConfigSubentryFlow):
|
||||
if user_input is not None:
|
||||
new_device_data: dict[str, Any] = user_input.copy()
|
||||
_, errors = validate_user_input(user_input, MQTT_DEVICE_PLATFORM_FIELDS)
|
||||
if "other_settings" in new_device_data:
|
||||
new_device_data |= new_device_data.pop("other_settings")
|
||||
if OTHER_SETTINGS in new_device_data:
|
||||
new_device_data |= new_device_data.pop(OTHER_SETTINGS)
|
||||
if not errors:
|
||||
self._subentry_data[CONF_DEVICE] = cast(MqttDeviceData, new_device_data)
|
||||
if self.source == SOURCE_RECONFIGURE:
|
||||
@@ -5250,331 +5305,162 @@ async def _get_uploaded_file(hass: HomeAssistant, id: str) -> bytes:
|
||||
return await hass.async_add_executor_job(_proces_uploaded_file)
|
||||
|
||||
|
||||
def _validate_pki_file(
|
||||
file_id: str | None, pem_data: str | None, errors: dict[str, str], error: str
|
||||
) -> bool:
|
||||
"""Return False if uploaded file could not be converted to PEM format."""
|
||||
if file_id and not pem_data:
|
||||
errors["base"] = error
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
async def async_get_broker_settings(
|
||||
flow: ConfigFlow | OptionsFlow,
|
||||
fields: OrderedDict[Any, Any],
|
||||
async def async_validate_broker_settings(
|
||||
flow: FlowHandler,
|
||||
entry_config: MappingProxyType[str, Any] | None,
|
||||
user_input: dict[str, Any] | None,
|
||||
validated_user_input: dict[str, Any],
|
||||
entry_config_update: dict[str, Any],
|
||||
errors: dict[str, str],
|
||||
) -> bool:
|
||||
"""Build the config flow schema to collect the broker settings.
|
||||
"""Validate the broker settings, and return the updated entry dataset."""
|
||||
|
||||
Shows advanced options if one or more are configured
|
||||
or when the advanced_broker_options checkbox was selected.
|
||||
Returns True when settings are collected successfully.
|
||||
"""
|
||||
hass = flow.hass
|
||||
advanced_broker_options: bool = False
|
||||
user_input_basic: dict[str, Any] = {}
|
||||
current_config: dict[str, Any] = (
|
||||
entry_config.copy() if entry_config is not None else {}
|
||||
)
|
||||
|
||||
async def _async_validate_broker_settings(
|
||||
config: dict[str, Any],
|
||||
user_input: dict[str, Any],
|
||||
validated_user_input: dict[str, Any],
|
||||
errors: dict[str, str],
|
||||
async def _async_process_file_upload(
|
||||
upload_id: str,
|
||||
field: str,
|
||||
pem_type: PEMType,
|
||||
error_code: str,
|
||||
password: str | None = None,
|
||||
) -> bool:
|
||||
"""Additional validation on broker settings for better error messages."""
|
||||
|
||||
if CONF_PROTOCOL not in validated_user_input:
|
||||
validated_user_input[CONF_PROTOCOL] = DEFAULT_PROTOCOL
|
||||
# Get current certificate settings from config entry
|
||||
certificate: str | None = (
|
||||
"auto"
|
||||
if user_input.get(SET_CA_CERT, "off") == "auto"
|
||||
else config.get(CONF_CERTIFICATE)
|
||||
if user_input.get(SET_CA_CERT, "off") == "custom"
|
||||
else None
|
||||
)
|
||||
client_certificate: str | None = (
|
||||
config.get(CONF_CLIENT_CERT) if user_input.get(SET_CLIENT_CERT) else None
|
||||
)
|
||||
client_key: str | None = (
|
||||
config.get(CONF_CLIENT_KEY) if user_input.get(SET_CLIENT_CERT) else None
|
||||
)
|
||||
|
||||
# Prepare entry update with uploaded files
|
||||
validated_user_input.update(user_input)
|
||||
client_certificate_id: str | None = user_input.get(CONF_CLIENT_CERT)
|
||||
client_key_id: str | None = user_input.get(CONF_CLIENT_KEY)
|
||||
# We do not store the private key password in the entry data
|
||||
client_key_password: str | None = validated_user_input.pop(
|
||||
CONF_CLIENT_KEY_PASSWORD, None
|
||||
)
|
||||
if (client_certificate_id and not client_key_id) or (
|
||||
not client_certificate_id and client_key_id
|
||||
):
|
||||
errors["base"] = "invalid_inclusion"
|
||||
return False
|
||||
certificate_id: str | None = user_input.get(CONF_CERTIFICATE)
|
||||
if certificate_id:
|
||||
certificate_data_raw = await _get_uploaded_file(hass, certificate_id)
|
||||
certificate = async_convert_to_pem(
|
||||
certificate_data_raw, PEMType.CERTIFICATE
|
||||
)
|
||||
if not _validate_pki_file(
|
||||
certificate_id, certificate, errors, "bad_certificate"
|
||||
):
|
||||
return False
|
||||
|
||||
# Return to form for file upload CA cert or client cert and key
|
||||
if (
|
||||
(
|
||||
not client_certificate
|
||||
and user_input.get(SET_CLIENT_CERT)
|
||||
and not client_certificate_id
|
||||
)
|
||||
or (
|
||||
not certificate
|
||||
and user_input.get(SET_CA_CERT, "off") == "custom"
|
||||
and not certificate_id
|
||||
)
|
||||
or (
|
||||
user_input.get(CONF_TRANSPORT) == TRANSPORT_WEBSOCKETS
|
||||
and CONF_WS_PATH not in user_input
|
||||
)
|
||||
):
|
||||
return False
|
||||
|
||||
if client_certificate_id:
|
||||
client_certificate_data = await _get_uploaded_file(
|
||||
hass, client_certificate_id
|
||||
)
|
||||
client_certificate = async_convert_to_pem(
|
||||
client_certificate_data, PEMType.CERTIFICATE
|
||||
)
|
||||
if not _validate_pki_file(
|
||||
client_certificate_id, client_certificate, errors, "bad_client_cert"
|
||||
):
|
||||
return False
|
||||
|
||||
if client_key_id:
|
||||
client_key_data = await _get_uploaded_file(hass, client_key_id)
|
||||
client_key = async_convert_to_pem(
|
||||
client_key_data, PEMType.PRIVATE_KEY, password=client_key_password
|
||||
)
|
||||
if not _validate_pki_file(
|
||||
client_key_id, client_key, errors, "client_key_error"
|
||||
):
|
||||
return False
|
||||
|
||||
certificate_data: dict[str, Any] = {}
|
||||
if certificate:
|
||||
certificate_data[CONF_CERTIFICATE] = certificate
|
||||
if client_certificate:
|
||||
certificate_data[CONF_CLIENT_CERT] = client_certificate
|
||||
certificate_data[CONF_CLIENT_KEY] = client_key
|
||||
|
||||
validated_user_input.update(certificate_data)
|
||||
await async_create_certificate_temp_files(hass, certificate_data)
|
||||
if error := await hass.async_add_executor_job(
|
||||
check_certicate_chain,
|
||||
):
|
||||
errors["base"] = error
|
||||
return False
|
||||
|
||||
validated_user_input.pop(SET_CA_CERT, None)
|
||||
validated_user_input.pop(SET_CLIENT_CERT, None)
|
||||
if validated_user_input.get(CONF_TRANSPORT, TRANSPORT_TCP) == TRANSPORT_TCP:
|
||||
validated_user_input.pop(CONF_WS_PATH, None)
|
||||
validated_user_input.pop(CONF_WS_HEADERS, None)
|
||||
return True
|
||||
"""Get uploaded file, or a preserved copy, and convert to a PEM file."""
|
||||
try:
|
||||
validated_user_input[CONF_WS_HEADERS] = json_loads(
|
||||
validated_user_input.get(CONF_WS_HEADERS, "{}")
|
||||
data_raw = await _get_uploaded_file(hass, upload_id)
|
||||
except ValueError:
|
||||
# Use preserved file if available.
|
||||
# When an uploaded file was read, but an error occurs,
|
||||
# the form will reload but the temporary file from the upload
|
||||
# will not be available any more. If it was processed correctly,
|
||||
# we can use the preserved copy.
|
||||
if upload_id in flow.last_uploaded:
|
||||
data_raw = flow.last_uploaded[upload_id]
|
||||
else:
|
||||
raise
|
||||
else:
|
||||
# Preserve a copy in case the validation fails,
|
||||
# and we need it later
|
||||
flow.last_uploaded[upload_id] = data_raw
|
||||
pem_data = async_convert_to_pem(data_raw, pem_type, password)
|
||||
if upload_id and not pem_data:
|
||||
errors["base"] = error_code
|
||||
return False
|
||||
entry_config_update[field] = pem_data
|
||||
return True
|
||||
|
||||
if user_input is None:
|
||||
return False
|
||||
|
||||
hass = flow.hass
|
||||
|
||||
# Copy basic and other entry fields
|
||||
entry_config_update |= user_input
|
||||
entry_config_update.update(entry_config_update.pop(OTHER_SETTINGS))
|
||||
# Pop incompatible fields for update
|
||||
for key in (
|
||||
SET_CA_CERT,
|
||||
SET_CLIENT_CERT,
|
||||
CONF_CERTIFICATE,
|
||||
CONF_CLIENT_CERT,
|
||||
CONF_CLIENT_KEY,
|
||||
CONF_CLIENT_KEY_PASSWORD,
|
||||
):
|
||||
entry_config_update.pop(key, None)
|
||||
|
||||
# Get current CA certificate settings from config entry
|
||||
if (set_ca_cert := user_input[OTHER_SETTINGS][SET_CA_CERT]) == "auto":
|
||||
entry_config_update[CONF_CERTIFICATE] = "auto"
|
||||
elif (
|
||||
entry_config is not None
|
||||
and set_ca_cert == "custom"
|
||||
and (current_cert := entry_config.get(CONF_CERTIFICATE))
|
||||
):
|
||||
entry_config_update[CONF_CERTIFICATE] = current_cert
|
||||
|
||||
# Prepare entry update with uploaded certificate files
|
||||
# converted to PEM format
|
||||
new_client_certificate: str | None = user_input[OTHER_SETTINGS].get(
|
||||
CONF_CLIENT_CERT
|
||||
)
|
||||
new_client_key: str | None = user_input[OTHER_SETTINGS].get(CONF_CLIENT_KEY)
|
||||
set_client_cert = user_input[OTHER_SETTINGS][SET_CLIENT_CERT]
|
||||
|
||||
if (new_client_certificate and not new_client_key) or (
|
||||
not new_client_certificate and new_client_key
|
||||
):
|
||||
errors["base"] = "invalid_inclusion"
|
||||
return False
|
||||
|
||||
if new_certificate := user_input[OTHER_SETTINGS].get(CONF_CERTIFICATE):
|
||||
if not await _async_process_file_upload(
|
||||
new_certificate, CONF_CERTIFICATE, PEMType.CERTIFICATE, "bad_certificate"
|
||||
):
|
||||
return False
|
||||
|
||||
if new_client_certificate:
|
||||
if not await _async_process_file_upload(
|
||||
new_client_certificate,
|
||||
CONF_CLIENT_CERT,
|
||||
PEMType.CERTIFICATE,
|
||||
"bad_client_cert",
|
||||
):
|
||||
return False
|
||||
elif (
|
||||
entry_config is not None
|
||||
and set_client_cert
|
||||
and (client_cert := entry_config.get(CONF_CLIENT_CERT))
|
||||
):
|
||||
entry_config_update[CONF_CLIENT_CERT] = client_cert
|
||||
|
||||
if new_client_key:
|
||||
if not await _async_process_file_upload(
|
||||
new_client_key,
|
||||
CONF_CLIENT_KEY,
|
||||
PEMType.PRIVATE_KEY,
|
||||
"client_key_error",
|
||||
password=user_input[OTHER_SETTINGS].get(CONF_CLIENT_KEY_PASSWORD),
|
||||
):
|
||||
return False
|
||||
elif (
|
||||
entry_config is not None
|
||||
and set_client_cert
|
||||
and (client_key := entry_config.get(CONF_CLIENT_KEY))
|
||||
):
|
||||
entry_config_update[CONF_CLIENT_KEY] = client_key
|
||||
|
||||
# We temporarily create the current and new uploaded certificate files
|
||||
# and we check the certificate chain.
|
||||
await async_create_certificate_temp_files(hass, entry_config_update)
|
||||
if error := await hass.async_add_executor_job(
|
||||
check_certicate_chain,
|
||||
):
|
||||
errors["base"] = error
|
||||
return False
|
||||
|
||||
if user_input[OTHER_SETTINGS].get(CONF_TRANSPORT, TRANSPORT_TCP) == TRANSPORT_TCP:
|
||||
entry_config_update.pop(CONF_WS_PATH, None)
|
||||
entry_config_update.pop(CONF_WS_HEADERS, None)
|
||||
else:
|
||||
# Web socket transport
|
||||
try:
|
||||
entry_config_update[CONF_WS_HEADERS] = json_loads(
|
||||
user_input[OTHER_SETTINGS].get(CONF_WS_HEADERS, "{}")
|
||||
)
|
||||
schema = vol.Schema({cv.string: cv.template})
|
||||
schema(validated_user_input[CONF_WS_HEADERS])
|
||||
schema = vol.Schema({str: str})
|
||||
schema(entry_config_update[CONF_WS_HEADERS])
|
||||
except (*JSON_DECODE_EXCEPTIONS, vol.MultipleInvalid):
|
||||
errors["base"] = "bad_ws_headers"
|
||||
return False
|
||||
|
||||
# Test the configuration
|
||||
if entry_config is not None:
|
||||
update_password_from_user_input(
|
||||
entry_config.get(CONF_PASSWORD), entry_config_update
|
||||
)
|
||||
if await hass.async_add_executor_job(
|
||||
try_connection,
|
||||
entry_config_update,
|
||||
):
|
||||
return True
|
||||
|
||||
if user_input:
|
||||
user_input_basic = user_input.copy()
|
||||
advanced_broker_options = user_input_basic.get(ADVANCED_OPTIONS, False)
|
||||
if ADVANCED_OPTIONS not in user_input or advanced_broker_options is False:
|
||||
if await _async_validate_broker_settings(
|
||||
current_config,
|
||||
user_input_basic,
|
||||
validated_user_input,
|
||||
errors,
|
||||
):
|
||||
return True
|
||||
# Get defaults settings from previous post
|
||||
current_broker = user_input_basic.get(CONF_BROKER)
|
||||
current_port = user_input_basic.get(CONF_PORT, DEFAULT_PORT)
|
||||
current_user = user_input_basic.get(CONF_USERNAME)
|
||||
current_pass = user_input_basic.get(CONF_PASSWORD)
|
||||
else:
|
||||
# Get default settings from entry (if any)
|
||||
current_broker = current_config.get(CONF_BROKER)
|
||||
current_port = current_config.get(CONF_PORT, DEFAULT_PORT)
|
||||
current_user = current_config.get(CONF_USERNAME)
|
||||
# Return the sentinel password to avoid exposure
|
||||
current_entry_pass = current_config.get(CONF_PASSWORD)
|
||||
current_pass = PWD_NOT_CHANGED if current_entry_pass else None
|
||||
|
||||
# Treat the previous post as an update of the current settings
|
||||
# (if there was a basic broker setup step)
|
||||
current_config.update(user_input_basic)
|
||||
|
||||
# Get default settings for advanced broker options
|
||||
current_client_id = current_config.get(CONF_CLIENT_ID)
|
||||
current_keepalive = current_config.get(CONF_KEEPALIVE, DEFAULT_KEEPALIVE)
|
||||
current_ca_certificate = current_config.get(CONF_CERTIFICATE)
|
||||
current_client_certificate = current_config.get(CONF_CLIENT_CERT)
|
||||
current_client_key = current_config.get(CONF_CLIENT_KEY)
|
||||
current_tls_insecure = current_config.get(CONF_TLS_INSECURE, False)
|
||||
current_protocol = current_config.get(CONF_PROTOCOL, DEFAULT_PROTOCOL)
|
||||
current_transport = current_config.get(CONF_TRANSPORT, DEFAULT_TRANSPORT)
|
||||
current_ws_path = current_config.get(CONF_WS_PATH, DEFAULT_WS_PATH)
|
||||
current_ws_headers = (
|
||||
json_dumps(current_config.get(CONF_WS_HEADERS))
|
||||
if CONF_WS_HEADERS in current_config
|
||||
else None
|
||||
)
|
||||
advanced_broker_options |= bool(
|
||||
current_client_id
|
||||
or current_keepalive != DEFAULT_KEEPALIVE
|
||||
or current_ca_certificate
|
||||
or current_client_certificate
|
||||
or current_client_key
|
||||
or current_tls_insecure
|
||||
or current_config.get(SET_CA_CERT, "off") != "off"
|
||||
or current_config.get(SET_CLIENT_CERT)
|
||||
or current_transport == TRANSPORT_WEBSOCKETS
|
||||
)
|
||||
|
||||
# Build form
|
||||
fields[vol.Required(CONF_BROKER, default=current_broker)] = TEXT_SELECTOR
|
||||
fields[vol.Required(CONF_PORT, default=current_port)] = PORT_SELECTOR
|
||||
fields[
|
||||
vol.Optional(
|
||||
CONF_PROTOCOL,
|
||||
description={"suggested_value": current_protocol},
|
||||
)
|
||||
] = PROTOCOL_SELECTOR
|
||||
fields[
|
||||
vol.Optional(
|
||||
CONF_USERNAME,
|
||||
description={"suggested_value": current_user},
|
||||
)
|
||||
] = TEXT_SELECTOR
|
||||
fields[
|
||||
vol.Optional(
|
||||
CONF_PASSWORD,
|
||||
description={"suggested_value": current_pass},
|
||||
)
|
||||
] = PASSWORD_SELECTOR
|
||||
# show advanced options checkbox if no defaults
|
||||
# of the advanced options are overridden
|
||||
if not advanced_broker_options:
|
||||
fields[
|
||||
vol.Optional(
|
||||
ADVANCED_OPTIONS,
|
||||
)
|
||||
] = BOOLEAN_SELECTOR
|
||||
return False
|
||||
fields[
|
||||
vol.Optional(
|
||||
CONF_CLIENT_ID,
|
||||
description={"suggested_value": current_client_id},
|
||||
)
|
||||
] = TEXT_SELECTOR
|
||||
fields[
|
||||
vol.Optional(
|
||||
CONF_KEEPALIVE,
|
||||
description={"suggested_value": current_keepalive},
|
||||
)
|
||||
] = KEEPALIVE_SELECTOR
|
||||
fields[
|
||||
vol.Optional(
|
||||
SET_CLIENT_CERT,
|
||||
default=current_client_certificate is not None
|
||||
or current_config.get(SET_CLIENT_CERT) is True,
|
||||
)
|
||||
] = BOOLEAN_SELECTOR
|
||||
if (
|
||||
current_client_certificate is not None
|
||||
or current_config.get(SET_CLIENT_CERT) is True
|
||||
):
|
||||
fields[
|
||||
vol.Optional(
|
||||
CONF_CLIENT_CERT,
|
||||
description={"suggested_value": user_input_basic.get(CONF_CLIENT_CERT)},
|
||||
)
|
||||
] = CERT_UPLOAD_SELECTOR
|
||||
fields[
|
||||
vol.Optional(
|
||||
CONF_CLIENT_KEY,
|
||||
description={"suggested_value": user_input_basic.get(CONF_CLIENT_KEY)},
|
||||
)
|
||||
] = CERT_KEY_UPLOAD_SELECTOR
|
||||
fields[
|
||||
vol.Optional(
|
||||
CONF_CLIENT_KEY_PASSWORD,
|
||||
description={
|
||||
"suggested_value": user_input_basic.get(CONF_CLIENT_KEY_PASSWORD)
|
||||
},
|
||||
)
|
||||
] = PASSWORD_SELECTOR
|
||||
verification_mode = current_config.get(SET_CA_CERT) or (
|
||||
"off"
|
||||
if current_ca_certificate is None
|
||||
else "auto"
|
||||
if current_ca_certificate == "auto"
|
||||
else "custom"
|
||||
)
|
||||
fields[
|
||||
vol.Optional(
|
||||
SET_CA_CERT,
|
||||
default=verification_mode,
|
||||
)
|
||||
] = BROKER_VERIFICATION_SELECTOR
|
||||
if current_ca_certificate is not None or verification_mode == "custom":
|
||||
fields[
|
||||
vol.Optional(
|
||||
CONF_CERTIFICATE,
|
||||
user_input_basic.get(CONF_CERTIFICATE),
|
||||
)
|
||||
] = CA_CERT_UPLOAD_SELECTOR
|
||||
fields[
|
||||
vol.Optional(
|
||||
CONF_TLS_INSECURE,
|
||||
description={"suggested_value": current_tls_insecure},
|
||||
)
|
||||
] = BOOLEAN_SELECTOR
|
||||
fields[
|
||||
vol.Optional(
|
||||
CONF_TRANSPORT,
|
||||
description={"suggested_value": current_transport},
|
||||
)
|
||||
] = TRANSPORT_SELECTOR
|
||||
if current_transport == TRANSPORT_WEBSOCKETS:
|
||||
fields[
|
||||
vol.Optional(CONF_WS_PATH, description={"suggested_value": current_ws_path})
|
||||
] = TEXT_SELECTOR
|
||||
fields[
|
||||
vol.Optional(
|
||||
CONF_WS_HEADERS, description={"suggested_value": current_ws_headers}
|
||||
)
|
||||
] = WS_HEADERS_SELECTOR
|
||||
|
||||
# Show form
|
||||
errors["base"] = "cannot_connect"
|
||||
return False
|
||||
|
||||
|
||||
|
||||
@@ -315,7 +315,6 @@ DEFAULT_TILT_MAX = 100
|
||||
DEFAULT_TILT_MIN = 0
|
||||
DEFAULT_TILT_OPEN_POSITION = 100
|
||||
DEFAULT_TILT_OPTIMISTIC = False
|
||||
DEFAULT_WS_HEADERS: dict[str, str] = {}
|
||||
DEFAULT_WS_PATH = "/"
|
||||
DEFAULT_POSITION_CLOSED = 0
|
||||
DEFAULT_POSITION_OPEN = 100
|
||||
|
||||
@@ -26,46 +26,53 @@
|
||||
"step": {
|
||||
"broker": {
|
||||
"data": {
|
||||
"advanced_options": "Advanced options",
|
||||
"broker": "Broker",
|
||||
"certificate": "Upload custom CA certificate file",
|
||||
"client_cert": "Upload client certificate file",
|
||||
"client_id": "Client ID (leave empty to randomly generated one)",
|
||||
"client_key": "Upload private key file",
|
||||
"client_key_password": "[%key:common::config_flow::data::password%]",
|
||||
"keepalive": "The time between sending keep alive messages",
|
||||
"password": "[%key:common::config_flow::data::password%]",
|
||||
"port": "[%key:common::config_flow::data::port%]",
|
||||
"protocol": "MQTT protocol",
|
||||
"set_ca_cert": "Broker certificate validation",
|
||||
"set_client_cert": "Use a client certificate",
|
||||
"tls_insecure": "Ignore broker certificate validation",
|
||||
"transport": "MQTT transport",
|
||||
"username": "[%key:common::config_flow::data::username%]",
|
||||
"ws_headers": "WebSocket headers in JSON format",
|
||||
"ws_path": "WebSocket path"
|
||||
"username": "[%key:common::config_flow::data::username%]"
|
||||
},
|
||||
"data_description": {
|
||||
"advanced_options": "Enable and select **Submit** to set advanced options.",
|
||||
"broker": "The hostname or IP address of your MQTT broker.",
|
||||
"certificate": "The custom CA certificate file to validate your MQTT broker's certificate.",
|
||||
"client_cert": "The client certificate to authenticate against your MQTT broker.",
|
||||
"client_id": "The unique ID to identify the Home Assistant MQTT API as MQTT client. It is recommended to leave this option blank.",
|
||||
"client_key": "The private key file that belongs to your client certificate.",
|
||||
"client_key_password": "The password for the private key file (if set).",
|
||||
"keepalive": "A value less than 90 seconds is advised.",
|
||||
"password": "The password to log in to your MQTT broker.",
|
||||
"port": "The port your MQTT broker listens to. For example 1883.",
|
||||
"protocol": "The MQTT protocol version that is used. Note that Home Assistant will silently change to version 5 if your broker supports it.",
|
||||
"set_ca_cert": "Select **Auto** for automatic CA validation, or **Custom** and select **Next** to set a custom CA certificate, to allow validating your MQTT broker's certificate.",
|
||||
"set_client_cert": "Enable and select **Next** to set a client certificate and private key to authenticate against your MQTT broker.",
|
||||
"tls_insecure": "Option to ignore validation of your MQTT broker's certificate.",
|
||||
"transport": "The transport to be used for the connection to your MQTT broker.",
|
||||
"username": "The username to log in to your MQTT broker.",
|
||||
"ws_headers": "The WebSocket headers to pass through the WebSocket-based connection to your MQTT broker.",
|
||||
"ws_path": "The WebSocket path to be used for the connection to your MQTT broker."
|
||||
"username": "The username to log in to your MQTT broker."
|
||||
},
|
||||
"description": "Please enter the connection information of your MQTT broker."
|
||||
"description": "Please enter the connection information of your MQTT broker.",
|
||||
"sections": {
|
||||
"other_settings": {
|
||||
"data": {
|
||||
"certificate": "Upload custom CA certificate file",
|
||||
"client_cert": "Upload client certificate file",
|
||||
"client_id": "Client ID (leave empty for a randomly generated one)",
|
||||
"client_key": "Upload private key file",
|
||||
"client_key_password": "[%key:common::config_flow::data::password%]",
|
||||
"keepalive": "The time between sending keep alive messages",
|
||||
"set_ca_cert": "Broker certificate validation",
|
||||
"set_client_cert": "Use a client certificate",
|
||||
"tls_insecure": "Ignore broker certificate validation",
|
||||
"transport": "MQTT transport",
|
||||
"ws_headers": "WebSocket headers in JSON format",
|
||||
"ws_path": "WebSocket path"
|
||||
},
|
||||
"data_description": {
|
||||
"certificate": "The custom CA certificate file to validate your MQTT broker's certificate.",
|
||||
"client_cert": "The client certificate to authenticate against your MQTT broker.",
|
||||
"client_id": "The unique ID to identify the Home Assistant MQTT API as MQTT client. It is recommended to leave this option blank.",
|
||||
"client_key": "The private key file that belongs to your client certificate.",
|
||||
"client_key_password": "The password for the private key file (if set).",
|
||||
"keepalive": "A value less than 90 seconds is advised. Defaults to 60 seconds.",
|
||||
"set_ca_cert": "When already set to **Custom**, a custom CA validation certificate is configured. Select **Auto** for automatic CA validation, or upload a custom CA certificate, to allow validating your MQTT broker's certificate.",
|
||||
"set_client_cert": "When already selected, client certificate authentication is enabled. Upload a client certificate and key to enable.",
|
||||
"tls_insecure": "Option to ignore validation of your MQTT broker's certificate.",
|
||||
"transport": "The transport to be used for the connection to your MQTT broker.",
|
||||
"ws_headers": "The WebSocket headers to pass through the WebSocket-based connection to your MQTT broker.",
|
||||
"ws_path": "The WebSocket path to be used for the connection to your MQTT broker."
|
||||
},
|
||||
"name": "Other settings"
|
||||
}
|
||||
}
|
||||
},
|
||||
"hassio_confirm": {
|
||||
"description": "Do you want to configure Home Assistant to connect to the MQTT broker provided by the {addon} app?",
|
||||
@@ -1178,48 +1185,6 @@
|
||||
"invalid_inclusion": "[%key:component::mqtt::config::error::invalid_inclusion%]"
|
||||
},
|
||||
"step": {
|
||||
"broker": {
|
||||
"data": {
|
||||
"advanced_options": "[%key:component::mqtt::config::step::broker::data::advanced_options%]",
|
||||
"broker": "[%key:component::mqtt::config::step::broker::data::broker%]",
|
||||
"certificate": "[%key:component::mqtt::config::step::broker::data::certificate%]",
|
||||
"client_cert": "[%key:component::mqtt::config::step::broker::data::client_cert%]",
|
||||
"client_id": "[%key:component::mqtt::config::step::broker::data::client_id%]",
|
||||
"client_key": "[%key:component::mqtt::config::step::broker::data::client_key%]",
|
||||
"keepalive": "[%key:component::mqtt::config::step::broker::data::keepalive%]",
|
||||
"password": "[%key:common::config_flow::data::password%]",
|
||||
"port": "[%key:common::config_flow::data::port%]",
|
||||
"protocol": "[%key:component::mqtt::config::step::broker::data::protocol%]",
|
||||
"set_ca_cert": "[%key:component::mqtt::config::step::broker::data::set_ca_cert%]",
|
||||
"set_client_cert": "[%key:component::mqtt::config::step::broker::data::set_client_cert%]",
|
||||
"tls_insecure": "[%key:component::mqtt::config::step::broker::data::tls_insecure%]",
|
||||
"transport": "[%key:component::mqtt::config::step::broker::data::transport%]",
|
||||
"username": "[%key:common::config_flow::data::username%]",
|
||||
"ws_headers": "[%key:component::mqtt::config::step::broker::data::ws_headers%]",
|
||||
"ws_path": "[%key:component::mqtt::config::step::broker::data::ws_path%]"
|
||||
},
|
||||
"data_description": {
|
||||
"advanced_options": "[%key:component::mqtt::config::step::broker::data_description::advanced_options%]",
|
||||
"broker": "[%key:component::mqtt::config::step::broker::data_description::broker%]",
|
||||
"certificate": "[%key:component::mqtt::config::step::broker::data_description::certificate%]",
|
||||
"client_cert": "[%key:component::mqtt::config::step::broker::data_description::client_cert%]",
|
||||
"client_id": "[%key:component::mqtt::config::step::broker::data_description::client_id%]",
|
||||
"client_key": "[%key:component::mqtt::config::step::broker::data_description::client_key%]",
|
||||
"keepalive": "[%key:component::mqtt::config::step::broker::data_description::keepalive%]",
|
||||
"password": "[%key:component::mqtt::config::step::broker::data_description::password%]",
|
||||
"port": "[%key:component::mqtt::config::step::broker::data_description::port%]",
|
||||
"protocol": "[%key:component::mqtt::config::step::broker::data_description::protocol%]",
|
||||
"set_ca_cert": "[%key:component::mqtt::config::step::broker::data_description::set_ca_cert%]",
|
||||
"set_client_cert": "[%key:component::mqtt::config::step::broker::data_description::set_client_cert%]",
|
||||
"tls_insecure": "[%key:component::mqtt::config::step::broker::data_description::tls_insecure%]",
|
||||
"transport": "[%key:component::mqtt::config::step::broker::data_description::transport%]",
|
||||
"username": "[%key:component::mqtt::config::step::broker::data_description::username%]",
|
||||
"ws_headers": "[%key:component::mqtt::config::step::broker::data_description::ws_headers%]",
|
||||
"ws_path": "[%key:component::mqtt::config::step::broker::data_description::ws_path%]"
|
||||
},
|
||||
"description": "[%key:component::mqtt::config::step::broker::description%]",
|
||||
"title": "Broker options"
|
||||
},
|
||||
"options": {
|
||||
"data": {
|
||||
"birth_enable": "Enable birth message",
|
||||
|
||||
@@ -39,23 +39,5 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"issues": {
|
||||
"deprecated_yaml": {
|
||||
"description": "Configuring {integration_title} using YAML is being removed.\n\nYour existing YAML configuration has been imported into the UI automatically.\n\nRemove both the `{domain}` and the relevant Modbus configuration from your configuration.yaml file and restart Home Assistant to fix this issue.",
|
||||
"title": "The {integration_title} YAML configuration is being removed"
|
||||
},
|
||||
"deprecated_yaml_import_issue_cannot_connect": {
|
||||
"description": "Configuring {integration_title} using YAML is being removed but there was a connect error while importing your existing configuration.\nSetup will not proceed.\n\nVerify that your {integration_title} is operating correctly and restart Home Assistant to attempt the import again.\n\nAlternatively, you may remove the `{domain}` configuration from your configuration.yaml entirely, restart Home Assistant, and add the {integration_title} integration manually.",
|
||||
"title": "YAML import failed due to a connection error"
|
||||
},
|
||||
"deprecated_yaml_import_issue_missing_hub": {
|
||||
"description": "Configuring {integration_title} using YAML is being removed but the configuration was not complete, thus we could not import your configuration.\nSetup will not proceed.\n\nVerify that your {integration_title} is operating correctly and restart Home Assistant to attempt the import again.\n\nAlternatively, you may remove the `{domain}` configuration from your configuration.yaml entirely, restart Home Assistant, and add the {integration_title} integration manually.",
|
||||
"title": "YAML import failed due to incomplete config"
|
||||
},
|
||||
"deprecated_yaml_import_issue_unknown": {
|
||||
"description": "Configuring {integration_title} using YAML is being removed but there was an unknown error while importing your existing configuration.\nSetup will not proceed.\n\nVerify that your {integration_title} is operating correctly and restart Home Assistant to attempt the import again.\n\nAlternatively, you may remove the `{domain}` configuration from your configuration.yaml entirely, restart Home Assistant, and add the {integration_title} integration manually.",
|
||||
"title": "YAML import failed due to an unknown error"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1038,6 +1038,7 @@ async def handle_subscribe_trigger(
|
||||
vol.Optional("variables"): dict,
|
||||
}
|
||||
)
|
||||
@decorators.require_admin
|
||||
@decorators.async_response
|
||||
async def handle_test_condition(
|
||||
hass: HomeAssistant, connection: ActiveConnection, msg: dict[str, Any]
|
||||
@@ -1100,6 +1101,7 @@ async def handle_test_condition(
|
||||
vol.Required("condition"): cv.CONDITION_SCHEMA,
|
||||
}
|
||||
)
|
||||
@decorators.require_admin
|
||||
@decorators.async_response
|
||||
async def handle_subscribe_condition(
|
||||
hass: HomeAssistant, connection: ActiveConnection, msg: dict[str, Any]
|
||||
|
||||
@@ -527,9 +527,6 @@ class HomeAssistant:
|
||||
self._tasks,
|
||||
)
|
||||
|
||||
# Allow automations to set up the start triggers before changing state
|
||||
await asyncio.sleep(0)
|
||||
|
||||
if self.state is not CoreState.starting:
|
||||
_LOGGER.warning(
|
||||
"Home Assistant startup has been interrupted. "
|
||||
|
||||
@@ -70,7 +70,7 @@ standard-telnetlib==3.13.0
|
||||
typing-extensions>=4.15.0,<5.0
|
||||
ulid-transform==2.2.9
|
||||
urllib3>=2.0
|
||||
uv==0.11.21
|
||||
uv==0.11.25
|
||||
voluptuous-openapi==0.4.1
|
||||
voluptuous-serialize==2.7.0
|
||||
voluptuous==0.15.2
|
||||
|
||||
+1
-1
@@ -74,7 +74,7 @@ dependencies = [
|
||||
"typing-extensions>=4.15.0,<5.0",
|
||||
"ulid-transform==2.2.9",
|
||||
"urllib3>=2.0",
|
||||
"uv==0.11.21",
|
||||
"uv==0.11.25",
|
||||
"voluptuous==0.15.2",
|
||||
"voluptuous-serialize==2.7.0",
|
||||
"voluptuous-openapi==0.4.1",
|
||||
|
||||
Generated
+1
-1
@@ -55,7 +55,7 @@ standard-telnetlib==3.13.0
|
||||
typing-extensions>=4.15.0,<5.0
|
||||
ulid-transform==2.2.9
|
||||
urllib3>=2.0
|
||||
uv==0.11.21
|
||||
uv==0.11.25
|
||||
voluptuous-openapi==0.4.1
|
||||
voluptuous-serialize==2.7.0
|
||||
voluptuous==0.15.2
|
||||
|
||||
Generated
+2
-2
@@ -1474,7 +1474,7 @@ libpyvivotek==0.6.1
|
||||
librehardwaremonitor-api==1.11.1
|
||||
|
||||
# homeassistant.components.mikrotik
|
||||
librouteros==3.2.1
|
||||
librouteros==4.1.1
|
||||
|
||||
# homeassistant.components.soundtouch
|
||||
libsoundtouch==0.8
|
||||
@@ -2148,7 +2148,7 @@ pyegps==0.2.5
|
||||
pyemoncms==0.1.3
|
||||
|
||||
# homeassistant.components.enphase_envoy
|
||||
pyenphase==3.0.0
|
||||
pyenphase==3.0.1
|
||||
|
||||
# homeassistant.components.envertech_evt800
|
||||
pyenvertechevt800==0.2.4
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
# ast-serialize is an internal mypy dependency
|
||||
ast-serialize==0.3.0
|
||||
astroid==4.0.4
|
||||
coverage==7.14.2
|
||||
coverage==7.14.3
|
||||
freezegun==1.5.5
|
||||
# librt is an internal mypy dependency
|
||||
librt==0.11.0
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -2918,32 +2918,6 @@ async def test_test_condition(
|
||||
assert msg["result"]["result"] is False
|
||||
|
||||
|
||||
async def test_test_condition_non_admin(
|
||||
hass: HomeAssistant,
|
||||
websocket_client: MockHAClientWebSocket,
|
||||
hass_admin_user: MockUser,
|
||||
) -> None:
|
||||
"""Test testing a condition does not require admin."""
|
||||
hass_admin_user.groups = []
|
||||
hass.states.async_set("hello.world", "paulus")
|
||||
|
||||
await websocket_client.send_json_auto_id(
|
||||
{
|
||||
"type": "test_condition",
|
||||
"condition": {
|
||||
"condition": "state",
|
||||
"entity_id": "hello.world",
|
||||
"state": "paulus",
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
msg = await websocket_client.receive_json()
|
||||
assert msg["type"] == const.TYPE_RESULT
|
||||
assert msg["success"]
|
||||
assert msg["result"]["result"] is True
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("value_template", "expected_template_errors"),
|
||||
[
|
||||
@@ -3116,36 +3090,6 @@ async def test_subscribe_condition(
|
||||
}
|
||||
|
||||
|
||||
async def test_subscribe_condition_non_admin(
|
||||
hass: HomeAssistant,
|
||||
websocket_client: MockHAClientWebSocket,
|
||||
hass_admin_user: MockUser,
|
||||
) -> None:
|
||||
"""Test subscribing to a condition does not require admin."""
|
||||
hass_admin_user.groups = []
|
||||
hass.states.async_set("hello.world", "paulus")
|
||||
|
||||
await websocket_client.send_json_auto_id(
|
||||
{
|
||||
"type": "subscribe_condition",
|
||||
"condition": {
|
||||
"condition": "state",
|
||||
"entity_id": "hello.world",
|
||||
"state": "paulus",
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
msg = await websocket_client.receive_json()
|
||||
assert msg["type"] == const.TYPE_RESULT
|
||||
assert msg["success"]
|
||||
|
||||
subscription_id = msg["id"]
|
||||
|
||||
msg = await websocket_client.receive_json()
|
||||
assert msg == {"id": subscription_id, "type": "event", "event": {"result": True}}
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("value_template", "expected_event"),
|
||||
[
|
||||
|
||||
@@ -2,7 +2,19 @@
|
||||
|
||||
import contextlib
|
||||
|
||||
from astroid import nodes
|
||||
from pylint.checkers import BaseChecker
|
||||
from pylint.testutils.unittest_linter import UnittestLinter
|
||||
from pylint.utils.ast_walker import ASTWalker
|
||||
|
||||
|
||||
def walk_checker(
|
||||
linter: UnittestLinter, checker: BaseChecker, node: nodes.NodeNG
|
||||
) -> None:
|
||||
"""Run the given checker over the parsed node."""
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(checker)
|
||||
walker.walk(node)
|
||||
|
||||
|
||||
@contextlib.contextmanager
|
||||
|
||||
@@ -2,13 +2,12 @@
|
||||
|
||||
import astroid
|
||||
from pylint.testutils import UnittestLinter
|
||||
from pylint.utils.ast_walker import ASTWalker
|
||||
from pylint_home_assistant.checkers.actions.service_registration import (
|
||||
ServiceRegistrationChecker,
|
||||
)
|
||||
import pytest
|
||||
|
||||
from tests.pylint import assert_no_messages
|
||||
from tests.pylint import assert_no_messages, walk_checker
|
||||
|
||||
|
||||
@pytest.fixture(name="registration_checker")
|
||||
@@ -68,11 +67,9 @@ def test_no_warning(
|
||||
) -> None:
|
||||
"""Test cases that should not trigger a warning."""
|
||||
root_node = astroid.parse(code, module_name)
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(registration_checker)
|
||||
|
||||
with assert_no_messages(linter):
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, registration_checker, root_node)
|
||||
|
||||
|
||||
def test_hass_services_register_flagged(
|
||||
@@ -87,9 +84,7 @@ async def async_setup_entry(hass, entry):
|
||||
""",
|
||||
"homeassistant.components.test_integration",
|
||||
)
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(registration_checker)
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, registration_checker, root_node)
|
||||
|
||||
messages = linter.release_messages()
|
||||
assert len(messages) == 1
|
||||
@@ -108,9 +103,7 @@ async def async_setup_entry(hass, entry):
|
||||
""",
|
||||
"homeassistant.components.test_integration",
|
||||
)
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(registration_checker)
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, registration_checker, root_node)
|
||||
|
||||
messages = linter.release_messages()
|
||||
assert len(messages) == 1
|
||||
@@ -128,9 +121,7 @@ async def async_setup_entry(hass, entry):
|
||||
""",
|
||||
"homeassistant.components.test_integration",
|
||||
)
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(registration_checker)
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, registration_checker, root_node)
|
||||
|
||||
messages = linter.release_messages()
|
||||
assert len(messages) == 1
|
||||
@@ -148,9 +139,7 @@ async def async_setup_entry(hass, entry):
|
||||
""",
|
||||
"homeassistant.components.test_integration",
|
||||
)
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(registration_checker)
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, registration_checker, root_node)
|
||||
|
||||
messages = linter.release_messages()
|
||||
assert len(messages) == 1
|
||||
@@ -170,9 +159,7 @@ async def async_setup_entry(hass, entry):
|
||||
""",
|
||||
"homeassistant.components.test_integration",
|
||||
)
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(registration_checker)
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, registration_checker, root_node)
|
||||
|
||||
messages = linter.release_messages()
|
||||
assert len(messages) == 3
|
||||
@@ -193,9 +180,7 @@ async def async_setup_entry(hass, entry):
|
||||
""",
|
||||
"homeassistant.components.test_integration",
|
||||
)
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(registration_checker)
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, registration_checker, root_node)
|
||||
|
||||
messages = linter.release_messages()
|
||||
assert len(messages) == 1
|
||||
@@ -219,8 +204,6 @@ async def async_setup_entry(hass, entry):
|
||||
""",
|
||||
"homeassistant.components.test_integration",
|
||||
)
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(registration_checker)
|
||||
|
||||
with assert_no_messages(linter):
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, registration_checker, root_node)
|
||||
|
||||
@@ -2,13 +2,12 @@
|
||||
|
||||
import astroid
|
||||
from pylint.testutils import UnittestLinter
|
||||
from pylint.utils.ast_walker import ASTWalker
|
||||
from pylint_home_assistant.checkers.actions.swallowed_exceptions import (
|
||||
SwallowedActionExceptionsChecker,
|
||||
)
|
||||
import pytest
|
||||
|
||||
from tests.pylint import assert_no_messages
|
||||
from tests.pylint import assert_no_messages, walk_checker
|
||||
|
||||
|
||||
@pytest.fixture(name="error_propagation_checker")
|
||||
@@ -129,11 +128,9 @@ def test_no_warning(
|
||||
) -> None:
|
||||
"""Test cases that should not trigger a warning."""
|
||||
root_node = astroid.parse(code, "homeassistant.components.test_integration.switch")
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(error_propagation_checker)
|
||||
|
||||
with assert_no_messages(linter):
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, error_propagation_checker, root_node)
|
||||
|
||||
|
||||
def test_log_only_flagged(
|
||||
@@ -152,9 +149,7 @@ class MySwitch(SwitchEntity):
|
||||
""",
|
||||
"homeassistant.components.test_integration.switch",
|
||||
)
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(error_propagation_checker)
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, error_propagation_checker, root_node)
|
||||
|
||||
messages = linter.release_messages()
|
||||
assert len(messages) == 1
|
||||
@@ -179,9 +174,7 @@ class MySwitch(SwitchEntity):
|
||||
""",
|
||||
"homeassistant.components.test_integration.switch",
|
||||
)
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(error_propagation_checker)
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, error_propagation_checker, root_node)
|
||||
|
||||
messages = linter.release_messages()
|
||||
assert len(messages) == 1
|
||||
@@ -203,9 +196,7 @@ class MySwitch(SwitchEntity):
|
||||
""",
|
||||
"homeassistant.components.test_integration.switch",
|
||||
)
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(error_propagation_checker)
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, error_propagation_checker, root_node)
|
||||
|
||||
messages = linter.release_messages()
|
||||
assert len(messages) == 1
|
||||
@@ -229,9 +220,7 @@ class MySwitch(SwitchEntity):
|
||||
""",
|
||||
"homeassistant.components.test_integration.switch",
|
||||
)
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(error_propagation_checker)
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, error_propagation_checker, root_node)
|
||||
|
||||
messages = linter.release_messages()
|
||||
assert len(messages) == 1
|
||||
@@ -255,9 +244,7 @@ class MySwitch(SwitchEntity):
|
||||
""",
|
||||
"homeassistant.components.test_integration.switch",
|
||||
)
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(error_propagation_checker)
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, error_propagation_checker, root_node)
|
||||
|
||||
messages = linter.release_messages()
|
||||
assert len(messages) == 1
|
||||
@@ -280,9 +267,7 @@ class MySwitch(SwitchEntity):
|
||||
""",
|
||||
"homeassistant.components.test_integration.switch",
|
||||
)
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(error_propagation_checker)
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, error_propagation_checker, root_node)
|
||||
|
||||
messages = linter.release_messages()
|
||||
assert len(messages) == 1
|
||||
@@ -304,9 +289,7 @@ class MySwitch(SwitchEntity):
|
||||
""",
|
||||
"homeassistant.components.test_integration.switch",
|
||||
)
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(error_propagation_checker)
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, error_propagation_checker, root_node)
|
||||
|
||||
messages = linter.release_messages()
|
||||
assert len(messages) == 1
|
||||
@@ -334,9 +317,7 @@ class MySwitch(SwitchEntity):
|
||||
""",
|
||||
"homeassistant.components.test_integration.switch",
|
||||
)
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(error_propagation_checker)
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, error_propagation_checker, root_node)
|
||||
|
||||
messages = linter.release_messages()
|
||||
assert len(messages) == 2
|
||||
@@ -356,9 +337,7 @@ class MySwitch(SwitchEntity):
|
||||
""",
|
||||
"homeassistant.components.test_integration.switch",
|
||||
)
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(error_propagation_checker)
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, error_propagation_checker, root_node)
|
||||
|
||||
messages = linter.release_messages()
|
||||
assert len(messages) == 1
|
||||
@@ -379,11 +358,9 @@ class MySwitch(SwitchEntity):
|
||||
""",
|
||||
"homeassistant.components.test_integration.switch",
|
||||
)
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(error_propagation_checker)
|
||||
|
||||
with assert_no_messages(linter):
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, error_propagation_checker, root_node)
|
||||
|
||||
|
||||
def test_decorator_swallows_flagged(
|
||||
@@ -408,9 +385,7 @@ class MySwitch(SwitchEntity):
|
||||
""",
|
||||
"homeassistant.components.test_integration.switch",
|
||||
)
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(error_propagation_checker)
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, error_propagation_checker, root_node)
|
||||
|
||||
messages = linter.release_messages()
|
||||
assert len(messages) == 1
|
||||
@@ -441,9 +416,7 @@ class MySwitch(SwitchEntity):
|
||||
""",
|
||||
"homeassistant.components.test_integration.switch",
|
||||
)
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(error_propagation_checker)
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, error_propagation_checker, root_node)
|
||||
|
||||
messages = linter.release_messages()
|
||||
assert len(messages) == 1
|
||||
@@ -471,11 +444,9 @@ class MySwitch(SwitchEntity):
|
||||
""",
|
||||
"homeassistant.components.test_integration.switch",
|
||||
)
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(error_propagation_checker)
|
||||
|
||||
with assert_no_messages(linter):
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, error_propagation_checker, root_node)
|
||||
|
||||
|
||||
def test_custom_service_method_flagged(
|
||||
@@ -502,9 +473,7 @@ class MyFan(FanEntity):
|
||||
""",
|
||||
"homeassistant.components.test_integration.fan",
|
||||
)
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(error_propagation_checker)
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, error_propagation_checker, root_node)
|
||||
|
||||
messages = linter.release_messages()
|
||||
assert len(messages) == 1
|
||||
@@ -535,11 +504,9 @@ class MyFan(FanEntity):
|
||||
""",
|
||||
"homeassistant.components.test_integration.fan",
|
||||
)
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(error_propagation_checker)
|
||||
|
||||
with assert_no_messages(linter):
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, error_propagation_checker, root_node)
|
||||
|
||||
|
||||
def test_unregistered_custom_method_ignored(
|
||||
@@ -558,11 +525,9 @@ class MyFan(FanEntity):
|
||||
""",
|
||||
"homeassistant.components.test_integration.fan",
|
||||
)
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(error_propagation_checker)
|
||||
|
||||
with assert_no_messages(linter):
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, error_propagation_checker, root_node)
|
||||
|
||||
|
||||
def test_standalone_service_handler_flagged(
|
||||
@@ -583,9 +548,7 @@ async def _handle_do_thing(call):
|
||||
""",
|
||||
"homeassistant.components.test_integration.services",
|
||||
)
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(error_propagation_checker)
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, error_propagation_checker, root_node)
|
||||
|
||||
messages = linter.release_messages()
|
||||
assert len(messages) == 1
|
||||
@@ -610,9 +573,7 @@ async def _handle_reset(call):
|
||||
""",
|
||||
"homeassistant.components.test_integration.services",
|
||||
)
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(error_propagation_checker)
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, error_propagation_checker, root_node)
|
||||
|
||||
messages = linter.release_messages()
|
||||
assert len(messages) == 1
|
||||
@@ -637,11 +598,9 @@ async def _handle_do_thing(call):
|
||||
""",
|
||||
"homeassistant.components.test_integration.services",
|
||||
)
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(error_propagation_checker)
|
||||
|
||||
with assert_no_messages(linter):
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, error_propagation_checker, root_node)
|
||||
|
||||
|
||||
def test_not_integration_module_ignored(
|
||||
@@ -660,8 +619,6 @@ class MySwitch(SwitchEntity):
|
||||
""",
|
||||
"tests.components.test_integration.test_switch",
|
||||
)
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(error_propagation_checker)
|
||||
|
||||
with assert_no_messages(linter):
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, error_propagation_checker, root_node)
|
||||
|
||||
@@ -8,10 +8,9 @@ from pathlib import Path
|
||||
import astroid
|
||||
from pylint.checkers import BaseChecker
|
||||
from pylint.testutils.unittest_linter import UnittestLinter
|
||||
from pylint.utils.ast_walker import ASTWalker
|
||||
import pytest
|
||||
|
||||
from tests.pylint import assert_no_messages
|
||||
from tests.pylint import assert_no_messages, walk_checker
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
@@ -62,11 +61,9 @@ def test_enforce_config_flow_no_name(
|
||||
) -> None:
|
||||
"""Good test cases."""
|
||||
root_node = astroid.parse(code, module_name)
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(enforce_config_flow_no_name_checker)
|
||||
|
||||
with assert_no_messages(linter):
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, enforce_config_flow_no_name_checker, root_node)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
@@ -110,10 +107,8 @@ def test_enforce_config_flow_no_name_bad(
|
||||
) -> None:
|
||||
"""Bad test cases."""
|
||||
root_node = astroid.parse(code, module_name)
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(enforce_config_flow_no_name_checker)
|
||||
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, enforce_config_flow_no_name_checker, root_node)
|
||||
messages = linter.release_messages()
|
||||
assert len(messages) == 1
|
||||
assert messages[0].msg_id == "home-assistant-config-flow-name-field"
|
||||
@@ -134,11 +129,9 @@ def test_enforce_config_flow_no_name_subentry_flow(
|
||||
)
|
||||
"""
|
||||
root_node = astroid.parse(code, "homeassistant.components.test.config_flow")
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(enforce_config_flow_no_name_checker)
|
||||
|
||||
with assert_no_messages(linter):
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, enforce_config_flow_no_name_checker, root_node)
|
||||
|
||||
|
||||
def test_enforce_config_flow_no_name_helper_integration(
|
||||
@@ -160,11 +153,8 @@ def test_enforce_config_flow_no_name_helper_integration(
|
||||
root_node = astroid.parse(code, "homeassistant.components.my_helper.config_flow")
|
||||
root_node.file = str(integration_dir / "config_flow.py")
|
||||
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(enforce_config_flow_no_name_checker)
|
||||
|
||||
with assert_no_messages(linter):
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, enforce_config_flow_no_name_checker, root_node)
|
||||
|
||||
|
||||
def test_enforce_config_flow_no_name_non_helper_integration(
|
||||
@@ -184,10 +174,7 @@ def test_enforce_config_flow_no_name_non_helper_integration(
|
||||
root_node = astroid.parse(code, "homeassistant.components.my_device.config_flow")
|
||||
root_node.file = str(integration_dir / "config_flow.py")
|
||||
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(enforce_config_flow_no_name_checker)
|
||||
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, enforce_config_flow_no_name_checker, root_node)
|
||||
messages = linter.release_messages()
|
||||
assert len(messages) == 1
|
||||
assert messages[0].msg_id == "home-assistant-config-flow-name-field"
|
||||
|
||||
@@ -3,10 +3,9 @@
|
||||
import astroid
|
||||
from pylint.checkers import BaseChecker
|
||||
from pylint.testutils.unittest_linter import UnittestLinter
|
||||
from pylint.utils.ast_walker import ASTWalker
|
||||
import pytest
|
||||
|
||||
from tests.pylint import assert_no_messages
|
||||
from tests.pylint import assert_no_messages, walk_checker
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
@@ -71,11 +70,9 @@ def test_enforce_config_flow_no_polling(
|
||||
) -> None:
|
||||
"""Good test cases."""
|
||||
root_node = astroid.parse(code, module_name)
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(enforce_config_flow_no_polling_checker)
|
||||
|
||||
with assert_no_messages(linter):
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, enforce_config_flow_no_polling_checker, root_node)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
@@ -133,10 +130,8 @@ def test_enforce_config_flow_no_polling_bad(
|
||||
) -> None:
|
||||
"""Bad test cases."""
|
||||
root_node = astroid.parse(code, module_name)
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(enforce_config_flow_no_polling_checker)
|
||||
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, enforce_config_flow_no_polling_checker, root_node)
|
||||
messages = linter.release_messages()
|
||||
assert len(messages) == 1
|
||||
assert messages[0].msg_id == "home-assistant-config-flow-polling-field"
|
||||
|
||||
@@ -3,10 +3,9 @@
|
||||
import astroid
|
||||
from pylint.checkers import BaseChecker
|
||||
from pylint.testutils.unittest_linter import UnittestLinter
|
||||
from pylint.utils.ast_walker import ASTWalker
|
||||
import pytest
|
||||
|
||||
from tests.pylint import assert_no_messages
|
||||
from tests.pylint import assert_no_messages, walk_checker
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
@@ -64,11 +63,9 @@ def test_enforce_unique_id_no_ip(
|
||||
) -> None:
|
||||
"""Good test cases."""
|
||||
root_node = astroid.parse(code, module_name)
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(enforce_config_entry_unique_id_no_ip_checker)
|
||||
|
||||
with assert_no_messages(linter):
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, enforce_config_entry_unique_id_no_ip_checker, root_node)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
@@ -121,10 +118,8 @@ def test_enforce_unique_id_no_ip_bad_call(
|
||||
) -> None:
|
||||
"""Bad async_set_unique_id call test cases."""
|
||||
root_node = astroid.parse(code, module_name)
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(enforce_config_entry_unique_id_no_ip_checker)
|
||||
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, enforce_config_entry_unique_id_no_ip_checker, root_node)
|
||||
messages = linter.release_messages()
|
||||
assert len(messages) == 1
|
||||
assert messages[0].msg_id == "home-assistant-unique-id-ip-based"
|
||||
@@ -182,10 +177,8 @@ def test_enforce_unique_id_no_ip_bad_call_variable(
|
||||
) -> None:
|
||||
"""Bad async_set_unique_id call test cases."""
|
||||
root_node = astroid.parse(code, module_name)
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(enforce_config_entry_unique_id_no_ip_checker)
|
||||
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, enforce_config_entry_unique_id_no_ip_checker, root_node)
|
||||
messages = linter.release_messages()
|
||||
assert len(messages) == 1
|
||||
assert messages[0].msg_id == "home-assistant-unique-id-ip-based"
|
||||
|
||||
@@ -4,7 +4,6 @@ from pathlib import Path
|
||||
|
||||
import astroid
|
||||
from pylint.testutils import MessageTest, UnittestLinter
|
||||
from pylint.utils.ast_walker import ASTWalker
|
||||
from pylint_home_assistant.checkers.quality_scale.config_entry_unloading import (
|
||||
ConfigEntryUnloadingChecker,
|
||||
)
|
||||
@@ -12,7 +11,7 @@ from pylint_home_assistant.helpers.quality_scale import clear_quality_scale_cach
|
||||
import pytest
|
||||
import yaml
|
||||
|
||||
from tests.pylint import assert_adds_messages, assert_no_messages
|
||||
from tests.pylint import assert_adds_messages, assert_no_messages, walk_checker
|
||||
|
||||
|
||||
@pytest.fixture(name="unloading_checker")
|
||||
@@ -56,11 +55,8 @@ async def async_unload_entry(hass, entry):
|
||||
)
|
||||
root_node.file = str(integration_dir / "__init__.py")
|
||||
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(unloading_checker)
|
||||
|
||||
with assert_no_messages(linter):
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, unloading_checker, root_node)
|
||||
|
||||
|
||||
def test_unload_entry_missing_fires(
|
||||
@@ -81,9 +77,6 @@ async def async_setup_entry(hass, entry):
|
||||
)
|
||||
root_node.file = str(integration_dir / "__init__.py")
|
||||
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(unloading_checker)
|
||||
|
||||
with assert_adds_messages(
|
||||
linter,
|
||||
MessageTest(
|
||||
@@ -93,7 +86,7 @@ async def async_setup_entry(hass, entry):
|
||||
col_offset=0,
|
||||
),
|
||||
):
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, unloading_checker, root_node)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
@@ -146,8 +139,5 @@ async def async_setup_entry(hass, entry):
|
||||
)
|
||||
root_node.file = str(integration_dir / "__init__.py")
|
||||
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(unloading_checker)
|
||||
|
||||
with assert_no_messages(linter):
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, unloading_checker, root_node)
|
||||
|
||||
@@ -4,13 +4,12 @@ from pathlib import Path
|
||||
|
||||
import astroid
|
||||
from pylint.testutils import MessageTest, UnittestLinter
|
||||
from pylint.utils.ast_walker import ASTWalker
|
||||
from pylint_home_assistant.checkers.quality_scale.diagnostics import DiagnosticsChecker
|
||||
from pylint_home_assistant.helpers.quality_scale import clear_quality_scale_cache
|
||||
import pytest
|
||||
import yaml
|
||||
|
||||
from tests.pylint import assert_adds_messages, assert_no_messages
|
||||
from tests.pylint import assert_adds_messages, assert_no_messages, walk_checker
|
||||
|
||||
|
||||
@pytest.fixture(name="diagnostics_checker")
|
||||
@@ -75,11 +74,8 @@ def test_diagnostics_present(
|
||||
root_node = astroid.parse(code, "homeassistant.components.test_int.diagnostics")
|
||||
root_node.file = str(integration_dir / "diagnostics.py")
|
||||
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(diagnostics_checker)
|
||||
|
||||
with assert_no_messages(linter):
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, diagnostics_checker, root_node)
|
||||
|
||||
|
||||
def test_diagnostics_missing_fires(
|
||||
@@ -100,9 +96,6 @@ async def async_setup(hass, config):
|
||||
)
|
||||
root_node.file = str(integration_dir / "diagnostics.py")
|
||||
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(diagnostics_checker)
|
||||
|
||||
with assert_adds_messages(
|
||||
linter,
|
||||
MessageTest(
|
||||
@@ -112,7 +105,7 @@ async def async_setup(hass, config):
|
||||
col_offset=0,
|
||||
),
|
||||
):
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, diagnostics_checker, root_node)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
@@ -165,8 +158,5 @@ async def async_setup(hass, config):
|
||||
)
|
||||
root_node.file = str(integration_dir / "diagnostics.py")
|
||||
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(diagnostics_checker)
|
||||
|
||||
with assert_no_messages(linter):
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, diagnostics_checker, root_node)
|
||||
|
||||
@@ -6,7 +6,6 @@ from pathlib import Path
|
||||
import astroid
|
||||
from astroid import nodes
|
||||
from pylint.testutils import MessageTest, UnittestLinter
|
||||
from pylint.utils.ast_walker import ASTWalker
|
||||
from pylint_home_assistant.checkers.quality_scale.entity_unique_id import (
|
||||
EntityUniqueIdChecker,
|
||||
)
|
||||
@@ -15,7 +14,7 @@ from pylint_home_assistant.helpers.quality_scale import clear_quality_scale_cach
|
||||
import pytest
|
||||
import yaml
|
||||
|
||||
from tests.pylint import assert_adds_messages, assert_no_messages
|
||||
from tests.pylint import assert_adds_messages, assert_no_messages, walk_checker
|
||||
|
||||
|
||||
@pytest.fixture(name="entity_unique_id_checker")
|
||||
@@ -258,10 +257,8 @@ def test_handled(
|
||||
_create_quality_scale(integration_dir, {"entity-unique-id": "done"})
|
||||
|
||||
root_node = _parse(code, integration_dir)
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(entity_unique_id_checker)
|
||||
with assert_no_messages(linter):
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, entity_unique_id_checker, root_node)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
@@ -351,10 +348,8 @@ def test_ancestor_satisfies_rule(
|
||||
astroid.parse(ancestor_code, "homeassistant.components.test_integration.eui_entity")
|
||||
root_node = _parse(sensor_code, integration_dir)
|
||||
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(entity_unique_id_checker)
|
||||
with assert_no_messages(linter):
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, entity_unique_id_checker, root_node)
|
||||
|
||||
|
||||
def test_missing_fires(
|
||||
@@ -377,10 +372,8 @@ class MySensor(Entity):
|
||||
)
|
||||
|
||||
class_node = next(root_node.nodes_of_class(nodes.ClassDef))
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(entity_unique_id_checker)
|
||||
with assert_adds_messages(linter, _expect_missing(class_node)):
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, entity_unique_id_checker, root_node)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
@@ -444,10 +437,8 @@ def test_conditional_self_assignment_fires(
|
||||
for cls in root_node.nodes_of_class(nodes.ClassDef)
|
||||
if cls.name == class_name
|
||||
)
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(entity_unique_id_checker)
|
||||
with assert_adds_messages(linter, _expect_missing(class_node)):
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, entity_unique_id_checker, root_node)
|
||||
|
||||
|
||||
def test_explicit_none_class_body_fires(
|
||||
@@ -470,10 +461,8 @@ class MySensor(Entity):
|
||||
)
|
||||
|
||||
class_node = next(root_node.nodes_of_class(nodes.ClassDef))
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(entity_unique_id_checker)
|
||||
with assert_adds_messages(linter, _expect_missing(class_node)):
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, entity_unique_id_checker, root_node)
|
||||
|
||||
|
||||
def test_subclass_nullifies_ancestor_value(
|
||||
@@ -510,10 +499,8 @@ class MySensor(TestIntegrationBaseEntity):
|
||||
for cls in root_node.nodes_of_class(nodes.ClassDef)
|
||||
if cls.name == "MySensor"
|
||||
)
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(entity_unique_id_checker)
|
||||
with assert_adds_messages(linter, _expect_missing(class_node)):
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, entity_unique_id_checker, root_node)
|
||||
|
||||
|
||||
def test_explicit_none_self_assign_fires(
|
||||
@@ -537,10 +524,8 @@ class MySensor(Entity):
|
||||
)
|
||||
|
||||
class_node = next(root_node.nodes_of_class(nodes.ClassDef))
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(entity_unique_id_checker)
|
||||
with assert_adds_messages(linter, _expect_missing(class_node)):
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, entity_unique_id_checker, root_node)
|
||||
|
||||
|
||||
def test_bare_annotation_only_fires(
|
||||
@@ -563,10 +548,8 @@ class MySensor(Entity):
|
||||
)
|
||||
|
||||
class_node = next(root_node.nodes_of_class(nodes.ClassDef))
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(entity_unique_id_checker)
|
||||
with assert_adds_messages(linter, _expect_missing(class_node)):
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, entity_unique_id_checker, root_node)
|
||||
|
||||
|
||||
def test_entity_default_does_not_satisfy(
|
||||
@@ -596,10 +579,8 @@ class MySensor(Entity):
|
||||
)
|
||||
|
||||
class_node = next(root_node.nodes_of_class(nodes.ClassDef))
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(entity_unique_id_checker)
|
||||
with assert_adds_messages(linter, _expect_missing(class_node)):
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, entity_unique_id_checker, root_node)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
@@ -638,10 +619,8 @@ def test_class_not_subject_to_rule(
|
||||
|
||||
root_node = _parse(code, integration_dir)
|
||||
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(entity_unique_id_checker)
|
||||
with assert_no_messages(linter):
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, entity_unique_id_checker, root_node)
|
||||
|
||||
|
||||
def test_leaf_class_still_fires(
|
||||
@@ -671,10 +650,8 @@ class SomethingUnrelated:
|
||||
for cls in root_node.nodes_of_class(nodes.ClassDef)
|
||||
if cls.name == "LonelySensor"
|
||||
)
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(entity_unique_id_checker)
|
||||
with assert_adds_messages(linter, _expect_missing(class_node)):
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, entity_unique_id_checker, root_node)
|
||||
|
||||
|
||||
def test_dict_status_done_fires(
|
||||
@@ -700,10 +677,8 @@ class MySensor(Entity):
|
||||
)
|
||||
|
||||
class_node = next(root_node.nodes_of_class(nodes.ClassDef))
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(entity_unique_id_checker)
|
||||
with assert_adds_messages(linter, _expect_missing(class_node)):
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, entity_unique_id_checker, root_node)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
@@ -773,10 +748,8 @@ class MySensor(Entity):
|
||||
"""
|
||||
root_node = _parse(code, integration_dir, module_name, file_name)
|
||||
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(entity_unique_id_checker)
|
||||
with assert_no_messages(linter):
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, entity_unique_id_checker, root_node)
|
||||
|
||||
|
||||
def _find_attr_value_node(
|
||||
@@ -848,10 +821,8 @@ def test_static_class_body_string_in_multi_entry_fires(
|
||||
|
||||
root_node = _parse(code, integration_dir)
|
||||
value_node = _find_attr_value_node(root_node)
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(entity_unique_id_checker)
|
||||
with assert_adds_messages(linter, _expect_static(value_node, "MySensor")):
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, entity_unique_id_checker, root_node)
|
||||
|
||||
|
||||
def test_static_class_body_string_no_manifest_fires(
|
||||
@@ -875,10 +846,8 @@ class MySensor(Entity):
|
||||
)
|
||||
|
||||
value_node = _find_attr_value_node(root_node)
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(entity_unique_id_checker)
|
||||
with assert_adds_messages(linter, _expect_static(value_node, "MySensor")):
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, entity_unique_id_checker, root_node)
|
||||
|
||||
|
||||
_STATIC_CLASS_BODY_STRING = """
|
||||
@@ -946,7 +915,5 @@ def test_static_rule_does_not_warn(
|
||||
_create_quality_scale(integration_dir, {"entity-unique-id": rule_status})
|
||||
|
||||
root_node = _parse(code, integration_dir)
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(entity_unique_id_checker)
|
||||
with assert_no_messages(linter):
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, entity_unique_id_checker, root_node)
|
||||
|
||||
@@ -5,7 +5,6 @@ from pathlib import Path
|
||||
import astroid
|
||||
from astroid import nodes
|
||||
from pylint.testutils import MessageTest, UnittestLinter
|
||||
from pylint.utils.ast_walker import ASTWalker
|
||||
from pylint_home_assistant.checkers.quality_scale.has_entity_name import (
|
||||
HasEntityNameChecker,
|
||||
)
|
||||
@@ -13,7 +12,7 @@ from pylint_home_assistant.helpers.quality_scale import clear_quality_scale_cach
|
||||
import pytest
|
||||
import yaml
|
||||
|
||||
from tests.pylint import assert_adds_messages, assert_no_messages
|
||||
from tests.pylint import assert_adds_messages, assert_no_messages, walk_checker
|
||||
|
||||
|
||||
@pytest.fixture(name="has_entity_name_checker")
|
||||
@@ -145,10 +144,8 @@ def test_handled(
|
||||
_create_quality_scale(integration_dir, {"has-entity-name": "done"})
|
||||
|
||||
root_node = _parse(code, integration_dir)
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(has_entity_name_checker)
|
||||
with assert_no_messages(linter):
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, has_entity_name_checker, root_node)
|
||||
|
||||
|
||||
def test_ancestor_class_level(
|
||||
@@ -180,10 +177,8 @@ class MySensor(TestIntegrationBaseEntity):
|
||||
integration_dir,
|
||||
)
|
||||
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(has_entity_name_checker)
|
||||
with assert_no_messages(linter):
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, has_entity_name_checker, root_node)
|
||||
|
||||
|
||||
def test_ancestor_self_assign(
|
||||
@@ -216,10 +211,8 @@ class MySensor(TestIntegrationBaseEntity):
|
||||
integration_dir,
|
||||
)
|
||||
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(has_entity_name_checker)
|
||||
with assert_no_messages(linter):
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, has_entity_name_checker, root_node)
|
||||
|
||||
|
||||
def test_missing_fires(
|
||||
@@ -242,10 +235,8 @@ class MySensor(Entity):
|
||||
)
|
||||
|
||||
class_node = next(root_node.nodes_of_class(nodes.ClassDef))
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(has_entity_name_checker)
|
||||
with assert_adds_messages(linter, _expect_missing(class_node)):
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, has_entity_name_checker, root_node)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
@@ -333,10 +324,8 @@ def test_conditional_self_assignment_fires(
|
||||
for cls in root_node.nodes_of_class(nodes.ClassDef)
|
||||
if cls.name == class_name
|
||||
)
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(has_entity_name_checker)
|
||||
with assert_adds_messages(linter, _expect_missing(class_node)):
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, has_entity_name_checker, root_node)
|
||||
|
||||
|
||||
def test_explicit_false_fires(
|
||||
@@ -359,10 +348,8 @@ class MySensor(Entity):
|
||||
)
|
||||
|
||||
class_node = next(root_node.nodes_of_class(nodes.ClassDef))
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(has_entity_name_checker)
|
||||
with assert_adds_messages(linter, _expect_missing(class_node)):
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, has_entity_name_checker, root_node)
|
||||
|
||||
|
||||
def test_generic_subscript_base_sets_flag(
|
||||
@@ -394,10 +381,8 @@ class MySensor(TestIntegrationGenericBase[int]):
|
||||
integration_dir,
|
||||
)
|
||||
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(has_entity_name_checker)
|
||||
with assert_no_messages(linter):
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, has_entity_name_checker, root_node)
|
||||
|
||||
|
||||
def test_two_level_subscript_chain(
|
||||
@@ -438,10 +423,8 @@ class MyLight(TestIntegrationLightBase):
|
||||
file_name="light.py",
|
||||
)
|
||||
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(has_entity_name_checker)
|
||||
with assert_no_messages(linter):
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, has_entity_name_checker, root_node)
|
||||
|
||||
|
||||
def test_entity_description_fallback(
|
||||
@@ -471,10 +454,8 @@ class MyEntity(Entity):
|
||||
integration_dir,
|
||||
)
|
||||
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(has_entity_name_checker)
|
||||
with assert_no_messages(linter):
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, has_entity_name_checker, root_node)
|
||||
|
||||
|
||||
def test_entity_description_subscripted_annotation(
|
||||
@@ -504,10 +485,8 @@ class MyEntity[T](Entity):
|
||||
integration_dir,
|
||||
)
|
||||
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(has_entity_name_checker)
|
||||
with assert_no_messages(linter):
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, has_entity_name_checker, root_node)
|
||||
|
||||
|
||||
def test_entity_description_without_flag_still_fires(
|
||||
@@ -542,10 +521,8 @@ class MyEntity(Entity):
|
||||
for cls in root_node.nodes_of_class(nodes.ClassDef)
|
||||
if cls.name == "MyEntity"
|
||||
)
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(has_entity_name_checker)
|
||||
with assert_adds_messages(linter, _expect_missing(class_node)):
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, has_entity_name_checker, root_node)
|
||||
|
||||
|
||||
def test_entity_description_set_in_ancestor(
|
||||
@@ -585,10 +562,8 @@ class MySensor(TestIntegrationBaseEntity):
|
||||
integration_dir,
|
||||
)
|
||||
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(has_entity_name_checker)
|
||||
with assert_no_messages(linter):
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, has_entity_name_checker, root_node)
|
||||
|
||||
|
||||
def test_mixin_subclassed_in_same_module_ignored(
|
||||
@@ -613,10 +588,8 @@ class ActualEntity(MyClimateMixin):
|
||||
integration_dir,
|
||||
)
|
||||
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(has_entity_name_checker)
|
||||
with assert_no_messages(linter):
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, has_entity_name_checker, root_node)
|
||||
|
||||
|
||||
def test_subclassed_via_subscript_ignored(
|
||||
@@ -641,10 +614,8 @@ class ConcreteEntity(GenericBase[int]):
|
||||
integration_dir,
|
||||
)
|
||||
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(has_entity_name_checker)
|
||||
with assert_no_messages(linter):
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, has_entity_name_checker, root_node)
|
||||
|
||||
|
||||
def test_leaf_class_still_fires(
|
||||
@@ -674,10 +645,8 @@ class SomethingUnrelated:
|
||||
for cls in root_node.nodes_of_class(nodes.ClassDef)
|
||||
if cls.name == "LonelySensor"
|
||||
)
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(has_entity_name_checker)
|
||||
with assert_adds_messages(linter, _expect_missing(class_node)):
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, has_entity_name_checker, root_node)
|
||||
|
||||
|
||||
def test_non_entity_class_ignored(
|
||||
@@ -697,10 +666,8 @@ class NotAnEntity:
|
||||
integration_dir,
|
||||
)
|
||||
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(has_entity_name_checker)
|
||||
with assert_no_messages(linter):
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, has_entity_name_checker, root_node)
|
||||
|
||||
|
||||
def test_dict_status_done_fires(
|
||||
@@ -726,10 +693,8 @@ class MySensor(Entity):
|
||||
)
|
||||
|
||||
class_node = next(root_node.nodes_of_class(nodes.ClassDef))
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(has_entity_name_checker)
|
||||
with assert_adds_messages(linter, _expect_missing(class_node)):
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, has_entity_name_checker, root_node)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
@@ -799,7 +764,5 @@ class MySensor(Entity):
|
||||
"""
|
||||
root_node = _parse(code, integration_dir, module_name, file_name)
|
||||
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(has_entity_name_checker)
|
||||
with assert_no_messages(linter):
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, has_entity_name_checker, root_node)
|
||||
|
||||
@@ -4,7 +4,6 @@ from pathlib import Path
|
||||
|
||||
import astroid
|
||||
from pylint.testutils import MessageTest, UnittestLinter
|
||||
from pylint.utils.ast_walker import ASTWalker
|
||||
from pylint_home_assistant.checkers.quality_scale.parallel_updates import (
|
||||
ParallelUpdatesChecker,
|
||||
)
|
||||
@@ -12,7 +11,7 @@ from pylint_home_assistant.helpers.quality_scale import clear_quality_scale_cach
|
||||
import pytest
|
||||
import yaml
|
||||
|
||||
from tests.pylint import assert_adds_messages, assert_no_messages
|
||||
from tests.pylint import assert_adds_messages, assert_no_messages, walk_checker
|
||||
|
||||
|
||||
@pytest.fixture(name="parallel_updates_checker")
|
||||
@@ -61,11 +60,8 @@ def test_parallel_updates_present(
|
||||
root_node = astroid.parse("PARALLEL_UPDATES = 1\n", module_name)
|
||||
root_node.file = str(integration_dir / "sensor.py")
|
||||
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(parallel_updates_checker)
|
||||
|
||||
with assert_no_messages(linter):
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, parallel_updates_checker, root_node)
|
||||
|
||||
|
||||
def test_parallel_updates_zero(
|
||||
@@ -82,11 +78,8 @@ def test_parallel_updates_zero(
|
||||
)
|
||||
root_node.file = str(integration_dir / "sensor.py")
|
||||
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(parallel_updates_checker)
|
||||
|
||||
with assert_no_messages(linter):
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, parallel_updates_checker, root_node)
|
||||
|
||||
|
||||
def test_parallel_updates_annotated_assignment(
|
||||
@@ -104,11 +97,8 @@ def test_parallel_updates_annotated_assignment(
|
||||
)
|
||||
root_node.file = str(integration_dir / "sensor.py")
|
||||
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(parallel_updates_checker)
|
||||
|
||||
with assert_no_messages(linter):
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, parallel_updates_checker, root_node)
|
||||
|
||||
|
||||
def test_parallel_updates_missing_fires(
|
||||
@@ -126,9 +116,6 @@ def test_parallel_updates_missing_fires(
|
||||
)
|
||||
root_node.file = str(integration_dir / "sensor.py")
|
||||
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(parallel_updates_checker)
|
||||
|
||||
with assert_adds_messages(
|
||||
linter,
|
||||
MessageTest(
|
||||
@@ -138,7 +125,7 @@ def test_parallel_updates_missing_fires(
|
||||
col_offset=0,
|
||||
),
|
||||
):
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, parallel_updates_checker, root_node)
|
||||
|
||||
|
||||
def test_parallel_updates_missing_status_done_dict(
|
||||
@@ -159,9 +146,6 @@ def test_parallel_updates_missing_status_done_dict(
|
||||
)
|
||||
root_node.file = str(integration_dir / "sensor.py")
|
||||
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(parallel_updates_checker)
|
||||
|
||||
with assert_adds_messages(
|
||||
linter,
|
||||
MessageTest(
|
||||
@@ -171,7 +155,7 @@ def test_parallel_updates_missing_status_done_dict(
|
||||
col_offset=0,
|
||||
),
|
||||
):
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, parallel_updates_checker, root_node)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
@@ -231,8 +215,5 @@ def test_parallel_updates_not_fired(
|
||||
)
|
||||
root_node.file = str(integration_dir / "sensor.py")
|
||||
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(parallel_updates_checker)
|
||||
|
||||
with assert_no_messages(linter):
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, parallel_updates_checker, root_node)
|
||||
|
||||
@@ -4,7 +4,6 @@ from pathlib import Path
|
||||
|
||||
import astroid
|
||||
from pylint.testutils import MessageTest, UnittestLinter
|
||||
from pylint.utils.ast_walker import ASTWalker
|
||||
from pylint_home_assistant.checkers.quality_scale.reauthentication_flow import (
|
||||
ReauthenticationFlowChecker,
|
||||
)
|
||||
@@ -12,7 +11,7 @@ from pylint_home_assistant.helpers.quality_scale import clear_quality_scale_cach
|
||||
import pytest
|
||||
import yaml
|
||||
|
||||
from tests.pylint import assert_adds_messages, assert_no_messages
|
||||
from tests.pylint import assert_adds_messages, assert_no_messages, walk_checker
|
||||
|
||||
|
||||
@pytest.fixture(name="reauth_checker")
|
||||
@@ -54,11 +53,8 @@ class MyConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
)
|
||||
root_node.file = str(integration_dir / "config_flow.py")
|
||||
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(reauth_checker)
|
||||
|
||||
with assert_no_messages(linter):
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, reauth_checker, root_node)
|
||||
|
||||
|
||||
def test_reauth_missing_fires(
|
||||
@@ -80,9 +76,6 @@ class MyConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
)
|
||||
root_node.file = str(integration_dir / "config_flow.py")
|
||||
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(reauth_checker)
|
||||
|
||||
with assert_adds_messages(
|
||||
linter,
|
||||
MessageTest(
|
||||
@@ -92,7 +85,7 @@ class MyConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
col_offset=0,
|
||||
),
|
||||
):
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, reauth_checker, root_node)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
@@ -146,8 +139,5 @@ class MyConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
)
|
||||
root_node.file = str(integration_dir / "config_flow.py")
|
||||
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(reauth_checker)
|
||||
|
||||
with assert_no_messages(linter):
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, reauth_checker, root_node)
|
||||
|
||||
@@ -5,10 +5,9 @@ from pylint.checkers import BaseChecker
|
||||
from pylint.interfaces import UNDEFINED
|
||||
from pylint.testutils import MessageTest
|
||||
from pylint.testutils.unittest_linter import UnittestLinter
|
||||
from pylint.utils.ast_walker import ASTWalker
|
||||
import pytest
|
||||
|
||||
from . import assert_adds_messages, assert_no_messages
|
||||
from . import assert_adds_messages, assert_no_messages, walk_checker
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
@@ -54,11 +53,9 @@ def test_enforce_class_module_good(
|
||||
) -> None:
|
||||
"""Good test cases."""
|
||||
root_node = astroid.parse(code, path)
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(enforce_class_module_checker)
|
||||
|
||||
with assert_no_messages(linter):
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, enforce_class_module_checker, root_node)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
@@ -90,11 +87,9 @@ def test_enforce_class_platform_good(
|
||||
pass
|
||||
"""
|
||||
root_node = astroid.parse(code, path)
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(enforce_class_module_checker)
|
||||
|
||||
with assert_no_messages(linter):
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, enforce_class_module_checker, root_node)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
@@ -128,8 +123,6 @@ def test_enforce_class_module_bad_simple(
|
||||
""",
|
||||
path,
|
||||
)
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(enforce_class_module_checker)
|
||||
|
||||
with assert_adds_messages(
|
||||
linter,
|
||||
@@ -154,7 +147,7 @@ def test_enforce_class_module_bad_simple(
|
||||
end_col_offset=35,
|
||||
),
|
||||
):
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, enforce_class_module_checker, root_node)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
@@ -185,8 +178,6 @@ def test_enforce_class_module_bad_nested(
|
||||
""",
|
||||
path,
|
||||
)
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(enforce_class_module_checker)
|
||||
|
||||
with assert_adds_messages(
|
||||
linter,
|
||||
@@ -211,7 +202,7 @@ def test_enforce_class_module_bad_nested(
|
||||
end_col_offset=21,
|
||||
),
|
||||
):
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, enforce_class_module_checker, root_node)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
@@ -236,11 +227,9 @@ def test_enforce_entity_good(
|
||||
pass
|
||||
"""
|
||||
root_node = astroid.parse(code, path)
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(enforce_class_module_checker)
|
||||
|
||||
with assert_no_messages(linter):
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, enforce_class_module_checker, root_node)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
@@ -265,8 +254,6 @@ def test_enforce_entity_bad(
|
||||
pass
|
||||
"""
|
||||
root_node = astroid.parse(code, path)
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(enforce_class_module_checker)
|
||||
|
||||
with assert_adds_messages(
|
||||
linter,
|
||||
@@ -281,4 +268,4 @@ def test_enforce_entity_bad(
|
||||
end_col_offset=18,
|
||||
),
|
||||
):
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, enforce_class_module_checker, root_node)
|
||||
|
||||
@@ -5,10 +5,9 @@ from pylint.checkers import BaseChecker
|
||||
from pylint.interfaces import UNDEFINED
|
||||
from pylint.testutils import MessageTest
|
||||
from pylint.testutils.unittest_linter import UnittestLinter
|
||||
from pylint.utils.ast_walker import ASTWalker
|
||||
import pytest
|
||||
|
||||
from . import assert_adds_messages, assert_no_messages
|
||||
from . import assert_adds_messages, assert_no_messages, walk_checker
|
||||
|
||||
|
||||
def test_good_callback(linter: UnittestLinter, decorator_checker: BaseChecker) -> None:
|
||||
@@ -24,11 +23,9 @@ def test_good_callback(linter: UnittestLinter, decorator_checker: BaseChecker) -
|
||||
"""
|
||||
|
||||
root_node = astroid.parse(code)
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(decorator_checker)
|
||||
|
||||
with assert_no_messages(linter):
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, decorator_checker, root_node)
|
||||
|
||||
|
||||
def test_bad_callback(linter: UnittestLinter, decorator_checker: BaseChecker) -> None:
|
||||
@@ -44,8 +41,6 @@ def test_bad_callback(linter: UnittestLinter, decorator_checker: BaseChecker) ->
|
||||
"""
|
||||
|
||||
root_node = astroid.parse(code)
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(decorator_checker)
|
||||
|
||||
with assert_adds_messages(
|
||||
linter,
|
||||
@@ -60,7 +55,7 @@ def test_bad_callback(linter: UnittestLinter, decorator_checker: BaseChecker) ->
|
||||
end_col_offset=15,
|
||||
),
|
||||
):
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, decorator_checker, root_node)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
@@ -110,11 +105,9 @@ def test_good_fixture(
|
||||
"""
|
||||
|
||||
root_node = astroid.parse(code, path)
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(decorator_checker)
|
||||
|
||||
with assert_no_messages(linter):
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, decorator_checker, root_node)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
@@ -146,8 +139,6 @@ def test_bad_fixture_session_scope(
|
||||
"""
|
||||
|
||||
root_node = astroid.parse(code, path)
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(decorator_checker)
|
||||
|
||||
with assert_adds_messages(
|
||||
linter,
|
||||
@@ -162,7 +153,7 @@ def test_bad_fixture_session_scope(
|
||||
end_col_offset=32,
|
||||
),
|
||||
):
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, decorator_checker, root_node)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
@@ -193,8 +184,6 @@ def test_bad_fixture_package_scope(
|
||||
"""
|
||||
|
||||
root_node = astroid.parse(code, path)
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(decorator_checker)
|
||||
|
||||
with assert_adds_messages(
|
||||
linter,
|
||||
@@ -209,7 +198,7 @@ def test_bad_fixture_package_scope(
|
||||
end_col_offset=32,
|
||||
),
|
||||
):
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, decorator_checker, root_node)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
@@ -247,8 +236,6 @@ def test_bad_fixture_autouse(
|
||||
"""
|
||||
|
||||
root_node = astroid.parse(code, path)
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(decorator_checker)
|
||||
|
||||
with assert_adds_messages(
|
||||
linter,
|
||||
@@ -263,4 +250,4 @@ def test_bad_fixture_autouse(
|
||||
end_col_offset=17 + len(keywords),
|
||||
),
|
||||
):
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, decorator_checker, root_node)
|
||||
|
||||
@@ -2,11 +2,10 @@
|
||||
|
||||
import astroid
|
||||
from pylint.testutils import UnittestLinter
|
||||
from pylint.utils.ast_walker import ASTWalker
|
||||
from pylint_home_assistant.checkers.test_determinism import HassTestDeterminismChecker
|
||||
import pytest
|
||||
|
||||
from . import assert_no_messages
|
||||
from . import assert_no_messages, walk_checker
|
||||
|
||||
|
||||
@pytest.fixture(name="determinism_checker")
|
||||
@@ -144,11 +143,9 @@ def test_no_warning(
|
||||
) -> None:
|
||||
"""Test cases that should not trigger a warning."""
|
||||
root_node = astroid.parse(code, module_name)
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(determinism_checker)
|
||||
|
||||
with assert_no_messages(linter):
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, determinism_checker, root_node)
|
||||
|
||||
|
||||
def test_if_statement_flagged(
|
||||
@@ -167,9 +164,7 @@ def test_sensor_value(hass) -> None:
|
||||
""",
|
||||
"tests.components.test_integration.test_sensor",
|
||||
)
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(determinism_checker)
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, determinism_checker, root_node)
|
||||
|
||||
messages = linter.release_messages()
|
||||
assert len(messages) == 1
|
||||
@@ -193,9 +188,7 @@ def test_something(hass) -> None:
|
||||
""",
|
||||
"tests.components.test_integration.test_init",
|
||||
)
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(determinism_checker)
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, determinism_checker, root_node)
|
||||
|
||||
messages = linter.release_messages()
|
||||
assert len(messages) == 2
|
||||
@@ -216,9 +209,7 @@ async def test_something(hass) -> None:
|
||||
""",
|
||||
"tests.components.test_integration.test_init",
|
||||
)
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(determinism_checker)
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, determinism_checker, root_node)
|
||||
|
||||
messages = linter.release_messages()
|
||||
assert len(messages) == 1
|
||||
@@ -241,9 +232,7 @@ def test_something(state) -> None:
|
||||
""",
|
||||
"tests.components.test_integration.test_init",
|
||||
)
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(determinism_checker)
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, determinism_checker, root_node)
|
||||
|
||||
messages = linter.release_messages()
|
||||
assert len(messages) == 1
|
||||
|
||||
@@ -2,11 +2,10 @@
|
||||
|
||||
import astroid
|
||||
from pylint.testutils import UnittestLinter
|
||||
from pylint.utils.ast_walker import ASTWalker
|
||||
from pylint_home_assistant.checkers.domain_constant import DomainConstantChecker
|
||||
import pytest
|
||||
|
||||
from . import assert_no_messages
|
||||
from . import assert_no_messages, walk_checker
|
||||
|
||||
|
||||
@pytest.fixture(name="domain_constant_checker")
|
||||
@@ -221,11 +220,9 @@ def test_no_warning(
|
||||
) -> None:
|
||||
"""Test cases that should not trigger a warning."""
|
||||
root_node = astroid.parse(code, "tests.components.test_integration.test_init")
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(domain_constant_checker)
|
||||
|
||||
with assert_no_messages(linter):
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, domain_constant_checker, root_node)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
@@ -255,9 +252,7 @@ def test_domain_argument_flagged(
|
||||
) -> None:
|
||||
"""Test that non-domain arguments are flagged."""
|
||||
root_node = astroid.parse(code, "tests.components.test_integration.test_init")
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(domain_constant_checker)
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, domain_constant_checker, root_node)
|
||||
|
||||
messages = linter.release_messages()
|
||||
assert len(messages) == 1
|
||||
@@ -276,8 +271,6 @@ async_setup_component(hass, OTHER, {})
|
||||
""",
|
||||
"homeassistant.components.test_integration",
|
||||
)
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(domain_constant_checker)
|
||||
|
||||
with assert_no_messages(linter):
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, domain_constant_checker, root_node)
|
||||
|
||||
@@ -2,11 +2,10 @@
|
||||
|
||||
import astroid
|
||||
from pylint.testutils import UnittestLinter
|
||||
from pylint.utils.ast_walker import ASTWalker
|
||||
from pylint_home_assistant.checkers.duplicate_const import DuplicateConstChecker
|
||||
import pytest
|
||||
|
||||
from . import assert_no_messages
|
||||
from . import assert_no_messages, walk_checker
|
||||
|
||||
# Pre-load homeassistant.const so astroid can resolve it.
|
||||
astroid.MANAGER.ast_from_module_name("homeassistant.const")
|
||||
@@ -64,11 +63,9 @@ def test_no_warning(
|
||||
) -> None:
|
||||
"""Test cases that should not trigger a warning."""
|
||||
root_node = astroid.parse(code, "homeassistant.components.test_integration.const")
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(duplicate_const_checker)
|
||||
|
||||
with assert_no_messages(linter):
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, duplicate_const_checker, root_node)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
@@ -121,9 +118,7 @@ def test_duplicate_const_flagged(
|
||||
) -> None:
|
||||
"""Test that duplicate constants are flagged."""
|
||||
root_node = astroid.parse(code, "homeassistant.components.test_integration.const")
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(duplicate_const_checker)
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, duplicate_const_checker, root_node)
|
||||
|
||||
messages = linter.release_messages()
|
||||
assert len(messages) == 1
|
||||
@@ -142,8 +137,6 @@ CONF_HOST = "host"
|
||||
""",
|
||||
"tests.components.test_integration.test_const",
|
||||
)
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(duplicate_const_checker)
|
||||
|
||||
with assert_no_messages(linter):
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, duplicate_const_checker, root_node)
|
||||
|
||||
@@ -2,13 +2,12 @@
|
||||
|
||||
import astroid
|
||||
from pylint.testutils import UnittestLinter
|
||||
from pylint.utils.ast_walker import ASTWalker
|
||||
from pylint_home_assistant.checkers.entity_description_defaults import (
|
||||
EntityDescriptionDefaultsChecker,
|
||||
)
|
||||
import pytest
|
||||
|
||||
from . import assert_no_messages
|
||||
from . import assert_no_messages, walk_checker
|
||||
|
||||
# Pre-load EntityDescription so astroid can resolve it in parsed snippets.
|
||||
# This avoids depending on component-level imports which may not be
|
||||
@@ -75,11 +74,9 @@ def test_no_warning(
|
||||
) -> None:
|
||||
"""Test cases that should not trigger a warning."""
|
||||
root_node = astroid.parse(code, "homeassistant.components.test_integration.sensor")
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(defaults_checker)
|
||||
|
||||
with assert_no_messages(linter):
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, defaults_checker, root_node)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
@@ -161,9 +158,7 @@ def test_redundant_default_flagged(
|
||||
) -> None:
|
||||
"""Test that redundant defaults are flagged."""
|
||||
root_node = astroid.parse(code, "homeassistant.components.test_integration.sensor")
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(defaults_checker)
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, defaults_checker, root_node)
|
||||
|
||||
messages = linter.release_messages()
|
||||
assert len(messages) == 1
|
||||
@@ -185,11 +180,9 @@ JobDescription(icon=None)
|
||||
""",
|
||||
"homeassistant.components.test_integration.sensor",
|
||||
)
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(defaults_checker)
|
||||
|
||||
with assert_no_messages(linter):
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, defaults_checker, root_node)
|
||||
|
||||
|
||||
def test_local_entity_description_name_ignored(
|
||||
@@ -209,11 +202,9 @@ MyDescription(entity_registry_enabled_default=True)
|
||||
""",
|
||||
"homeassistant.components.test_integration.sensor",
|
||||
)
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(defaults_checker)
|
||||
|
||||
with assert_no_messages(linter):
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, defaults_checker, root_node)
|
||||
|
||||
|
||||
def test_aliased_description_flagged(
|
||||
@@ -230,9 +221,7 @@ Alias(key="temperature", icon=None)
|
||||
""",
|
||||
"homeassistant.components.test_integration.sensor",
|
||||
)
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(defaults_checker)
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, defaults_checker, root_node)
|
||||
|
||||
messages = linter.release_messages()
|
||||
assert len(messages) == 1
|
||||
@@ -256,8 +245,6 @@ EntityDescription(
|
||||
""",
|
||||
"tests.components.test_integration.test_sensor",
|
||||
)
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(defaults_checker)
|
||||
|
||||
with assert_no_messages(linter):
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, defaults_checker, root_node)
|
||||
|
||||
@@ -6,14 +6,13 @@ from pathlib import Path
|
||||
import astroid
|
||||
from astroid import nodes
|
||||
from pylint.testutils import MessageTest, UnittestLinter
|
||||
from pylint.utils.ast_walker import ASTWalker
|
||||
from pylint_home_assistant.checkers.entity_unique_id_format import (
|
||||
EntityUniqueIdFormatChecker,
|
||||
)
|
||||
from pylint_home_assistant.helpers.integration import clear_caches
|
||||
import pytest
|
||||
|
||||
from . import assert_adds_messages, assert_no_messages
|
||||
from . import assert_adds_messages, assert_no_messages, walk_checker
|
||||
|
||||
|
||||
@pytest.fixture(name="checker")
|
||||
@@ -181,10 +180,8 @@ def test_redundant_domain_fires(
|
||||
|
||||
root_node = _parse(code, integration_dir)
|
||||
value_node = _find_attr_value_node(root_node)
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(checker)
|
||||
with assert_adds_messages(linter, _expect_redundant_domain(value_node, "MySensor")):
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, checker, root_node)
|
||||
|
||||
|
||||
def test_redundant_domain_fires_in_both_branches(
|
||||
@@ -223,14 +220,12 @@ class MySensor(Entity):
|
||||
)
|
||||
]
|
||||
assert len(value_nodes) == 2
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(checker)
|
||||
with assert_adds_messages(
|
||||
linter,
|
||||
_expect_redundant_domain(value_nodes[0], "MySensor"),
|
||||
_expect_redundant_domain(value_nodes[1], "MySensor"),
|
||||
):
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, checker, root_node)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
@@ -280,10 +275,8 @@ def test_redundant_domain_does_not_fire(
|
||||
integration_dir = _make_integration(tmp_path)
|
||||
|
||||
root_node = _parse(code, integration_dir)
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(checker)
|
||||
with assert_no_messages(linter):
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, checker, root_node)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
@@ -370,9 +363,7 @@ def test_redundant_domain_literal_fires(
|
||||
integration_dir = _make_integration(tmp_path, domain="myhub")
|
||||
|
||||
root_node = _parse(code, integration_dir)
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(checker)
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, checker, root_node)
|
||||
messages = linter.release_messages()
|
||||
assert len(messages) == 1
|
||||
assert messages[0].msg_id == "home-assistant-entity-unique-id-redundant-domain"
|
||||
@@ -410,9 +401,7 @@ class MySensor(Entity):
|
||||
""",
|
||||
integration_dir,
|
||||
)
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(checker)
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, checker, root_node)
|
||||
messages = linter.release_messages()
|
||||
assert len(messages) == (1 if fires else 0)
|
||||
|
||||
@@ -492,10 +481,8 @@ def test_redundant_domain_literal_does_not_fire_on_word_substrings(
|
||||
integration_dir = _make_integration(tmp_path, domain="myhub")
|
||||
|
||||
root_node = _parse(code, integration_dir)
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(checker)
|
||||
with assert_no_messages(linter):
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, checker, root_node)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
@@ -539,12 +526,10 @@ def test_redundant_domain_fires_in_unique_id_property(
|
||||
|
||||
root_node = _parse(code, integration_dir)
|
||||
return_node = next(root_node.nodes_of_class(nodes.Return))
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(checker)
|
||||
with assert_adds_messages(
|
||||
linter, _expect_redundant_domain(return_node.value, "MySensor")
|
||||
):
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, checker, root_node)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
@@ -591,10 +576,8 @@ def test_out_of_scope_ignored(
|
||||
root_node = _parse(
|
||||
code, integration_dir, module_name=module_name, file_name=file_name
|
||||
)
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(checker)
|
||||
with assert_no_messages(linter):
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, checker, root_node)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
@@ -640,10 +623,8 @@ class MyEntity(Entity):
|
||||
file_name=file_name,
|
||||
)
|
||||
value_node = _find_attr_value_node(root_node)
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(checker)
|
||||
with assert_adds_messages(linter, _expect_redundant_domain(value_node, "MyEntity")):
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, checker, root_node)
|
||||
|
||||
|
||||
def test_same_module_mixin_base_fires(
|
||||
@@ -674,9 +655,7 @@ class MyConcreteSensor(MyBaseSensor):
|
||||
integration_dir,
|
||||
)
|
||||
value_node = _find_attr_value_node(root_node)
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(checker)
|
||||
with assert_adds_messages(
|
||||
linter, _expect_redundant_domain(value_node, "MyBaseSensor")
|
||||
):
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, checker, root_node)
|
||||
|
||||
@@ -5,7 +5,6 @@ from pathlib import Path
|
||||
|
||||
import astroid
|
||||
from pylint.testutils import UnittestLinter
|
||||
from pylint.utils.ast_walker import ASTWalker
|
||||
from pylint_home_assistant.checkers.exception_translations import (
|
||||
ExceptionTranslationsChecker,
|
||||
)
|
||||
@@ -14,7 +13,7 @@ from pylint_home_assistant.helpers.translations import clear_translations_cache
|
||||
import pytest
|
||||
import yaml
|
||||
|
||||
from . import assert_no_messages
|
||||
from . import assert_no_messages, walk_checker
|
||||
|
||||
# Pre-load so astroid can resolve exception classes in parsed snippets.
|
||||
astroid.MANAGER.ast_from_module_name("homeassistant.exceptions")
|
||||
@@ -125,11 +124,8 @@ def test_no_warning(
|
||||
root_node = astroid.parse(code, "homeassistant.components.test_int.coordinator")
|
||||
root_node.file = str(integration_dir / "coordinator.py")
|
||||
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(translations_checker)
|
||||
|
||||
with assert_no_messages(linter):
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, translations_checker, root_node)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
@@ -164,9 +160,7 @@ def test_hardcoded_string_flagged(
|
||||
root_node = astroid.parse(code, "homeassistant.components.test_int.coordinator")
|
||||
root_node.file = str(integration_dir / "coordinator.py")
|
||||
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(translations_checker)
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, translations_checker, root_node)
|
||||
|
||||
messages = linter.release_messages()
|
||||
assert len(messages) == 1
|
||||
@@ -218,9 +212,7 @@ def test_translation_key_domain_mismatch_flagged(
|
||||
)
|
||||
root_node.file = str(integration_dir / "coordinator.py")
|
||||
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(translations_checker)
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, translations_checker, root_node)
|
||||
|
||||
messages = linter.release_messages()
|
||||
assert len(messages) == 1
|
||||
@@ -249,9 +241,7 @@ raise HomeAssistantError(
|
||||
)
|
||||
root_node.file = str(integration_dir / "coordinator.py")
|
||||
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(translations_checker)
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, translations_checker, root_node)
|
||||
|
||||
messages = linter.release_messages()
|
||||
assert len(messages) == 1
|
||||
@@ -280,9 +270,7 @@ raise HomeAssistantError(
|
||||
)
|
||||
root_node.file = str(integration_dir / "coordinator.py")
|
||||
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(translations_checker)
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, translations_checker, root_node)
|
||||
|
||||
messages = linter.release_messages()
|
||||
assert len(messages) == 1
|
||||
@@ -312,11 +300,8 @@ raise HomeAssistantError(
|
||||
)
|
||||
root_node.file = str(integration_dir / "coordinator.py")
|
||||
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(translations_checker)
|
||||
|
||||
with assert_no_messages(linter):
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, translations_checker, root_node)
|
||||
|
||||
|
||||
def test_extra_placeholders_flagged(
|
||||
@@ -344,9 +329,7 @@ raise HomeAssistantError(
|
||||
)
|
||||
root_node.file = str(integration_dir / "coordinator.py")
|
||||
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(translations_checker)
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, translations_checker, root_node)
|
||||
|
||||
messages = linter.release_messages()
|
||||
assert len(messages) == 1
|
||||
@@ -378,9 +361,7 @@ raise HomeAssistantError(
|
||||
)
|
||||
root_node.file = str(integration_dir / "coordinator.py")
|
||||
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(translations_checker)
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, translations_checker, root_node)
|
||||
|
||||
messages = linter.release_messages()
|
||||
assert len(messages) == 1
|
||||
@@ -412,11 +393,8 @@ raise HomeAssistantError(
|
||||
)
|
||||
root_node.file = str(integration_dir / "coordinator.py")
|
||||
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(translations_checker)
|
||||
|
||||
with assert_no_messages(linter):
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, translations_checker, root_node)
|
||||
|
||||
|
||||
def test_placeholder_variable_resolved(
|
||||
@@ -445,11 +423,8 @@ raise HomeAssistantError(
|
||||
)
|
||||
root_node.file = str(integration_dir / "coordinator.py")
|
||||
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(translations_checker)
|
||||
|
||||
with assert_no_messages(linter):
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, translations_checker, root_node)
|
||||
|
||||
|
||||
def test_placeholder_variable_mismatch_flagged(
|
||||
@@ -478,9 +453,7 @@ raise HomeAssistantError(
|
||||
)
|
||||
root_node.file = str(integration_dir / "coordinator.py")
|
||||
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(translations_checker)
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, translations_checker, root_node)
|
||||
|
||||
messages = linter.release_messages()
|
||||
assert len(messages) == 1
|
||||
@@ -513,11 +486,8 @@ raise HomeAssistantError(
|
||||
)
|
||||
root_node.file = str(integration_dir / "coordinator.py")
|
||||
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(translations_checker)
|
||||
|
||||
with assert_no_messages(linter):
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, translations_checker, root_node)
|
||||
|
||||
|
||||
def test_constant_placeholder_keys_ok(
|
||||
@@ -546,11 +516,8 @@ raise HomeAssistantError(
|
||||
)
|
||||
root_node.file = str(integration_dir / "coordinator.py")
|
||||
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(translations_checker)
|
||||
|
||||
with assert_no_messages(linter):
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, translations_checker, root_node)
|
||||
|
||||
|
||||
def test_key_reference_resolution(
|
||||
@@ -588,11 +555,8 @@ raise HomeAssistantError(
|
||||
)
|
||||
root_node.file = str(integration_dir / "coordinator.py")
|
||||
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(translations_checker)
|
||||
|
||||
with assert_no_messages(linter):
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, translations_checker, root_node)
|
||||
|
||||
|
||||
def test_no_strings_json_flags_missing_key(
|
||||
@@ -614,9 +578,7 @@ raise HomeAssistantError(
|
||||
)
|
||||
root_node.file = str(integration_dir / "coordinator.py")
|
||||
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(translations_checker)
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, translations_checker, root_node)
|
||||
|
||||
messages = linter.release_messages()
|
||||
assert len(messages) == 1
|
||||
@@ -647,9 +609,7 @@ raise HomeAssistantError(
|
||||
)
|
||||
root_node.file = str(integration_dir / "coordinator.py")
|
||||
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(translations_checker)
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, translations_checker, root_node)
|
||||
|
||||
messages = linter.release_messages()
|
||||
assert len(messages) == 1
|
||||
@@ -682,9 +642,7 @@ raise HomeAssistantError(
|
||||
)
|
||||
root_node.file = str(integration_dir / "coordinator.py")
|
||||
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(translations_checker)
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, translations_checker, root_node)
|
||||
|
||||
messages = linter.release_messages()
|
||||
assert len(messages) == 1
|
||||
@@ -700,8 +658,6 @@ def test_not_integration_ignored(
|
||||
f'{_HA_IMPORTS}\nraise HomeAssistantError("hardcoded")',
|
||||
"tests.components.test_integration",
|
||||
)
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(translations_checker)
|
||||
|
||||
with assert_no_messages(linter):
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, translations_checker, root_node)
|
||||
|
||||
@@ -3,10 +3,9 @@
|
||||
import astroid
|
||||
from pylint.checkers import BaseChecker
|
||||
from pylint.testutils.unittest_linter import UnittestLinter
|
||||
from pylint.utils.ast_walker import ASTWalker
|
||||
import pytest
|
||||
|
||||
from . import assert_no_messages
|
||||
from . import assert_no_messages, walk_checker
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
@@ -77,11 +76,9 @@ def test_enforce_greek_micro_char(
|
||||
) -> None:
|
||||
"""Good test cases."""
|
||||
root_node = astroid.parse(code, "homeassistant.components.pylint_test")
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(enforce_greek_micro_char_checker)
|
||||
|
||||
with assert_no_messages(linter):
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, enforce_greek_micro_char_checker, root_node)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
@@ -153,10 +150,8 @@ def test_enforce_greek_micro_char_assign_bad(
|
||||
) -> None:
|
||||
"""Bad assignment test cases."""
|
||||
root_node = astroid.parse(code, "homeassistant.components.pylint_test")
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(enforce_greek_micro_char_checker)
|
||||
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, enforce_greek_micro_char_checker, root_node)
|
||||
messages = linter.release_messages()
|
||||
assert len(messages) == 1
|
||||
message = next(iter(messages))
|
||||
|
||||
@@ -5,12 +5,11 @@ from pathlib import Path
|
||||
|
||||
import astroid
|
||||
from pylint.testutils import UnittestLinter
|
||||
from pylint.utils.ast_walker import ASTWalker
|
||||
from pylint_home_assistant.checkers.mdi_icons import MdiIconsChecker
|
||||
from pylint_home_assistant.helpers.icons import clear_icons_cache
|
||||
import pytest
|
||||
|
||||
from . import assert_no_messages
|
||||
from . import assert_no_messages, walk_checker
|
||||
|
||||
|
||||
@pytest.fixture(name="mdi_checker")
|
||||
@@ -78,11 +77,9 @@ def test_python_no_warning(
|
||||
) -> None:
|
||||
"""Test that valid MDI icons in Python code pass."""
|
||||
root_node = astroid.parse(code, "homeassistant.components.test_integration.sensor")
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(mdi_checker)
|
||||
|
||||
with assert_no_messages(linter):
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, mdi_checker, root_node)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
@@ -118,9 +115,7 @@ def test_python_invalid_icon_flagged(
|
||||
) -> None:
|
||||
"""Test that invalid MDI icons in Python code are flagged."""
|
||||
root_node = astroid.parse(code, "homeassistant.components.test_integration.sensor")
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(mdi_checker)
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, mdi_checker, root_node)
|
||||
|
||||
messages = linter.release_messages()
|
||||
assert len(messages) == 1
|
||||
@@ -137,11 +132,9 @@ def test_python_not_integration_ignored(
|
||||
'ICON = "mdi:nonexistent-icon"',
|
||||
"tests.components.test_integration",
|
||||
)
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(mdi_checker)
|
||||
|
||||
with assert_no_messages(linter):
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, mdi_checker, root_node)
|
||||
|
||||
|
||||
# --- icons.json tests ---
|
||||
@@ -173,11 +166,8 @@ def test_icons_json_valid(
|
||||
)
|
||||
root_node.file = str(integration_dir / "__init__.py")
|
||||
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(mdi_checker)
|
||||
|
||||
with assert_no_messages(linter):
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, mdi_checker, root_node)
|
||||
|
||||
|
||||
def test_icons_json_invalid_flagged(
|
||||
@@ -203,9 +193,7 @@ def test_icons_json_invalid_flagged(
|
||||
)
|
||||
root_node.file = str(integration_dir / "__init__.py")
|
||||
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(mdi_checker)
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, mdi_checker, root_node)
|
||||
|
||||
messages = linter.release_messages()
|
||||
assert len(messages) == 1
|
||||
@@ -227,11 +215,8 @@ def test_icons_json_no_file_no_warning(
|
||||
)
|
||||
root_node.file = str(integration_dir / "__init__.py")
|
||||
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(mdi_checker)
|
||||
|
||||
with assert_no_messages(linter):
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, mdi_checker, root_node)
|
||||
|
||||
|
||||
def test_icons_json_nested_invalid_flagged(
|
||||
@@ -265,9 +250,7 @@ def test_icons_json_nested_invalid_flagged(
|
||||
)
|
||||
root_node.file = str(integration_dir / "__init__.py")
|
||||
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(mdi_checker)
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, mdi_checker, root_node)
|
||||
|
||||
messages = linter.release_messages()
|
||||
assert len(messages) == 1
|
||||
|
||||
@@ -3,10 +3,9 @@
|
||||
import astroid
|
||||
from pylint.checkers import BaseChecker
|
||||
from pylint.testutils.unittest_linter import UnittestLinter
|
||||
from pylint.utils.ast_walker import ASTWalker
|
||||
import pytest
|
||||
|
||||
from . import assert_no_messages
|
||||
from . import assert_no_messages, walk_checker
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
@@ -71,11 +70,9 @@ def test_enforce_naive_now_good(
|
||||
) -> None:
|
||||
"""Good test cases -- no message expected."""
|
||||
root_node = astroid.parse(code, "homeassistant.components.pylint_test")
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(enforce_naive_now_checker)
|
||||
|
||||
with assert_no_messages(linter):
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, enforce_naive_now_checker, root_node)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
@@ -158,10 +155,8 @@ def test_enforce_naive_now_bad(
|
||||
) -> None:
|
||||
"""Bad test cases -- one message expected per call."""
|
||||
root_node = astroid.parse(code, "homeassistant.components.pylint_test")
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(enforce_naive_now_checker)
|
||||
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, enforce_naive_now_checker, root_node)
|
||||
messages = linter.release_messages()
|
||||
assert len(messages) == 1
|
||||
assert messages[0].msg_id == "home-assistant-enforce-naive-now"
|
||||
@@ -197,8 +192,6 @@ def test_enforce_naive_now_skips_util_dt(
|
||||
) -> None:
|
||||
"""``homeassistant.util.dt`` defines ``naive_now`` itself, so it is skipped."""
|
||||
root_node = astroid.parse(code, "homeassistant.util.dt")
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(enforce_naive_now_checker)
|
||||
|
||||
with assert_no_messages(linter):
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, enforce_naive_now_checker, root_node)
|
||||
|
||||
@@ -3,10 +3,9 @@
|
||||
import astroid
|
||||
from pylint.checkers import BaseChecker
|
||||
from pylint.testutils.unittest_linter import UnittestLinter
|
||||
from pylint.utils.ast_walker import ASTWalker
|
||||
import pytest
|
||||
|
||||
from . import assert_no_messages
|
||||
from . import assert_no_messages, walk_checker
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
@@ -136,11 +135,9 @@ def test_enforce_now_good(
|
||||
) -> None:
|
||||
"""Good test cases -- no message expected."""
|
||||
root_node = astroid.parse(code, "homeassistant.components.pylint_test")
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(enforce_now_checker)
|
||||
|
||||
with assert_no_messages(linter):
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, enforce_now_checker, root_node)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
@@ -230,10 +227,8 @@ def test_enforce_now_bad(
|
||||
) -> None:
|
||||
"""Bad test cases -- one message expected per call."""
|
||||
root_node = astroid.parse(code, "homeassistant.components.pylint_test")
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(enforce_now_checker)
|
||||
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, enforce_now_checker, root_node)
|
||||
messages = linter.release_messages()
|
||||
assert len(messages) == 1
|
||||
assert messages[0].msg_id == "home-assistant-enforce-now"
|
||||
@@ -270,8 +265,6 @@ def test_enforce_now_skips_util_dt(
|
||||
) -> None:
|
||||
"""``homeassistant.util.dt`` defines ``now`` itself, so it is skipped."""
|
||||
root_node = astroid.parse(code, "homeassistant.util.dt")
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(enforce_now_checker)
|
||||
|
||||
with assert_no_messages(linter):
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, enforce_now_checker, root_node)
|
||||
|
||||
@@ -5,10 +5,9 @@ from pathlib import Path
|
||||
import astroid
|
||||
from pylint.checkers import BaseChecker
|
||||
from pylint.testutils.unittest_linter import UnittestLinter
|
||||
from pylint.utils.ast_walker import ASTWalker
|
||||
import pytest
|
||||
|
||||
from . import assert_no_messages
|
||||
from . import assert_no_messages, walk_checker
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
@@ -104,11 +103,9 @@ def test_enforce_runtime_data(
|
||||
) -> None:
|
||||
"""Good test cases."""
|
||||
root_node = astroid.parse(code, module_name)
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(enforce_runtime_data_checker)
|
||||
|
||||
with assert_no_messages(linter):
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, enforce_runtime_data_checker, root_node)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
@@ -160,10 +157,8 @@ def test_enforce_runtime_data_bad(
|
||||
) -> None:
|
||||
"""Bad test cases."""
|
||||
root_node = astroid.parse(code, module_name)
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(enforce_runtime_data_checker)
|
||||
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, enforce_runtime_data_checker, root_node)
|
||||
messages = linter.release_messages()
|
||||
assert len(messages) == 1
|
||||
assert messages[0].msg_id == "home-assistant-use-runtime-data"
|
||||
@@ -187,11 +182,8 @@ def test_enforce_runtime_data_no_config_flow(
|
||||
root_node = astroid.parse(code, "homeassistant.components.yaml_only")
|
||||
root_node.file = str(init_file)
|
||||
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(enforce_runtime_data_checker)
|
||||
|
||||
with assert_no_messages(linter):
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, enforce_runtime_data_checker, root_node)
|
||||
|
||||
|
||||
def test_enforce_runtime_data_with_config_flow(
|
||||
@@ -213,10 +205,7 @@ def test_enforce_runtime_data_with_config_flow(
|
||||
root_node = astroid.parse(code, "homeassistant.components.modern")
|
||||
root_node.file = str(init_file)
|
||||
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(enforce_runtime_data_checker)
|
||||
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, enforce_runtime_data_checker, root_node)
|
||||
messages = linter.release_messages()
|
||||
assert len(messages) == 1
|
||||
assert messages[0].msg_id == "home-assistant-use-runtime-data"
|
||||
|
||||
@@ -2,13 +2,12 @@
|
||||
|
||||
import astroid
|
||||
from pylint.testutils import UnittestLinter
|
||||
from pylint.utils.ast_walker import ASTWalker
|
||||
from pylint_home_assistant.checkers.sequential_executor_jobs import (
|
||||
SequentialExecutorJobsChecker,
|
||||
)
|
||||
import pytest
|
||||
|
||||
from . import assert_no_messages
|
||||
from . import assert_no_messages, walk_checker
|
||||
|
||||
|
||||
@pytest.fixture(name="executor_checker")
|
||||
@@ -56,11 +55,9 @@ def test_no_warning(
|
||||
) -> None:
|
||||
"""Test cases that should not trigger a warning."""
|
||||
root_node = astroid.parse(code, "homeassistant.components.test_integration")
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(executor_checker)
|
||||
|
||||
with assert_no_messages(linter):
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, executor_checker, root_node)
|
||||
|
||||
|
||||
def test_two_sequential_flagged(
|
||||
@@ -76,9 +73,7 @@ async def async_setup(hass, config):
|
||||
""",
|
||||
"homeassistant.components.test_integration",
|
||||
)
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(executor_checker)
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, executor_checker, root_node)
|
||||
|
||||
messages = linter.release_messages()
|
||||
assert len(messages) == 1
|
||||
@@ -99,9 +94,7 @@ async def async_setup(hass, config):
|
||||
""",
|
||||
"homeassistant.components.test_integration",
|
||||
)
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(executor_checker)
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, executor_checker, root_node)
|
||||
|
||||
messages = linter.release_messages()
|
||||
assert len(messages) == 2
|
||||
@@ -120,9 +113,7 @@ async def async_setup(hass, config):
|
||||
""",
|
||||
"homeassistant.components.test_integration",
|
||||
)
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(executor_checker)
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, executor_checker, root_node)
|
||||
|
||||
messages = linter.release_messages()
|
||||
assert len(messages) == 1
|
||||
@@ -144,9 +135,7 @@ async def async_setup(hass, config):
|
||||
""",
|
||||
"homeassistant.components.test_integration",
|
||||
)
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(executor_checker)
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, executor_checker, root_node)
|
||||
|
||||
messages = linter.release_messages()
|
||||
assert len(messages) == 1
|
||||
@@ -168,9 +157,7 @@ async def async_setup(hass, config):
|
||||
""",
|
||||
"homeassistant.components.test_integration",
|
||||
)
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(executor_checker)
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, executor_checker, root_node)
|
||||
|
||||
messages = linter.release_messages()
|
||||
assert len(messages) == 1
|
||||
@@ -193,9 +180,7 @@ async def async_setup(hass, config):
|
||||
""",
|
||||
"homeassistant.components.test_integration",
|
||||
)
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(executor_checker)
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, executor_checker, root_node)
|
||||
|
||||
messages = linter.release_messages()
|
||||
assert len(messages) == 1
|
||||
@@ -218,9 +203,7 @@ async def async_setup(hass, config):
|
||||
""",
|
||||
"homeassistant.components.test_integration",
|
||||
)
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(executor_checker)
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, executor_checker, root_node)
|
||||
|
||||
messages = linter.release_messages()
|
||||
assert len(messages) == 1
|
||||
@@ -240,9 +223,7 @@ async def async_setup(hass, config):
|
||||
""",
|
||||
"homeassistant.components.test_integration",
|
||||
)
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(executor_checker)
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, executor_checker, root_node)
|
||||
|
||||
messages = linter.release_messages()
|
||||
assert len(messages) == 1
|
||||
@@ -262,8 +243,6 @@ async def async_setup(hass, config):
|
||||
""",
|
||||
"tests.components.test_integration",
|
||||
)
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(executor_checker)
|
||||
|
||||
with assert_no_messages(linter):
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, executor_checker, root_node)
|
||||
|
||||
@@ -5,10 +5,9 @@ from pylint.checkers import BaseChecker
|
||||
from pylint.interfaces import UNDEFINED
|
||||
from pylint.testutils import MessageTest
|
||||
from pylint.testutils.unittest_linter import UnittestLinter
|
||||
from pylint.utils.ast_walker import ASTWalker
|
||||
import pytest
|
||||
|
||||
from . import assert_adds_messages, assert_no_messages
|
||||
from . import assert_adds_messages, assert_no_messages, walk_checker
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
@@ -75,11 +74,9 @@ def test_enforce_sorted_platforms(
|
||||
) -> None:
|
||||
"""Good test cases."""
|
||||
root_node = astroid.parse(code, "homeassistant.components.pylint_test")
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(enforce_sorted_platforms_checker)
|
||||
|
||||
with assert_no_messages(linter):
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, enforce_sorted_platforms_checker, root_node)
|
||||
|
||||
|
||||
def test_enforce_sorted_platforms_bad(
|
||||
|
||||
@@ -7,10 +7,9 @@ from pylint.checkers import BaseChecker
|
||||
from pylint.interfaces import INFERENCE
|
||||
from pylint.testutils import MessageTest
|
||||
from pylint.testutils.unittest_linter import UnittestLinter
|
||||
from pylint.utils.ast_walker import ASTWalker
|
||||
import pytest
|
||||
|
||||
from . import assert_adds_messages, assert_no_messages
|
||||
from . import assert_adds_messages, assert_no_messages, walk_checker
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
@@ -117,8 +116,6 @@ def test_enforce_super_call(
|
||||
) -> None:
|
||||
"""Good test cases."""
|
||||
root_node = astroid.parse(code, "homeassistant.components.pylint_test")
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(super_call_checker)
|
||||
|
||||
with (
|
||||
patch(
|
||||
@@ -127,7 +124,7 @@ def test_enforce_super_call(
|
||||
),
|
||||
assert_no_messages(linter),
|
||||
):
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, super_call_checker, root_node)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
@@ -199,8 +196,6 @@ def test_enforce_super_call_bad(
|
||||
) -> None:
|
||||
"""Bad test cases."""
|
||||
root_node = astroid.parse(code, "homeassistant.components.pylint_test")
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(super_call_checker)
|
||||
node = root_node.body[node_idx].body[0]
|
||||
|
||||
with (
|
||||
@@ -222,4 +217,4 @@ def test_enforce_super_call_bad(
|
||||
),
|
||||
),
|
||||
):
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, super_call_checker, root_node)
|
||||
|
||||
@@ -2,13 +2,12 @@
|
||||
|
||||
import astroid
|
||||
from pylint.testutils import UnittestLinter
|
||||
from pylint.utils.ast_walker import ASTWalker
|
||||
from pylint_home_assistant.checkers.unnecessary_format_mac import (
|
||||
UnnecessaryFormatMacChecker,
|
||||
)
|
||||
import pytest
|
||||
|
||||
from . import assert_no_messages
|
||||
from . import assert_no_messages, walk_checker
|
||||
|
||||
_IMPORTS = """\
|
||||
from homeassistant.helpers.device_registry import (
|
||||
@@ -95,11 +94,8 @@ def test_no_warning(
|
||||
"""Test cases that should not trigger a warning."""
|
||||
root_node = astroid.parse(code, "homeassistant.components.test_integration.sensor")
|
||||
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(format_mac_checker)
|
||||
|
||||
with assert_no_messages(linter):
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, format_mac_checker, root_node)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
@@ -152,9 +148,7 @@ def test_format_mac_flagged(
|
||||
"""Warning when format_mac is used in connections= keyword argument."""
|
||||
root_node = astroid.parse(code, "homeassistant.components.test_integration.sensor")
|
||||
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(format_mac_checker)
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, format_mac_checker, root_node)
|
||||
|
||||
messages = linter.release_messages()
|
||||
assert len(messages) == 1
|
||||
@@ -174,8 +168,5 @@ device = DeviceInfo(
|
||||
"""
|
||||
root_node = astroid.parse(code, "some_other.module")
|
||||
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(format_mac_checker)
|
||||
|
||||
with assert_no_messages(linter):
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, format_mac_checker, root_node)
|
||||
|
||||
@@ -2,13 +2,12 @@
|
||||
|
||||
import astroid
|
||||
from pylint.testutils import UnittestLinter
|
||||
from pylint.utils.ast_walker import ASTWalker
|
||||
from pylint_home_assistant.checkers.unused_test_fixture_args import (
|
||||
UnusedTestFixtureArgsChecker,
|
||||
)
|
||||
import pytest
|
||||
|
||||
from . import assert_no_messages
|
||||
from . import assert_no_messages, walk_checker
|
||||
|
||||
|
||||
@pytest.fixture(name="unused_args_checker")
|
||||
@@ -68,11 +67,9 @@ def test_no_warning(
|
||||
) -> None:
|
||||
"""Test cases that should not trigger a warning."""
|
||||
root_node = astroid.parse(code, "tests.components.test_integration.test_init")
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(unused_args_checker)
|
||||
|
||||
with assert_no_messages(linter):
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, unused_args_checker, root_node)
|
||||
|
||||
|
||||
def test_unused_single_arg(
|
||||
@@ -87,9 +84,7 @@ def test_something(hass: HomeAssistant, enable_bluetooth: None) -> None:
|
||||
""",
|
||||
"tests.components.test_integration.test_init",
|
||||
)
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(unused_args_checker)
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, unused_args_checker, root_node)
|
||||
|
||||
messages = linter.release_messages()
|
||||
assert len(messages) == 1
|
||||
@@ -115,9 +110,7 @@ def test_something(
|
||||
""",
|
||||
"tests.components.test_integration.test_init",
|
||||
)
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(unused_args_checker)
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, unused_args_checker, root_node)
|
||||
|
||||
messages = linter.release_messages()
|
||||
assert len(messages) == 2
|
||||
@@ -137,11 +130,9 @@ def test_something(unused: str) -> None:
|
||||
""",
|
||||
"homeassistant.components.test_integration",
|
||||
)
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(unused_args_checker)
|
||||
|
||||
with assert_no_messages(linter):
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, unused_args_checker, root_node)
|
||||
|
||||
|
||||
def test_async_test_function(
|
||||
@@ -156,9 +147,7 @@ async def test_something(hass: HomeAssistant, enable_bluetooth: None) -> None:
|
||||
""",
|
||||
"tests.components.test_integration.test_init",
|
||||
)
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(unused_args_checker)
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, unused_args_checker, root_node)
|
||||
|
||||
messages = linter.release_messages()
|
||||
assert len(messages) == 1
|
||||
|
||||
@@ -3,10 +3,9 @@
|
||||
import astroid
|
||||
from pylint.checkers import BaseChecker
|
||||
from pylint.testutils.unittest_linter import UnittestLinter
|
||||
from pylint.utils.ast_walker import ASTWalker
|
||||
import pytest
|
||||
|
||||
from . import assert_no_messages
|
||||
from . import assert_no_messages, walk_checker
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
@@ -72,11 +71,9 @@ def test_enforce_utcnow_good(
|
||||
) -> None:
|
||||
"""Good test cases -- no message expected."""
|
||||
root_node = astroid.parse(code, "homeassistant.components.pylint_test")
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(enforce_utcnow_checker)
|
||||
|
||||
with assert_no_messages(linter):
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, enforce_utcnow_checker, root_node)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
@@ -243,10 +240,8 @@ def test_enforce_utcnow_bad(
|
||||
) -> None:
|
||||
"""Bad test cases -- one message expected per call."""
|
||||
root_node = astroid.parse(code, "homeassistant.components.pylint_test")
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(enforce_utcnow_checker)
|
||||
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, enforce_utcnow_checker, root_node)
|
||||
messages = linter.release_messages()
|
||||
assert len(messages) == 1
|
||||
assert messages[0].msg_id == "home-assistant-enforce-utcnow"
|
||||
@@ -282,8 +277,6 @@ def test_enforce_utcnow_skips_util_dt(
|
||||
) -> None:
|
||||
"""``homeassistant.util.dt`` defines ``utcnow`` itself, so it is skipped."""
|
||||
root_node = astroid.parse(code, "homeassistant.util.dt")
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(enforce_utcnow_checker)
|
||||
|
||||
with assert_no_messages(linter):
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, enforce_utcnow_checker, root_node)
|
||||
|
||||
@@ -2,13 +2,12 @@
|
||||
|
||||
import astroid
|
||||
from pylint.testutils import UnittestLinter
|
||||
from pylint.utils.ast_walker import ASTWalker
|
||||
from pylint_home_assistant.checkers.tests.direct_async_migrate_entry import (
|
||||
DirectAsyncMigrateEntry,
|
||||
)
|
||||
import pytest
|
||||
|
||||
from tests.pylint import assert_no_messages
|
||||
from tests.pylint import assert_no_messages, walk_checker
|
||||
|
||||
# Pre-load so astroid can resolve ``async_migrate_entry`` in parsed snippets.
|
||||
astroid.MANAGER.ast_from_module_name("homeassistant.components.ps4")
|
||||
@@ -70,11 +69,9 @@ def test_no_warning(
|
||||
) -> None:
|
||||
"""Test cases that should not trigger a warning."""
|
||||
root_node = astroid.parse(code, module_name)
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(checker)
|
||||
|
||||
with assert_no_messages(linter):
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, checker, root_node)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
@@ -110,9 +107,7 @@ def test_warning(
|
||||
) -> None:
|
||||
"""Test cases that should trigger a warning."""
|
||||
root_node = astroid.parse(code, module_name)
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(checker)
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, checker, root_node)
|
||||
|
||||
messages = linter.release_messages()
|
||||
assert len(messages) == 1
|
||||
@@ -136,9 +131,7 @@ async def test_b(hass, mock_config_entry):
|
||||
""",
|
||||
"tests.components.ps4.test_init",
|
||||
)
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(checker)
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, checker, root_node)
|
||||
|
||||
messages = linter.release_messages()
|
||||
assert len(messages) == 2
|
||||
|
||||
@@ -2,11 +2,10 @@
|
||||
|
||||
import astroid
|
||||
from pylint.testutils import UnittestLinter
|
||||
from pylint.utils.ast_walker import ASTWalker
|
||||
from pylint_home_assistant.checkers.tests.direct_async_setup import DirectAsyncSetup
|
||||
import pytest
|
||||
|
||||
from tests.pylint import assert_no_messages
|
||||
from tests.pylint import assert_no_messages, walk_checker
|
||||
|
||||
# Pre-load so astroid can resolve ``async_setup`` in parsed snippets.
|
||||
astroid.MANAGER.ast_from_module_name("homeassistant.components.ps4")
|
||||
@@ -78,11 +77,9 @@ def test_no_warning(
|
||||
) -> None:
|
||||
"""Test cases that should not trigger a warning."""
|
||||
root_node = astroid.parse(code, module_name)
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(checker)
|
||||
|
||||
with assert_no_messages(linter):
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, checker, root_node)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
@@ -118,9 +115,7 @@ def test_warning(
|
||||
) -> None:
|
||||
"""Test cases that should trigger a warning."""
|
||||
root_node = astroid.parse(code, module_name)
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(checker)
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, checker, root_node)
|
||||
|
||||
messages = linter.release_messages()
|
||||
assert len(messages) == 1
|
||||
@@ -144,9 +139,7 @@ async def test_b(hass):
|
||||
""",
|
||||
"tests.components.ps4.test_init",
|
||||
)
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(checker)
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, checker, root_node)
|
||||
|
||||
messages = linter.release_messages()
|
||||
assert len(messages) == 2
|
||||
|
||||
@@ -2,13 +2,12 @@
|
||||
|
||||
import astroid
|
||||
from pylint.testutils import UnittestLinter
|
||||
from pylint.utils.ast_walker import ASTWalker
|
||||
from pylint_home_assistant.checkers.tests.direct_async_setup_entry import (
|
||||
DirectAsyncSetupEntry,
|
||||
)
|
||||
import pytest
|
||||
|
||||
from tests.pylint import assert_no_messages
|
||||
from tests.pylint import assert_no_messages, walk_checker
|
||||
|
||||
# Pre-load so astroid can resolve ``async_setup_entry`` in parsed snippets.
|
||||
astroid.MANAGER.ast_from_module_name("homeassistant.components.sun")
|
||||
@@ -71,11 +70,9 @@ def test_no_warning(
|
||||
) -> None:
|
||||
"""Test cases that should not trigger a warning."""
|
||||
root_node = astroid.parse(code, module_name)
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(checker)
|
||||
|
||||
with assert_no_messages(linter):
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, checker, root_node)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
@@ -136,9 +133,7 @@ def test_warning(
|
||||
) -> None:
|
||||
"""Test cases that should trigger a warning."""
|
||||
root_node = astroid.parse(code, module_name)
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(checker)
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, checker, root_node)
|
||||
|
||||
messages = linter.release_messages()
|
||||
assert len(messages) == 1
|
||||
@@ -162,9 +157,7 @@ async def test_b(hass, mock_config_entry):
|
||||
""",
|
||||
"tests.components.sun.test_init",
|
||||
)
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(checker)
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, checker, root_node)
|
||||
|
||||
messages = linter.release_messages()
|
||||
assert len(messages) == 2
|
||||
|
||||
@@ -2,13 +2,12 @@
|
||||
|
||||
import astroid
|
||||
from pylint.testutils import UnittestLinter
|
||||
from pylint.utils.ast_walker import ASTWalker
|
||||
from pylint_home_assistant.checkers.tests.direct_async_unload_entry import (
|
||||
DirectAsyncUnloadEntry,
|
||||
)
|
||||
import pytest
|
||||
|
||||
from tests.pylint import assert_no_messages
|
||||
from tests.pylint import assert_no_messages, walk_checker
|
||||
|
||||
# Pre-load so astroid can resolve ``async_unload_entry`` in parsed snippets.
|
||||
astroid.MANAGER.ast_from_module_name("homeassistant.components.ps4")
|
||||
@@ -70,11 +69,9 @@ def test_no_warning(
|
||||
) -> None:
|
||||
"""Test cases that should not trigger a warning."""
|
||||
root_node = astroid.parse(code, module_name)
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(checker)
|
||||
|
||||
with assert_no_messages(linter):
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, checker, root_node)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
@@ -110,9 +107,7 @@ def test_warning(
|
||||
) -> None:
|
||||
"""Test cases that should trigger a warning."""
|
||||
root_node = astroid.parse(code, module_name)
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(checker)
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, checker, root_node)
|
||||
|
||||
messages = linter.release_messages()
|
||||
assert len(messages) == 1
|
||||
@@ -136,9 +131,7 @@ async def test_b(hass, mock_config_entry):
|
||||
""",
|
||||
"tests.components.ps4.test_init",
|
||||
)
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(checker)
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, checker, root_node)
|
||||
|
||||
messages = linter.release_messages()
|
||||
assert len(messages) == 2
|
||||
|
||||
@@ -4,13 +4,12 @@ from pathlib import Path
|
||||
|
||||
import astroid
|
||||
from pylint.testutils import UnittestLinter
|
||||
from pylint.utils.ast_walker import ASTWalker
|
||||
from pylint_home_assistant.checkers.tests.redundant_usefixtures import (
|
||||
RedundantUsefixtures,
|
||||
)
|
||||
import pytest
|
||||
|
||||
from tests.pylint import assert_no_messages
|
||||
from tests.pylint import assert_no_messages, walk_checker
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
@@ -73,11 +72,9 @@ def test_no_warning(
|
||||
) -> None:
|
||||
"""Test cases that should not trigger a warning."""
|
||||
root_node = astroid.parse(code, "tests.components.test_integration.test_init")
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(usefixtures_checker)
|
||||
|
||||
with assert_no_messages(linter):
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, usefixtures_checker, root_node)
|
||||
|
||||
|
||||
def test_single_fixture_redundant(
|
||||
@@ -95,9 +92,7 @@ async def test_something(hass: HomeAssistant) -> None:
|
||||
""",
|
||||
"tests.components.test_integration.test_init",
|
||||
)
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(usefixtures_checker)
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, usefixtures_checker, root_node)
|
||||
|
||||
messages = linter.release_messages()
|
||||
assert len(messages) == 1
|
||||
@@ -120,9 +115,7 @@ async def test_something(hass: HomeAssistant) -> None:
|
||||
""",
|
||||
"tests.components.test_integration.test_init",
|
||||
)
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(usefixtures_checker)
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, usefixtures_checker, root_node)
|
||||
|
||||
messages = linter.release_messages()
|
||||
assert len(messages) == 1
|
||||
@@ -144,9 +137,7 @@ async def test_something(hass: HomeAssistant) -> None:
|
||||
""",
|
||||
"tests.components.test_integration.test_init",
|
||||
)
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(usefixtures_checker)
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, usefixtures_checker, root_node)
|
||||
|
||||
messages = linter.release_messages()
|
||||
assert len(messages) == 1
|
||||
@@ -171,9 +162,7 @@ async def test_b(hass: HomeAssistant) -> None:
|
||||
""",
|
||||
"tests.components.test_integration.test_init",
|
||||
)
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(usefixtures_checker)
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, usefixtures_checker, root_node)
|
||||
|
||||
messages = linter.release_messages()
|
||||
assert len(messages) == 2
|
||||
@@ -202,9 +191,7 @@ async def test_something(hass: HomeAssistant) -> None:
|
||||
)
|
||||
root_node.file = str(test_dir / "test_init.py")
|
||||
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(usefixtures_checker)
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, usefixtures_checker, root_node)
|
||||
|
||||
messages = linter.release_messages()
|
||||
assert len(messages) == 1
|
||||
@@ -235,9 +222,7 @@ async def test_something(hass: HomeAssistant) -> None:
|
||||
)
|
||||
root_node.file = str(test_dir / "test_init.py")
|
||||
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(usefixtures_checker)
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, usefixtures_checker, root_node)
|
||||
|
||||
messages = linter.release_messages()
|
||||
assert len(messages) == 1
|
||||
@@ -268,9 +253,7 @@ async def test_something(hass: HomeAssistant) -> None:
|
||||
)
|
||||
root_node.file = str(test_dir / "test_init.py")
|
||||
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(usefixtures_checker)
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, usefixtures_checker, root_node)
|
||||
|
||||
messages = linter.release_messages()
|
||||
assert len(messages) == 1
|
||||
@@ -292,8 +275,6 @@ async def test_something(hass: HomeAssistant) -> None:
|
||||
""",
|
||||
"homeassistant.components.test_integration",
|
||||
)
|
||||
walker = ASTWalker(linter)
|
||||
walker.add_checker(usefixtures_checker)
|
||||
|
||||
with assert_no_messages(linter):
|
||||
walker.walk(root_node)
|
||||
walk_checker(linter, usefixtures_checker, root_node)
|
||||
|
||||
Reference in New Issue
Block a user