From bb0d6afff875079e273e1ba9665e099280aea167 Mon Sep 17 00:00:00 2001 From: Rob Hofmann Date: Sun, 15 Nov 2026 12:15:07 +0100 Subject: [PATCH 1/4] Run the test suite on Home Assistant 2026.11 with pytest-homeassistant pytest-homeassistant-custom-component stopped at Home Assistant 2026.10.4 and is now deprecated upstream. The suite was pinned to 2026.10, below the 2026.11 floor of the component, so the climate entity, which uses the native temperature members of 2026.11, could not be tested through Home Assistant. Replace it with pytest-homeassistant 2026.11.1, which home-assistant/core publishes from packages/pytest-homeassistant, one release per Home Assistant release. - Import MockConfigEntry from pytest_homeassistant.common. - Switch off the respx pytest plugin, as the package README asks. - Ignore two import-time DeprecationWarnings from code outside this repo: aiohttp on the HomeAssistantApplication subclass, and asyncio.iscoroutinefunction in the backoff package. - Drop the enable_custom_integrations fixture: the new hass fixture loads custom integrations by default. - Update the comments and docs that named the old plugin. 390 passed on Python 3.14 with Home Assistant 2026.11.1. --- .claude/skills/run-tests/SKILL.md | 2 +- docs/development.md | 32 +++++++++++++---------- pytest.ini | 14 +++++++++- requirements_dev.txt | 11 +++++--- tests/config_flow/conftest.py | 7 +++-- tests/config_flow/test_registry_lookup.py | 2 +- tests/conftest.py | 2 +- 7 files changed, 44 insertions(+), 26 deletions(-) diff --git a/.claude/skills/run-tests/SKILL.md b/.claude/skills/run-tests/SKILL.md index 373c7601..a6a2c68a 100644 --- a/.claude/skills/run-tests/SKILL.md +++ b/.claude/skills/run-tests/SKILL.md @@ -101,7 +101,7 @@ for. Do not widen the shared config. The suite covers the protocol layer, `custom_components/gree_custom/aiogree/`, and the config flow, in `tests/config_flow/`. The config flow tests run a real Home Assistant through -[pytest-homeassistant-custom-component](https://github.com/MatthewFlamm/pytest-homeassistant-custom-component), +[pytest-homeassistant](https://github.com/home-assistant/core/tree/dev/packages/pytest-homeassistant), against a fake Gree Cloud, a fake MQTT broker and fake units on loopback. It does not cover the entities, the coordinator beyond setup and unload, or the diff --git a/docs/development.md b/docs/development.md index 5dfe4c40..dd05a5ad 100644 --- a/docs/development.md +++ b/docs/development.md @@ -28,17 +28,21 @@ pytest It takes about 65 seconds: about 45 for the protocol tests and about 20 for the config flow. The first install takes a few minutes, because -`requirements_dev.txt` pins `pytest-homeassistant-custom-component`, which -brings one exact Home Assistant release (0.13.371 is Home Assistant 2026.10.0). -That plugin also pins pytest, pytest-asyncio and pytest-timeout. Bump it on +`requirements_dev.txt` pins `pytest-homeassistant`, which brings one exact +Home Assistant release. Its version is that release: 2026.11.1 is Home +Assistant 2026.11.1. It also pins pytest and pytest-asyncio. Bump it on purpose, in its own PR. -The pinned release is below the 2026.11 floor, because no release of the -plugin for Home Assistant 2026.11 exists yet. Bump it in its own PR when one -exists. Until then, `async_setup_entry` and `async_unload_entry` keep returning -`bool`: Home Assistant 2026.10 marks an entry as failed when setup returns -`None`. Since 2026.11 they may return `None`, and `async_unload_entry` can use -`async_unload_platforms_or_raise`. Make that change together with the bump. +The package is published from home-assistant/core, in +`packages/pytest-homeassistant`, one release for each Home Assistant release. +It replaces `pytest-homeassistant-custom-component`, which is deprecated and +stopped at Home Assistant 2026.10. That was below the 2026.11 floor of the +component. The climate entity uses the native temperature members that came +in 2026.11, so on 2026.10 no test could check it through Home Assistant. + +`async_setup_entry` and `async_unload_entry` still return `bool`. Since 2026.11 +they may return `None`, and `async_unload_entry` can use +`async_unload_platforms_or_raise`. That change is not made yet. Without a local Python 3.14, run it in a throwaway container: @@ -79,7 +83,7 @@ and says what to report. | `config_flow/test_compressor.py` | Compressor entities with and without compressor data, disabled by default, the outdoor sensor of a new and an existing device, `hvac_action` | | `config_flow/test_translations.py` | Every config flow key, exception and sensor name has a text in `en`, `nl` and `pt` | -360 tests in all, protocol and config flow together (HA 2026.10 pin, November 2026). The protocol tests cover about 94 percent of `aiogree/`. +390 tests in all, protocol and config flow together (HA 2026.11.1, November 2026). The protocol tests cover about 94 percent of `aiogree/`. One config flow test is a strict `xfail`: it shows a known defect and starts to fail as soon as the defect is fixed, so the marker gets removed with the fix. Check the coverage of the day with: @@ -102,10 +106,10 @@ tested. ### The config flow tests They use -[pytest-homeassistant-custom-component](https://github.com/MatthewFlamm/pytest-homeassistant-custom-component), -which extracts Home Assistant's own test plugins: the `hass` fixture, the flow -manager, the config entries and the registries. The component is loaded from -`custom_components/` through the `enable_custom_integrations` fixture. +[pytest-homeassistant](https://github.com/home-assistant/core/tree/dev/packages/pytest-homeassistant), +which ships Home Assistant's own test plugins: the `hass` fixture, the flow +manager, the config entries and the registries. The `hass` fixture loads the +component from `custom_components/` by default. `tests/config_flow/conftest.py` says per piece what is real: - The Gree Cloud is `FakeGreeCloud` on real HTTP. Only the server address of diff --git a/pytest.ini b/pytest.ini index b68b558b..9aff4c0c 100644 --- a/pytest.ini +++ b/pytest.ini @@ -12,8 +12,13 @@ pythonpath = custom_components/gree_custom testpaths = tests +# From the pytest-homeassistant README: switch off the pytest plugin of respx, +# so Home Assistant can install its httpx alias before respx is imported. The +# HTTP mocks of the package still use respx itself. +addopts = -p no:respx + # Async tests need no marker. Home Assistant's own test suite uses the same -# setting, and pytest-homeassistant-custom-component requires it. +# setting, and pytest-homeassistant requires it. asyncio_mode = auto asyncio_default_fixture_loop_scope = function @@ -28,3 +33,10 @@ filterwarnings = # "Event loop is closed" into the unraisable hook. It says nothing about # the code under test. ignore::pytest.PytestUnraisableExceptionWarning + # Two warnings raised at import time, by code outside this repo. Home + # Assistant's HTTP server subclasses aiohttp's web.Application, which + # aiohttp discourages. + ignore:Inheritance class HomeAssistantApplication:DeprecationWarning + # The backoff package calls asyncio.iscoroutinefunction, which Python 3.14 + # deprecates. + ignore:'asyncio.iscoroutinefunction' is deprecated:DeprecationWarning:backoff diff --git a/requirements_dev.txt b/requirements_dev.txt index 38b7e206..90537836 100755 --- a/requirements_dev.txt +++ b/requirements_dev.txt @@ -10,10 +10,13 @@ pytest>=8.4 pytest-asyncio>=1.0 pytest-timeout>=2.3 -# The config flow tests run a real Home Assistant. This plugin pins one exact -# Home Assistant release, and pytest, pytest-asyncio and pytest-timeout with -# it. 0.13.371 is Home Assistant 2026.10.0. Bump it on purpose, in its own PR. -pytest-homeassistant-custom-component==0.13.371 +# The config flow tests run a real Home Assistant. This plugin is published +# from home-assistant/core (packages/pytest-homeassistant), one release per +# Home Assistant release, and its version is that release. It pins Home +# Assistant, pytest and pytest-asyncio. It replaces +# pytest-homeassistant-custom-component, which is deprecated and stopped at +# Home Assistant 2026.10. Bump it on purpose, in its own PR. +pytest-homeassistant==2026.11.1 # Integration dependencies (from manifest) asyncio-dgram diff --git a/tests/config_flow/conftest.py b/tests/config_flow/conftest.py index b3e0bacf..9f623098 100644 --- a/tests/config_flow/conftest.py +++ b/tests/config_flow/conftest.py @@ -1,9 +1,9 @@ """Fixtures for the config flow tests. These tests run the shipped config flow inside a real Home Assistant, from -pytest-homeassistant-custom-component: the flow manager, the config entries, -the device registry and the reload after a flow. What is real and what is -faked: +pytest-homeassistant: the flow manager, the config entries, the device +registry and the reload after a flow. Its `hass` fixture loads the component +from `custom_components/` by default. What is real and what is faked: - Gree Cloud: `FakeGreeCloud`, real HTTP on loopback. Only the server address of the region changes, so the login and the device list run the real client. @@ -207,7 +207,6 @@ def component_logs() -> Iterator[RecordingHandler]: @pytest.fixture async def gree( hass: HomeAssistant, - enable_custom_integrations: None, monkeypatch: pytest.MonkeyPatch, loopback_ips: Callable[[int], list[str]], ) -> AsyncIterator[GreeEnv]: diff --git a/tests/config_flow/test_registry_lookup.py b/tests/config_flow/test_registry_lookup.py index fc5aff69..be634a69 100644 --- a/tests/config_flow/test_registry_lookup.py +++ b/tests/config_flow/test_registry_lookup.py @@ -9,7 +9,7 @@ # pytest pattern, not shadowing. import pytest -from pytest_homeassistant_custom_component.common import MockConfigEntry +from pytest_homeassistant.common import MockConfigEntry from custom_components.gree_custom.const import DOMAIN from custom_components.gree_custom.helpers import get_device_by_identifier diff --git a/tests/conftest.py b/tests/conftest.py index 55435927..08de308f 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -80,7 +80,7 @@ def warnings(self) -> list[str]: def loopback_sockets() -> None: """Allow sockets on loopback, and nowhere else. - pytest-homeassistant-custom-component blocks every socket before each + pytest-homeassistant blocks every socket before each test, and allows a connect only to 127.0.0.1. The fakes in this suite listen on real sockets anywhere in 127.0.0.0/8, so this opens that range again. A test that tries to reach a real Gree server or a real device From f750121239a64d403e9b6b6a31c4399e192dbc9a Mon Sep 17 00:00:00 2001 From: Rob Hofmann Date: Sun, 15 Nov 2026 12:49:39 +0100 Subject: [PATCH 2/4] Drop the version pins from requirements_dev.txt The devcontainer installs Home Assistant core from the dev branch, then requirements_dev.txt on top. Its exact pins clashed with what that core pins, and the old test plugin pinned homeassistant==2026.10.0, so the install broke after a core update. - requirements_dev.txt lists the tools and libraries with no pins, so they follow the core in the devcontainer. It keeps --upgrade. - The devcontainer installs pytest-homeassistant from .ha-core/packages/pytest-homeassistant. That copy has no Home Assistant pin. The copy on PyPI pins one release and would replace the core. - New requirements_test.txt adds the exact pins (pytest-homeassistant 2026.11.1 and Ruff 0.17.0) on top of requirements_dev.txt. CI and plain runs outside the devcontainer install it, so each run tests the same versions. 390 passed on Python 3.14 with pip install -r requirements_test.txt. --- .claude/skills/run-tests/SKILL.md | 4 ++-- .devcontainer/postCreate.sh | 5 +++++ .github/workflows/lint.yml | 2 +- .github/workflows/validate.yaml | 2 +- CONTRIBUTING.md | 2 +- docs/development.md | 18 ++++++++++++++---- requirements_dev.txt | 26 +++++++++++--------------- requirements_test.txt | 15 +++++++++++++++ 8 files changed, 50 insertions(+), 24 deletions(-) create mode 100644 requirements_test.txt diff --git a/.claude/skills/run-tests/SKILL.md b/.claude/skills/run-tests/SKILL.md index a6a2c68a..56ad4056 100644 --- a/.claude/skills/run-tests/SKILL.md +++ b/.claude/skills/run-tests/SKILL.md @@ -29,14 +29,14 @@ source .venv/bin/activate ```bash python3.14 -m venv .venv && source .venv/bin/activate -pip install -r requirements_dev.txt +pip install -r requirements_test.txt ``` **C. A container**, when there is no local 3.14: ```bash docker run --rm -v "$PWD:/src" -w /src python:3.14-slim sh -c \ - "python -m venv /venv && /venv/bin/pip install -q -r requirements_dev.txt && /venv/bin/pytest -q" + "python -m venv /venv && /venv/bin/pip install -q -r requirements_test.txt && /venv/bin/pytest -q" ``` The tests bind addresses out of `127.0.0.0/8`, so discovery tests need Linux. diff --git a/.devcontainer/postCreate.sh b/.devcontainer/postCreate.sh index 62b140c1..9a1ff6bd 100755 --- a/.devcontainer/postCreate.sh +++ b/.devcontainer/postCreate.sh @@ -54,6 +54,11 @@ echo "==> Compiling Home Assistant translations" python -m script.translations develop --all ) +echo "==> Installing pytest-homeassistant from the Home Assistant core checkout" +# The copy on PyPI pins one Home Assistant release and would replace the +# core installed above. This copy has no pin, so it matches that core. +python -m pip install --editable "$HA_SRC_DIR/packages/pytest-homeassistant" + echo "==> Installing dev/lint tooling" if [ -f requirements_dev.txt ]; then python -m pip install --upgrade -r requirements_dev.txt diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 899330d0..01c6ee1d 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -26,7 +26,7 @@ jobs: python-version: "3.14" - name: Install Ruff - # Pinned, same as requirements_dev.txt. A new Ruff release can add or + # Pinned, same as requirements_test.txt. A new Ruff release can add or # change rules, so bump it on purpose in its own PR. run: pip install "ruff==0.17.0" diff --git a/.github/workflows/validate.yaml b/.github/workflows/validate.yaml index 7217aaa8..77a0cbd4 100644 --- a/.github/workflows/validate.yaml +++ b/.github/workflows/validate.yaml @@ -48,7 +48,7 @@ jobs: python-version: "3.14" - name: Install dependencies - run: pip install -r requirements_dev.txt + run: pip install -r requirements_test.txt - name: Run the tests # The tests bind loopback addresses out of 127.0.0.0/8, which needs diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index e3bcf478..00c9362c 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -24,7 +24,7 @@ This repository includes a DevContainer to improve the development experience. T Run the test suite before you open a pull request: ```bash -pip install -r requirements_dev.txt +pip install -r requirements_test.txt pytest ``` diff --git a/docs/development.md b/docs/development.md index dd05a5ad..f9979af1 100644 --- a/docs/development.md +++ b/docs/development.md @@ -22,17 +22,27 @@ holds tests for the config flow that run inside a real Home Assistant. One `pytest` run does both. Run it from the repo root, on Linux: ```bash -pip install -r requirements_dev.txt +pip install -r requirements_test.txt pytest ``` It takes about 65 seconds: about 45 for the protocol tests and about 20 for the config flow. The first install takes a few minutes, because -`requirements_dev.txt` pins `pytest-homeassistant`, which brings one exact +`requirements_test.txt` pins `pytest-homeassistant`, which brings one exact Home Assistant release. Its version is that release: 2026.11.1 is Home Assistant 2026.11.1. It also pins pytest and pytest-asyncio. Bump it on purpose, in its own PR. +There are two requirement files: + +- `requirements_dev.txt` lists the tools and libraries with no version pins. + The devcontainer installs it after Home Assistant core from source, so the + versions follow that core. It installs `pytest-homeassistant` from + `.ha-core/packages/pytest-homeassistant`, because the copy on PyPI pins one + Home Assistant release and would replace the core. +- `requirements_test.txt` adds the exact pins: `pytest-homeassistant` and + Ruff. CI installs it, and so does a plain run outside the devcontainer. + The package is published from home-assistant/core, in `packages/pytest-homeassistant`, one release for each Home Assistant release. It replaces `pytest-homeassistant-custom-component`, which is deprecated and @@ -48,7 +58,7 @@ Without a local Python 3.14, run it in a throwaway container: ```bash docker run --rm -v "$PWD:/src" -w /src python:3.14-slim sh -c \ - "python -m venv /venv && /venv/bin/pip install -q -r requirements_dev.txt && /venv/bin/pytest -q" + "python -m venv /venv && /venv/bin/pip install -q -r requirements_test.txt && /venv/bin/pytest -q" ``` Only the config flow tests: @@ -260,7 +270,7 @@ Never log an encryption key, cloud password or token in clear text. `lint.yml` runs `ruff check` and `ruff format --check` on every push and PR. -Ruff is pinned to one exact version, in `lint.yml` and in `requirements_dev.txt`. Keep the two the same. New Ruff releases change rules: 0.16 and 0.17 want opposite forms of the same import, so no code passes both. Bump the pin in its own PR and run `ruff check --fix .` with the new version in that PR. +Ruff is pinned to one exact version, in `lint.yml` and in `requirements_test.txt`. Keep the two the same. The devcontainer does not use that pin, so its Ruff can be newer than the one in CI. New Ruff releases change rules: 0.16 and 0.17 want opposite forms of the same import, so no code passes both. Bump the pin in its own PR and run `ruff check --fix .` with the new version in that PR. `validate.yaml` runs three jobs on every push and PR: diff --git a/requirements_dev.txt b/requirements_dev.txt index 90537836..0308e81d 100755 --- a/requirements_dev.txt +++ b/requirements_dev.txt @@ -1,22 +1,18 @@ +# Dev and lint tooling, with no version pins. The devcontainer installs Home +# Assistant core from source first, and these resolve to whatever that core +# pins. requirements_test.txt adds the exact pins for CI and plain runs. + # Linting / formatting (same tool HA core uses) -ruff==0.17.0 +ruff # Additional static analysis - HA core's CI also runs these -pylint>=4.0.7 -mypy>=2.3.1 - -# Tests -pytest>=8.4 -pytest-asyncio>=1.0 -pytest-timeout>=2.3 +pylint +mypy -# The config flow tests run a real Home Assistant. This plugin is published -# from home-assistant/core (packages/pytest-homeassistant), one release per -# Home Assistant release, and its version is that release. It pins Home -# Assistant, pytest and pytest-asyncio. It replaces -# pytest-homeassistant-custom-component, which is deprecated and stopped at -# Home Assistant 2026.10. Bump it on purpose, in its own PR. -pytest-homeassistant==2026.11.1 +# Tests. pytest-homeassistant brings pytest and pytest-asyncio, and is not +# listed here: the devcontainer installs it from the Home Assistant core +# checkout, and requirements_test.txt pins it for everything else. +pytest-timeout # Integration dependencies (from manifest) asyncio-dgram diff --git a/requirements_test.txt b/requirements_test.txt new file mode 100644 index 00000000..412a289b --- /dev/null +++ b/requirements_test.txt @@ -0,0 +1,15 @@ +# What CI installs to run the tests, and what to install for a plain run +# outside the devcontainer. The exact pins make every run test the same +# versions. Bump them on purpose, in their own PR. +-r requirements_dev.txt + +# The config flow tests run a real Home Assistant. This plugin is published +# from home-assistant/core (packages/pytest-homeassistant), one release per +# Home Assistant release, and its version is that release. It pins Home +# Assistant, pytest and pytest-asyncio. It replaces +# pytest-homeassistant-custom-component, which is deprecated and stopped at +# Home Assistant 2026.10. +pytest-homeassistant==2026.11.1 + +# Same version as lint.yml. A new Ruff release can add or change rules. +ruff==0.17.0 From 2dfd222005a1114b641486053360e11237c7d8f8 Mon Sep 17 00:00:00 2001 From: Rob Hofmann Date: Sun, 15 Nov 2026 15:51:34 +0100 Subject: [PATCH 3/4] Install pytest-homeassistant in setup-ha-core.sh The task that updates Home Assistant to the latest dev branch runs setup-ha-core.sh on its own. With the plugin installed there, right after the core, that task keeps the two in step too. --- .devcontainer/postCreate.sh | 5 ----- .devcontainer/setup-ha-core.sh | 7 ++++++- docs/development.md | 8 +++++--- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/.devcontainer/postCreate.sh b/.devcontainer/postCreate.sh index 9a1ff6bd..62b140c1 100755 --- a/.devcontainer/postCreate.sh +++ b/.devcontainer/postCreate.sh @@ -54,11 +54,6 @@ echo "==> Compiling Home Assistant translations" python -m script.translations develop --all ) -echo "==> Installing pytest-homeassistant from the Home Assistant core checkout" -# The copy on PyPI pins one Home Assistant release and would replace the -# core installed above. This copy has no pin, so it matches that core. -python -m pip install --editable "$HA_SRC_DIR/packages/pytest-homeassistant" - echo "==> Installing dev/lint tooling" if [ -f requirements_dev.txt ]; then python -m pip install --upgrade -r requirements_dev.txt diff --git a/.devcontainer/setup-ha-core.sh b/.devcontainer/setup-ha-core.sh index 45875cb8..dfff6bdd 100755 --- a/.devcontainer/setup-ha-core.sh +++ b/.devcontainer/setup-ha-core.sh @@ -31,4 +31,9 @@ echo "==> Installing Home Assistant core requirements" "$PYTHON" -m uv pip install -r "$HA_SRC_DIR/requirements_all.txt" echo "==> Installing Home Assistant core" -"$PYTHON" -m uv pip install --upgrade --no-cache-dir --editable "$HA_SRC_DIR" --config-settings editable_mode=compat \ No newline at end of file +"$PYTHON" -m uv pip install --upgrade --no-cache-dir --editable "$HA_SRC_DIR" --config-settings editable_mode=compat + +echo "==> Installing pytest-homeassistant from the Home Assistant core checkout" +# The copy on PyPI pins one Home Assistant release and would replace the +# core installed above. This copy has no pin, so it matches that core. +"$PYTHON" -m uv pip install --editable "$HA_SRC_DIR/packages/pytest-homeassistant" diff --git a/docs/development.md b/docs/development.md index f9979af1..8906030b 100644 --- a/docs/development.md +++ b/docs/development.md @@ -37,9 +37,11 @@ There are two requirement files: - `requirements_dev.txt` lists the tools and libraries with no version pins. The devcontainer installs it after Home Assistant core from source, so the - versions follow that core. It installs `pytest-homeassistant` from - `.ha-core/packages/pytest-homeassistant`, because the copy on PyPI pins one - Home Assistant release and would replace the core. + versions follow that core. `.devcontainer/setup-ha-core.sh` installs + `pytest-homeassistant` from `.ha-core/packages/pytest-homeassistant`, right + after the core, because the copy on PyPI pins one Home Assistant release and + would replace the core. The task "Update Home Assistant to latest dev + branch" runs the same script, so the two stay in step. - `requirements_test.txt` adds the exact pins: `pytest-homeassistant` and Ruff. CI installs it, and so does a plain run outside the devcontainer. From 9065caa4ee609ca9dc5d1ccd38683f85ca38cebb Mon Sep 17 00:00:00 2001 From: Rob Hofmann Date: Sun, 15 Nov 2026 15:55:34 +0100 Subject: [PATCH 4/4] Install pytest-homeassistant with the same flags as the core Use --upgrade, --no-cache-dir and editable_mode=compat, as the core install above it does. --- .devcontainer/setup-ha-core.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.devcontainer/setup-ha-core.sh b/.devcontainer/setup-ha-core.sh index dfff6bdd..c207ddba 100755 --- a/.devcontainer/setup-ha-core.sh +++ b/.devcontainer/setup-ha-core.sh @@ -36,4 +36,4 @@ echo "==> Installing Home Assistant core" echo "==> Installing pytest-homeassistant from the Home Assistant core checkout" # The copy on PyPI pins one Home Assistant release and would replace the # core installed above. This copy has no pin, so it matches that core. -"$PYTHON" -m uv pip install --editable "$HA_SRC_DIR/packages/pytest-homeassistant" +"$PYTHON" -m uv pip install --upgrade --no-cache-dir --editable "$HA_SRC_DIR/packages/pytest-homeassistant" --config-settings editable_mode=compat