|
| 1 | +# AGENTS.md |
| 2 | + |
| 3 | +Guidance for AI coding agents working on this repository. Human contributors: |
| 4 | +see [CONTRIBUTING](CONTRIBUTING.md). |
| 5 | + |
| 6 | +## Project |
| 7 | + |
| 8 | +`ojmicroline-thermostat`: an asynchronous Python client for OJ Microline cloud |
| 9 | +thermostats, published on PyPI. Its main consumer is the |
| 10 | +[Home Assistant integration](https://github.com/robbinjanssen/home-assistant-ojmicroline-thermostat) |
| 11 | +(same owner), which pins a released version; keep that integration in mind when |
| 12 | +changing the public API. |
| 13 | + |
| 14 | +```text |
| 15 | +ojmicroline_thermostat/ |
| 16 | + ojmicroline.py OJMicroline client: HTTP requests, session retry, push |
| 17 | + subscriptions; the OJMicrolineAPI protocol and |
| 18 | + SessionOJMicrolineAPI base class |
| 19 | + wd5.py WD5API: WD5 series (OWD5, MWD5), session API |
| 20 | + wg4.py WG4API: WG4 series (UWG4, AWG4), session API, push long-poll |
| 21 | + wg5.py WG5API: WG5 series (UWG5), OAuth2 API |
| 22 | + models/ Thermostat and Schedule dataclasses, parsed per series |
| 23 | + exceptions.py public exceptions |
| 24 | + const.py regulation modes and other constants |
| 25 | +tests/ pytest tests with aresponses and JSON fixtures |
| 26 | +``` |
| 27 | + |
| 28 | +## Commands |
| 29 | + |
| 30 | +The project uses [uv](https://docs.astral.sh/uv/) and |
| 31 | +[prek](https://github.com/j178/prek). |
| 32 | + |
| 33 | +```sh |
| 34 | +uv sync # create .venv with the dev tools |
| 35 | +uv run prek install # git hook running all checks on commit |
| 36 | +uv run prek run --all-files # Ruff, mypy, pylint, pytest, codespell, ... |
| 37 | +uv run pytest # tests with coverage |
| 38 | +uv build --no-sources # build the wheel and sdist (uv_build) |
| 39 | +``` |
| 40 | + |
| 41 | +Run all hooks and tests before committing. The hooks refuse commits to `main`; |
| 42 | +work on a branch. |
| 43 | + |
| 44 | +## Requirements |
| 45 | + |
| 46 | +- Python 3.11 to 3.14; CI tests every version. Write code that runs on 3.11: |
| 47 | + no PEP 695 generics (`def f[T]`), use `TypeVar`. mypy and Ruff target 3.11. |
| 48 | +- Runtime dependencies are only `aiohttp` and `yarl`. Do not import packages |
| 49 | + that are only development dependencies; `async_timeout` once broke clean |
| 50 | + installs that way, use `asyncio.timeout`. |
| 51 | + |
| 52 | +## Conventions |
| 53 | + |
| 54 | +- **Public API**: everything users need is exported from |
| 55 | + `ojmicroline_thermostat/__init__.py` and listed in `__all__`. Constructor |
| 56 | + arguments of the model APIs are public; `WD5API` keeps its positional |
| 57 | + arguments (`noqa: PLR0917`). |
| 58 | +- **Model APIs** implement the `OJMicrolineAPI` protocol: `login()`, |
| 59 | + `invalidate_session()`, `get_thermostats()`, `get_energy_usage()`, |
| 60 | + `set_regulation_mode()`, `get_notifications()` and `supports_notifications`. |
| 61 | + Session-based APIs (WD5, WG4) derive from `SessionOJMicrolineAPI`. |
| 62 | +- **HTTP**: all requests go through `OJMicroline._request` (the `request` |
| 63 | + attribute of an API), so the session passed to `OJMicroline` is used. It |
| 64 | + supports JSON bodies, form fields (`form=`) and another host (`host=`). |
| 65 | +- **Errors**: HTTP 401 raises `OJMicrolineUnauthorizedError`; `OJMicroline` |
| 66 | + then invalidates the session, logs in again and retries once. Other HTTP |
| 67 | + errors raise `OJMicrolineConnectionError`, timeouts `OJMicrolineTimeoutError`, |
| 68 | + and wrong credentials `OJMicrolineAuthError`. |
| 69 | +- **Temperatures** are integers in 1/100 °C. |
| 70 | +- **Typing**: mypy runs in strict mode from `pyproject.toml`; there is no |
| 71 | + `mypy.ini`. |
| 72 | + |
| 73 | +## Tests |
| 74 | + |
| 75 | +- Tests mock the API with `aresponses` and the JSON responses in |
| 76 | + `tests/fixtures/`. The Home Assistant integration copies these fixtures, so |
| 77 | + keep them realistic. |
| 78 | +- Coverage is 100%; CI requires at least 90%. Add a test for every bug fix that |
| 79 | + fails without the fix. |
| 80 | +- `config.py` (gitignored) holds real credentials for `test_output.py`, a |
| 81 | + manual script. Never commit it, and never print credentials or tokens. |
| 82 | + `test_output.py`'s import order depends on whether `config.py` exists, which |
| 83 | + is why `I001` is ignored for it in `pyproject.toml`. |
| 84 | + |
| 85 | +## Pull requests and releases |
| 86 | + |
| 87 | +- Every pull request needs one of these labels: `breaking-change`, `bugfix`, |
| 88 | + `hotfix`, `documentation`, `enhancement`, `refactor`, `performance`, |
| 89 | + `new-feature`, `maintenance`, `ci`, `dependencies`, `skip-changelog`. |
| 90 | +- Release Drafter derives the next version from the labels. Publishing a GitHub |
| 91 | + release runs `release.yaml`, which sets the version from the tag |
| 92 | + (`uv version`), builds the package and publishes it to PyPI. The version in |
| 93 | + `pyproject.toml` stays `0.0.0`. |
| 94 | +- Renovate keeps dependencies up to date and automerges minor and patch |
| 95 | + updates. |
0 commit comments