Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .claude/skills/run-tests/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion .devcontainer/setup-ha-core.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
"$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 --upgrade --no-cache-dir --editable "$HA_SRC_DIR/packages/pytest-homeassistant" --config-settings editable_mode=compat
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/validate.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```

Expand Down
50 changes: 33 additions & 17 deletions docs/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,29 +22,45 @@ 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-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_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.

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.
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. `.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.

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:

```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:
Expand Down Expand Up @@ -79,7 +95,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:
Expand All @@ -102,10 +118,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
Expand Down Expand Up @@ -256,7 +272,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:

Expand Down
14 changes: 13 additions & 1 deletion pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
23 changes: 11 additions & 12 deletions requirements_dev.txt
Original file line number Diff line number Diff line change
@@ -1,19 +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 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
# 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
Expand Down
15 changes: 15 additions & 0 deletions requirements_test.txt
Original file line number Diff line number Diff line change
@@ -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
7 changes: 3 additions & 4 deletions tests/config_flow/conftest.py
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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]:
Expand Down
2 changes: 1 addition & 1 deletion tests/config_flow/test_registry_lookup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading