Metadata-Version: 2.5
Name: bradford_white_wave_client
Version: 1.0.0
Summary: Client for Bradford White Wave API
Project-URL: Homepage, https://github.com/gclenaghan/bradford-white-wave-client
Author-email: Graham Clenaghan <gclenaghan@gmail.com>
License-Expression: MIT
License-File: LICENSE
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Home Automation
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Typing :: Typed
Requires-Python: >=3.10
Requires-Dist: aiohttp>=3.9.0
Requires-Dist: pydantic>=2.0.0
Provides-Extra: dev
Requires-Dist: aiohttp<3.14,>=3.9.0; extra == 'dev'
Requires-Dist: aioresponses>=0.7.6; extra == 'dev'
Requires-Dist: mypy>=1.10; extra == 'dev'
Requires-Dist: pytest-asyncio>=0.23; extra == 'dev'
Requires-Dist: pytest-cov>=5.0; extra == 'dev'
Requires-Dist: pytest>=8.0; extra == 'dev'
Requires-Dist: ruff>=0.6; extra == 'dev'
Description-Content-Type: text/markdown

# Bradford White Wave Client

An asynchronous Python client library for the Bradford White Wave API for smart water heaters. The "Wave"
platform is separate from the older "Connect" platform — for example, the original AeroTherm uses an
optional "Connect" module add-on, while the AeroTherm G2 has built-in connectivity on the "Wave" platform.

This library is designed for use in a Home Assistant integration and general automation tasks.

Inspired by [bradford-white-connect-client](https://github.com/ablyler/bradford_white_connect_client).

## Installation

```bash
pip install bradford-white-wave-client
```

## Usage

### Authenticate with Email & Password

```python
from bradford_white_wave_client import (
    BradfordWhiteClient,
    BradfordWhiteMode,
    EnergyViewType,
)

async with BradfordWhiteClient(
    email="you@example.com",
    password="your-password",
) as client:
    devices = await client.list_devices()

    for device in devices:
        mac = device.mac_address

        # Get status
        status = await client.get_status(mac)

        # Get energy usage (EnergyViewType or "hourly", "daily", "weekly", "monthly")
        energy = await client.get_energy_usage(mac, EnergyViewType.WEEKLY)

        # Set temperature (°F)
        await client.set_temperature(mac, 120)

        # Set mode
        await client.set_mode(mac, BradfordWhiteMode.HEAT_PUMP)
```

### Persist & Reuse `refresh_token`

For long-running applications (like Home Assistant), you can inject an external `aiohttp.ClientSession`, persist rotated tokens via `on_token_update`, and optionally pass `email` and `password` so the client automatically re-authenticates if the refresh token eventually expires:

```python
async with BradfordWhiteClient() as client:
    await client.authenticate_with_credentials("you@example.com", "your-password")
    saved_refresh_token = client.refresh_token

# Later session: uses refresh_token first, falling back to email/password only if expired
async with BradfordWhiteClient(
    refresh_token=saved_refresh_token,
    email="you@example.com",
    password="your-password",
    on_token_update=lambda token: print("Updated refresh token:", token),
) as client:
    devices = await client.list_devices()
```

### Example Script

You can test interactively with `example_script.py`, which prompts for your email and password and caches `refresh_token` in `.credentials.json`:

```bash
.venv/bin/python example_script.py
```

## Features
- Async/Await support using `aiohttp`
- Direct Azure AD B2C Email/Password authentication
- Automatic OAuth access token refresh (with seamless credential fallback on refresh-token expiry)
- Type-hinted with `Pydantic` models

## Disclaimers
- This is an unofficial library and is not affiliated with Bradford White.
- I have only tested with an Aerotherm G2.
- This is largely written in "collaboration" with Gemini, though I have manually reviewed the code and verified the flows.
