Metadata-Version: 2.4
Name: united-utilities
Version: 0.3.1
Summary: Async Python client for the United Utilities mobile API (unofficial, reverse-engineered)
Author: Kieran Roper
License-Expression: MIT
Project-URL: Homepage, https://github.com/KRoperUK/united-utilities-py
Project-URL: Repository, https://github.com/KRoperUK/united-utilities-py
Project-URL: Issues, https://github.com/KRoperUK/united-utilities-py/issues
Project-URL: Changelog, https://github.com/KRoperUK/united-utilities-py/blob/main/CHANGELOG.md
Keywords: united-utilities,water,utility,asyncio,homeassistant
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Framework :: AsyncIO
Classifier: Topic :: Home Automation
Classifier: Typing :: Typed
Requires-Python: >=3.12
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: aiohttp>=3.9
Provides-Extra: dev
Requires-Dist: pytest>=9.2.0; extra == "dev"
Requires-Dist: pytest-asyncio>=1.5.0; extra == "dev"
Requires-Dist: pytest-cov>=7.1.0; extra == "dev"
Requires-Dist: aresponses>=3.0; extra == "dev"
Requires-Dist: ruff>=0.17.6; extra == "dev"
Requires-Dist: mypy>=2.4.1; extra == "dev"
Dynamic: license-file

# united-utilities-py

Async Python client for the **United Utilities** "Your Water" mobile API,
reverse-engineered from the app (build 102). Pairs with a Home Assistant
integration (`united-utilities-hass`).

> Unofficial. Uses a private app API that United Utilities can change or
> withdraw at any time. For personal use with your own account.

## Why the mobile API (not the website)

The `myaccount.unitedutilities.com` website is gated behind Google reCAPTCHA
Enterprise and Jscrambler, so a scripted login needs a real browser. The mobile
app talks to a separate gateway (`prd-mobile-apigateway.unitedutilities.com`)
with a far simpler scheme: a static app `apiKey` header plus a `customerId` +
numeric `PIN` login that returns a session token. No captcha.

## Credentials

The mobile API does **not** use your website email/password. It needs:

- **`customerId`** — a numeric id assigned when you register in the app.
- **`pin`** — the numeric PIN you set in the app.
- **`accountNumber`** — your water account number (for account-scoped calls).

The app doesn't show `customerId`, but you can look it up from your account
number and postcode, the same way the app's "register again" screen does. The
account must already be registered in the app:

```python
from united_utilities import lookup_customer_id

customer_id = await lookup_customer_id("4000000000", "M1 1AA")
```

> ⚠️ **Login and lookup both lock out.** A wrong PIN decrements
> `attemptsRemaining`; at zero the account locks (HTTP 423, raised as
> `AccountLockedError`, which the app says lasts 60 minutes). This client never
> retries `login()` or `lookup_customer_id()`. Do not loop on `AuthError`.

## Install

```sh
pip install united-utilities
```

## Usage

```python
import asyncio
from united_utilities import UnitedUtilitiesClient


async def main() -> None:
    async with UnitedUtilitiesClient("24000000", "000000", "4000000000") as uu:
        await uu.login()
        details = await uu.account_details()
        meter = await uu.meter_readings()
        print("balance:", details.account_balance)
        if meter.latest:
            print("last read:", meter.latest.value, "on", meter.latest.date)


asyncio.run(main())
```

In Home Assistant, pass the shared session:

```python
from homeassistant.helpers.aiohttp_client import async_get_clientsession

client = UnitedUtilitiesClient(customer_id, pin, account_number,
                               session=async_get_clientsession(hass))
```

## Endpoints covered

| Method | Returns |
| --- | --- |
| `lookup_customer_id(account_number, postcode)` | the app `customerId` (module function, no login needed) |
| `login()` / `logout()` | session token lifecycle |
| `account_details()` | balance, next payment, meter flag, payment plan, bill count |
| `meter_readings()` | meter details + reading history (`.latest`) |
| `statement()` | itemised bills & payments |
| `payment_info()` | current balance, minimum payment |
| `preferences()` | notification preferences |
| `notifications()` | customer notifications |

## Development

See [CONTRIBUTING.md](CONTRIBUTING.md). Response shapes were confirmed against
live production responses; tests run on synthetic fixtures (no real account
data) with `aresponses`.

## License

MIT
