Metadata-Version: 2.4
Name: switch2
Version: 0.2.0
Summary: Async client library for the Switch2 energy portal
Author-email: Jelmer Vernooij <jelmer@jelmer.uk>
License-Expression: Apache-2.0
Project-URL: Homepage, https://github.com/jelmer/python-switch2
Project-URL: Repository, https://github.com/jelmer/python-switch2
Project-URL: Issues, https://github.com/jelmer/python-switch2/issues
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
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: Topic :: Home Automation
Classifier: Framework :: AsyncIO
Requires-Python: >=3.10
Description-Content-Type: text/markdown
Requires-Dist: aiohttp>=3.8
Requires-Dist: beautifulsoup4>=4.12

# python-switch2

Async Python client library for the [Switch2](https://my.switch2.co.uk) energy portal.

## Installation

```sh
pip install switch2
```

## Usage

```python
import asyncio
from switch2 import Switch2ApiClient

async def main():
    async with Switch2ApiClient("you@example.com", "your-password") as client:
        data = await client.fetch_data()
        print(f"Customer: {data.customer.name}")
        if data.account_balance is not None:
            print(f"Balance: £{data.account_balance.balance}")
        for reading in data.readings:
            print(f"  {reading.date}: {reading.amount} {reading.unit}")
        for bill in data.bills:
            print(f"  {bill.date}: £{bill.amount}")
            detail = await client.fetch_bill_detail(bill)
            print(f"    invoice {detail.invoice_number}, total £{detail.total}")

asyncio.run(main())
```

All exceptions derive from `Switch2Error`. `Switch2AuthError` means the
portal rejected the credentials; `Switch2ParseError` means a page did not
look the way the parser expects, which usually means the portal changed.

`data.readings` holds the readings of the register the portal selects by
default; `data.register_readings` maps each register in `data.registers`
to its readings.

## Command line

```sh
SWITCH2_PASSWORD=... python -m switch2 you@example.com
```

prints what the portal reports. With `--dump-html DIR` it also saves every
page it fetches, which is the easiest way to capture a page the parser gets
wrong.

## License

Apache-2.0
