Skip to content

feat: add AirQualityInput plugin with multi-connector pattern (AQICN, PMS5003, BME680)#2437

Open
Wanbogang wants to merge 5 commits into
OpenMind:mainfrom
Wanbogang:feature/air-quality-input
Open

feat: add AirQualityInput plugin with multi-connector pattern (AQICN, PMS5003, BME680)#2437
Wanbogang wants to merge 5 commits into
OpenMind:mainfrom
Wanbogang:feature/air-quality-input

Conversation

@Wanbogang
Copy link
Copy Markdown
Contributor

Overview

Adds a generic AirQualityInput plugin that supports multiple air quality sensors and APIs via a connector pattern. This allows OM1 to read real-time air quality data without changing the core plugin when switching sensors. #365

Features

  • AirQualityInput plugin — reads standardized AirQualityData and converts it to human-readable text for the LLM
  • Connector pattern — swap sensors via config, no code changes needed
  • 3 connectors out of the box:
    • aqicn — AQICN World Air Quality Index cloud API (no hardware needed)
    • pms5003 — PMS5003/PMS7003 particulate matter sensor via Serial/UART
    • bme680 — BME680 environmental sensor (temperature, humidity, VOC) via I2C
  • AQI alerts — WARNING and DANGER thresholds configurable per deployment
  • Async & non-blocking — serial/I2C reads run in executor to avoid blocking event loop

Sensors Integrated

Connector Sensor Interface Data
aqicn AQICN API HTTP AQI, PM2.5, PM10, CO, NO2, SO2, O3, temp, humidity
pms5003 PMS5003/PMS7003 Serial/UART PM2.5, PM10, AQI
bme680 BME680 I2C Temperature, humidity, IAQ score

Configuration Example

# AQICN (cloud, no hardware)
connector: aqicn
connector_config:
  api_key: "your_token_here"
  latitude: -6.9667
  longitude: 110.4167

# PMS5003 (hardware)
connector: pms5003
connector_config:
  port: /dev/ttyUSB0
  location: Outdoor

# BME680 (hardware)
connector: bme680
connector_config:
  i2c_address: 0x76
  location: Indoor
  gas_baseline: 50000.0

- Add AirQualityInput plugin supporting multiple sensors/APIs
- Add connector/base.py: AirQualityData dataclass, AirQualityConnector ABC, get_aqi_level()
- Add connector/aqicn.py: AQICN cloud API connector (no hardware needed)
- Add connector/pms5003.py: PMS5003/PMS7003 particulate sensor via Serial
- Add connector/bme680.py: BME680 environmental sensor via I2C
- Add 88 tests covering all connectors and plugin behavior (100% coverage)
- Patch inputs/__init__.py auto-discovery to support subpackage plugins
- Fix aqi_label/aqi_description unbound variable in _raw_to_text
@Wanbogang Wanbogang requested review from a team as code owners March 3, 2026 13:36
@github-actions github-actions Bot added robotics Robotics code changes python Python code tests Test files labels Mar 3, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 3, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ All tests successful. No failed tests found.

📢 Thoughts on this report? Let us know!

Wanbogang and others added 3 commits March 3, 2026 21:06
- Fix test_base.py: add type: ignore[abstract] for abstract instantiation
- Fix test_bme680.py: assert aqi is not None before comparison
- Add tests for subpackage scanning in inputs/__init__.py (100% coverage)
- Add tests for load_input error paths (ImportError, AttributeError)
- Move inline 'import types' to top-level in test_init.py
- Use setattr() for ModuleType attribute assignment (pyright)
@Prachi1615
Copy link
Copy Markdown
Collaborator

Prachi1615 commented May 29, 2026

Hi @Wanbogang
Thanks for your PR.
If you have videos with working demo; please attach them here, after you resolve the conflicts.

@Wanbogang
Copy link
Copy Markdown
Contributor Author

Hi @Prachi1615

thanks for the review! Conflicts are now resolved (merged latest main), and all 104 tests pass.

I tested the aqicn connector end-to-end against the live AQICN API (no hardware needed for this one). The screenshot below shows both the connector read and the full OM1 pipeline.

Setup: AirQualityInput plugin with connector: aqicn, using a free AQICN token, pointed at my location (Semarang, Indonesia: lat -6.9667, lon 110.4167).

What the screenshot shows:

  1. Calling AqicnConnector.read() directly returns live data:
    AirQualityData(aqi=99, pm25=99, temperature=32.9, humidity=53.1, location='Semarang, Indonesia', source='aqicn')

  2. Running the agent in OM1, the plugin polls the API and feeds formatted data into the LLM:

INPUT: Air Quality
Air Quality in Semarang, Indonesia: MODERATE (AQI: 99). PM2.5: 99 µg/m³. Temperature: 32.9°C, Humidity: 53.1%.

So the AQICN API → connector → AirQualityInput → LLM path works with real-time data. The AQI level classification (MODERATE) and the WARNING/DANGER threshold logic are applied in the plugin.

The pms5003 and bme680 connectors are hardware sensors (Serial/I2C) which I can't demo without the physical devices, but they share the same AirQualityConnector interface and are fully unit-tested (100% coverage).

Let me know if you'd like anything else. Thanks!

Screenshot from 2026-06-01 14-49-10

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

python Python code robotics Robotics code changes tests Test files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants