Python library for interacting with Airspot devices via Bluetooth Low Energy (BLE)
Project description
Airspot BLE
Python library for interacting with Airspot devices via Bluetooth Low Energy (BLE).
Installation
pip install airspot-ble
Usage
Parse BLE Advertisement
from airspot_ble.client import AirspotAdvertisement
from bleak import BleakScanner
async def scan():
scanner = BleakScanner()
devices = await scanner.discover()
for device, advertisement_data in devices:
adv = AirspotAdvertisement(device, advertisement_data)
if adv.co2 is not None:
print(f"Found Airspot device: {device.address}")
print(f" CO2: {adv.co2} ppm")
print(f" Battery: {adv.battery_level}%")
print(f" Charging: {adv.charging}")
print(f" Reading Mode: {adv.reading_mode}")
print(f" Sequence: {adv.sequence}")
# Run scanner
import asyncio
asyncio.run(scan())
With Home Assistant
from airspot_ble.client import AirspotAdvertisement
from homeassistant.components.bluetooth.models import BluetoothServiceInfoBleak
def parse_advertisement(service_info: BluetoothServiceInfoBleak):
"""Parse advertisement for Home Assistant integration."""
return AirspotAdvertisement(service_info.device, service_info.advertisement)
Advertisement Data Format
The library parses 6-byte manufacturer-specific data:
| Byte | Description | Range/Format |
|---|---|---|
| 0-1 | CO2 value | 0-65535 ppm (big-endian) |
| 2 | Battery level | 0-100% |
| 3 | Flags byte | Bitfield (see below) |
| 4-5 | Sequence number | 0-65535 (big-endian, increments) |
Flags Byte (Byte 3)
| Bit | Name | Description |
|---|---|---|
| 0-1 | Reading Mode | 00=On-Demand, 01=Low, 10=Mid, 11=High |
| 2 | Charging | 1=Charging, 0=Not charging |
| 3 | Low Battery | 1=Battery < 20%, 0=Normal |
| 4 | Sensor Error | 1=Error, 0=OK |
| 5 | Calibration | 1=Active, 0=Idle |
| 6-7 | Reserved | Always 0 |
API Reference
AirspotAdvertisement
Dataclass containing parsed advertisement data.
Attributes
device: BLEDevice object from bleakco2: CO2 concentration in ppm (int | None)battery_level: Battery percentage 0-100 (int | None)reading_mode: Reading mode string: "On-Demand", "Low", "Mid", or "High" (str | None)charging: Whether device is charging (bool)low_battery: Whether battery is low (< 20%) (bool)sensor_error: Whether sensor error is detected (bool)calibration_active: Whether calibration is active (bool)sequence: Sequence number (increments on each update) (int | None)rssi: Signal strength in dBm (int | None)
Constructor
AirspotAdvertisement(device: BLEDevice | None = None, ad_data: AdvertisementData | None = None)
Constants
Constants are available from the airspot_ble.const module:
from airspot_ble.const import (
MANUFACTURER_ID,
SERVICE_UUID,
WRITE_CHAR_UUID,
NOTIFY_CHAR_UUID,
ADV_DATA_LENGTH,
)
Available Constants
MANUFACTURER_ID: Manufacturer ID (0xFFFF for testing)SERVICE_UUID: BLE service UUIDWRITE_CHAR_UUID: Write characteristic UUIDNOTIFY_CHAR_UUID: Notify characteristic UUIDADV_DATA_LENGTH: Expected advertisement data length (6 bytes)
Development
Setup
git clone https://github.com/AirSpotHealth/airspot-ble-python.git
cd airspot-ble-python
pip install -e ".[dev]"
Running Tests
pytest
Building Package
python -m build
Publishing to PyPI
twine upload dist/*
License
MIT License
Contributing
Contributions are welcome! Please open an issue or submit a pull request on GitHub.
Links
- Repository: https://github.com/AirSpotHealth/airspot-ble-python
- Issues: https://github.com/AirSpotHealth/airspot-ble-python/issues
- Home Assistant Integration: https://www.home-assistant.io/integrations/airspot
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file airspot_ble-1.0.0.tar.gz.
File metadata
- Download URL: airspot_ble-1.0.0.tar.gz
- Upload date:
- Size: 7.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9a7c3dcd6fc248f3833a42d9dca9b5dcb87b0616b4049fe0d063887b66c0cbe4
|
|
| MD5 |
3f818e5c66b0164739e7acebcd9e63f2
|
|
| BLAKE2b-256 |
913dce444f10bcc7f692ae68d743255b59201dfc35f7223b6bec6374cb2c4116
|
File details
Details for the file airspot_ble-1.0.0-py3-none-any.whl.
File metadata
- Download URL: airspot_ble-1.0.0-py3-none-any.whl
- Upload date:
- Size: 6.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bbaf656c1a4d4ea3d3c468dbfb474e1c9492fd50808ba3e87c7f8ba1a46066d6
|
|
| MD5 |
330533ea304f2e48fb9e122539fc070a
|
|
| BLAKE2b-256 |
e0595970c74218eb9b76c2138ba3844fb8027bae6b07a5ed0b8f0933344b0f87
|