Metadata-Version: 2.5
Name: homerun-client
Version: 0.1.0
Summary: Unofficial async client for Homerun smart air purifiers
Project-URL: Homepage, https://github.com/Szyoo/homerun-client
Project-URL: Issues, https://github.com/Szyoo/homerun-client/issues
Author: Szyoo
License-Expression: MIT
License-File: LICENSE
Keywords: air purifier,home assistant,homerun,iot
Classifier: Development Status :: 4 - Beta
Classifier: Framework :: AsyncIO
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Home Automation
Classifier: Typing :: Typed
Requires-Python: >=3.12
Requires-Dist: aiohttp>=3.9
Provides-Extra: test
Requires-Dist: pytest-asyncio>=0.24; extra == 'test'
Requires-Dist: pytest>=8; extra == 'test'
Description-Content-Type: text/markdown

# homerun-client

Unofficial async Python client for **Homerun (霍曼)** smart air purifiers, built on
`aiohttp`. It talks to the same cloud API as the official Homerun app and powers the
[Home Assistant integration](https://github.com/Szyoo/ha-homerun).

> This project is not affiliated with or endorsed by Homerun. The cloud API is
> undocumented and may change without notice.

## Supported devices

- Homerun air purifier S1 (Wi-Fi)

Other Homerun air purifiers that use the same app are likely to work.

## Installation

```bash
pip install homerun-client
```

## Usage

```python
import asyncio

import aiohttp

from homerun_client import HomerunClient, PurifierMode, new_client_device_id


async def main() -> None:
    async with aiohttp.ClientSession() as session:
        # Keep the client device id and the token; reuse them next time.
        client = HomerunClient(session, new_client_device_id())
        await client.login_email_password("user@example.com", "password")

        for device in await client.devices():
            props = await client.get_properties(device.serial)
            print(device.name, props.get("pm25"), props.get("fan_speed"))
            await client.set_properties(device.serial, {"switch": True, "mode": PurifierMode.AUTO})


asyncio.run(main())
```

### Login methods

| Account | Password | Verification code |
| --- | --- | --- |
| Phone | `login_phone_password(area_code, phone, password)` | `send_code("phone", phone, area_code)` then `login_phone_code(area_code, phone, code)` |
| Email | `login_email_password(email, password)` | `send_code("email", email)` then `login_email_code(email, code)` |

`send_code` raises `HomerunCaptchaRequired` when the server asks for a slider
captcha; use password login in that case.

### Region

The defaults match the Chinese mainland app (`country_code="CN"`, `region="Asia"`,
`language="zh_CN"`). Pass other values to `HomerunClient` if your account was
registered elsewhere.

### Common properties

| Property | Type | Notes |
| --- | --- | --- |
| `switch` | bool | Power |
| `mode` | int | `PurifierMode`: 0 manual, 1 auto, 2 sleep, 3 pet |
| `fan_speed` | int | 1–5, effective in manual mode |
| `pm25` | int | µg/m³ |
| `tvoc` | int | µg/m³ |
| `air_quality` | int | `AirQuality`: 0 unknown, 1 good, 2 medium, 3 severe |
| `filter_life` | int | Remaining filter life, % |
| `filter_reset` | bool | Write `true` to reset the filter |
| `child_lock` | bool | |
| `mute` | bool | |
| `countdown_set` / `countdown_left` | int | Timer, minutes |
| `online_status` | bool | Device is connected to the cloud |

## Development

```bash
python -m venv .venv
.venv/bin/pip install -e ".[test]" ruff
.venv/bin/ruff check . && .venv/bin/pytest
```

## License

MIT
