# OralB BLE

<p align="center">
  <a href="https://github.com/Bluetooth-Devices/oralb-ble/actions?query=workflow%3ACI">
    <img src="https://img.shields.io/github/workflow/status/Bluetooth-Devices/oralb-ble/CI/main?label=CI&logo=github&style=flat-square" alt="CI Status" >
  </a>
  <a href="https://oralb-ble.readthedocs.io">
    <img src="https://img.shields.io/readthedocs/oralb-ble.svg?logo=read-the-docs&logoColor=fff&style=flat-square" alt="Documentation Status">
  </a>
  <a href="https://codecov.io/gh/Bluetooth-Devices/oralb-ble">
    <img src="https://img.shields.io/codecov/c/github/Bluetooth-Devices/oralb-ble.svg?logo=codecov&logoColor=fff&style=flat-square" alt="Test coverage percentage">
  </a>
</p>
<p align="center">
  <a href="https://python-poetry.org/">
    <img src="https://img.shields.io/badge/packaging-poetry-299bd7?style=flat-square&logo=data:image/png;base64, " alt="Poetry">
  </a>
  <a href="https://github.com/ambv/black">
    <img src="https://img.shields.io/badge/code%20style-black-000000.svg?style=flat-square" alt="black">
  </a>
  <a href="https://github.com/pre-commit/pre-commit">
    <img src="https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white&style=flat-square" alt="pre-commit">
  </a>
</p>
<p align="center">
  <a href="https://pypi.org/project/oralb-ble/">
    <img src="https://img.shields.io/pypi/v/oralb-ble.svg?logo=python&logoColor=fff&style=flat-square" alt="PyPI Version">
  </a>
  <img src="https://img.shields.io/pypi/pyversions/oralb-ble.svg?style=flat-square&logo=python&amp;logoColor=fff" alt="Supported Python versions">
  <img src="https://img.shields.io/pypi/l/oralb-ble.svg?style=flat-square" alt="License">
</p>

Bluetooth library for Oral B devices

## Installation

Install this via pip (or your favourite package manager):

`pip install oralb-ble`

## Usage

`oralb-ble` is a **passive parser** for Oral-B toothbrush BLE advertisements.
It does not connect to the device — it decodes the manufacturer data that the
brush broadcasts while in use.

Feed each advertisement you receive into `OralBBluetoothDeviceData.update()`
and read the resulting `SensorUpdate`:

```python
from home_assistant_bluetooth import BluetoothServiceInfo
from oralb_ble import OralBBluetoothDeviceData

# A BLE advertisement captured from an Oral-B IO Series 6.
service_info = BluetoothServiceInfo(
    name="Oral-B Toothbrush",
    address="78:DB:2F:C2:48:BE",
    rssi=-63,
    manufacturer_data={220: b"\x062k\x02r\x00\x00\x01\x01\x00\x04"},
    service_uuids=[],
    service_data={},
    source="local",
)

parser = OralBBluetoothDeviceData()
update = parser.update(service_info)

print(update.title)
# 'IO Series 48BE'

for key, value in update.entity_values.items():
    print(f"{key.key}: {value.native_value}")
# time: 0
# sector: no sector
# number_of_sectors: 4
# sector_timer: 0
# toothbrush_state: idle
# pressure: normal
# mode: sensitive
# signal_strength: -63

for key, value in update.binary_entity_values.items():
    print(f"{key.key}: {value.native_value}")
# brushing: False
```

The parser is stateful per device: keep the same `OralBBluetoothDeviceData`
instance across advertisements from the same toothbrush so that derived
fields (`sector_timer`, `toothbrush_state`) stay accurate.

For real-world advertisement collection see Home Assistant's
[bluetooth integration][ha-bluetooth] — that is the primary consumer of this
library.

[ha-bluetooth]: https://www.home-assistant.io/integrations/bluetooth/

## Contributors ✨

Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):

<!-- prettier-ignore-start -->
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
<!-- markdownlint-disable -->
<!-- markdownlint-enable -->
<!-- ALL-CONTRIBUTORS-LIST:END -->
<!-- prettier-ignore-end -->

This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!

## Credits

This package was created with
[Cookiecutter](https://github.com/audreyr/cookiecutter) and the
[browniebroke/cookiecutter-pypackage](https://github.com/browniebroke/cookiecutter-pypackage)
project template.
