diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 62a86f3..ea5eb7a 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,4 +1,12 @@ repos: + - repo: local + hooks: + - id: sync-ha-version + name: Sync HA version from hacs.json + entry: python scripts/sync_ha_version.py + language: system + pass_filenames: false + files: ^(hacs\.json|requirements_dev\.txt)$ - repo: https://github.com/asottile/pyupgrade rev: v3.3.1 hooks: diff --git a/requirements_dev.txt b/requirements_dev.txt index 2c9a326..62999b0 100644 --- a/requirements_dev.txt +++ b/requirements_dev.txt @@ -1,5 +1,5 @@ -r requirements.txt -homeassistant==2022.7.7 +homeassistant==2024.12.0b0 black isort flake8 diff --git a/scripts/sync_ha_version.py b/scripts/sync_ha_version.py new file mode 100644 index 0000000..2a594f1 --- /dev/null +++ b/scripts/sync_ha_version.py @@ -0,0 +1,28 @@ +#!/usr/bin/env python3 +"""Sync homeassistant version in requirements_dev.txt to hacs.json.""" +import json +import re +from pathlib import Path + + +def main() -> int: + root = Path(__file__).parent.parent + + with open(root / "hacs.json") as f: + expected = json.load(f)["homeassistant"] + + req_path = root / "requirements_dev.txt" + with open(req_path) as f: + req_text = f.read() + new_req = re.sub(r"^homeassistant==.+$", f"homeassistant=={expected}", req_text, flags=re.MULTILINE) + if new_req != req_text: + with open(req_path, "w") as f: + f.write(new_req) + print(f"Fixed requirements_dev.txt homeassistant -> {expected}") + return 1 + + return 0 + + +if __name__ == "__main__": + raise SystemExit(main())