Metadata-Version: 2.5
Name: laifen-ble
Version: 0.1.0
Summary: Bluetooth LE library for Laifen Wave electric toothbrushes
Project-URL: Homepage, https://github.com/bzumik1/laifen-ble
Project-URL: Issues, https://github.com/bzumik1/laifen-ble/issues
Author: Jakub Znamenáček
License-Expression: MIT
License-File: LICENSE
Classifier: Development Status :: 3 - Alpha
Classifier: Framework :: AsyncIO
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: Programming Language :: Python :: 3.14
Classifier: Topic :: Home Automation
Requires-Python: >=3.12
Requires-Dist: bleak-retry-connector>=3.5.0
Requires-Dist: bleak>=0.22.0
Provides-Extra: lint
Requires-Dist: mypy>=1.10.0; extra == 'lint'
Requires-Dist: ruff>=0.6.0; extra == 'lint'
Provides-Extra: test
Requires-Dist: pytest-asyncio>=0.24.0; extra == 'test'
Requires-Dist: pytest-cov>=5.0.0; extra == 'test'
Requires-Dist: pytest>=8.0.0; extra == 'test'
Description-Content-Type: text/markdown

# laifen-ble

Async Bluetooth LE library for the **Laifen Wave** electric toothbrush (`LFTB01-P`).

It reads the toothbrush state (active mode, per-mode settings, battery level, brushing time,
running state and feature flags) and, when its format is known, the firmware version. It is
built on [bleak](https://github.com/hbldh/bleak) and
[bleak-retry-connector](https://github.com/Bluetooth-Devices/bleak-retry-connector) and is
intended to be used by the Home Assistant `laifen` integration.

## Supported devices

| Model | Advertised name | Status |
|---|---|---|
| Laifen Wave (plastic, stainless steel and aluminium shells) | `LFTB01-P-xxxx` | Supported |
| Laifen Wave SE, Wave Pro and other models | `LFTB01-SE-…`, `LFTB02-…` | Not supported (different protocol) |

## Usage

```python
import asyncio

from bleak import BleakScanner

from laifen_ble import LaifenToothbrush, is_supported


async def main() -> None:
    device = await BleakScanner.find_device_by_filter(
        lambda device, advertisement: is_supported(advertisement.local_name)
    )
    toothbrush = LaifenToothbrush(device)
    toothbrush.register_callback(lambda: print(toothbrush.state))
    await toothbrush.connect()
    print(toothbrush.firmware_version, toothbrush.state)
    await asyncio.sleep(30)
    await toothbrush.disconnect()


asyncio.run(main())
```

The toothbrush only advertises while it is awake (after a button press) and disconnects on its
own about a minute after the last activity. While connected it pushes its state on every change,
so registered callbacks are called whenever the state, the firmware version or the connection
changes.

## Protocol

The protocol was documented by
[marc-alexis-com/laifen-toolbox](https://github.com/marc-alexis-com/laifen-toolbox/blob/main/docs/PROTOCOL.md)
and earlier explored by [UrbanTechIO/Laifen](https://github.com/UrbanTechIO/Laifen). This
library only sends the documented read requests.

## Development

```bash
python -m venv .venv
. .venv/bin/activate
pip install -e '.[test,lint]'
pytest
ruff check . && ruff format --check . && mypy src
```

## License

MIT
