Metadata-Version: 2.4
Name: pro-os-connect-py
Version: 0.9.5
Summary: Library to interface with the Donaldson Bofa Pro OS Connect fume extractor controller
Author-email: Petr Sedlacek <piit@zz9.cz>
License-Expression: MIT
Project-URL: Homepage, https://github.com/piit79/pro-os-connect-py
Project-URL: Repository, https://github.com/piit79/pro-os-connect-py
Project-URL: Issues, https://github.com/piit79/pro-os-connect-py/issues
Keywords: fume extractor,donaldson bofa,bofa,pro os,pro os connect
Classifier: Programming Language :: Python :: 3
Classifier: Operating System :: OS Independent
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: crccheck<1.4.0,>=1.3.1
Dynamic: license-file

# pro-os-connect-py

Python library and command-line tool for monitoring and controlling
**Donaldson BOFA** fume extractors over the **Pro OS Connect** TCP protocol.

- Read telemetry: flow rate, filter pressures, blockage levels, alarms, pump state
- Start and stop the pump, change the setpoint
- Read and set the device clock
- Query device information: software version, serial numbers, network configuration
- No dependencies beyond [`crccheck`](https://pypi.org/project/crccheck/)

### Disclaimer

The initial working version of this library was written by a human. It was then refactored and improved with the help of Claude Code.

## Installation

```sh
pip install pro-os-connect-py
```

Requires Python 3.10 or newer. The device must be reachable on TCP port 2345.

## Command-line tool

```sh
pro-os-connect-cli --device bofa.local get_telemetry
```

```
timestamp=109951839
alarms=0
setpoint=370
flow_rate=9.2
combined_pressure=12.5
pre_pressure=11.1
inlet_pressure=15.4
pump_level=0
real_combined_blockage=0
real_pre_blockage=0
real_inlet_blockage=0
compensated_combined_blockage=0
compensated_pre_blockage=0
is_running=0
```

### Commands

| Command | Description |
|---|---|
| `get_telemetry` | All telemetry fields |
| `get_setpoint` | Current target flow rate |
| `set_setpoint VALUE` | Set the target flow rate (0–4294967295) and print the new value read back from the device |
| `is_running` | `1` if the pump is running, `0` otherwise |
| `pump_start` | Start the pump |
| `pump_stop` | Stop the pump |
| `get_uptime` | Device uptime in seconds |
| `get_time` | Device clock |
| `set_time` | Set the device clock to this computer's local time |
| `get_software_version` | Firmware version |
| `get_serial_number` | Device serial number |
| `get_cpu_serial_number` | CPU serial number (hex) |
| `get_network_configuration` | Network configuration |
| `get_protocol_version` | Pro OS Connect protocol version |
| `echo [--payload TEXT]` | Check connectivity and measure the round-trip time |
| `reboot` | Reboot the device |

### Options

| Option | Description |
|---|---|
| `-d`, `--device HOST` | Hostname or IP address of the device (required) |
| `-j`, `--json` | Output JSON instead of text |
| `-p`, `--precision N` | Decimal places for telemetry values (default: 1) |
| `-l`, `--log-level LEVEL` | Log to stderr at `ERROR`, `WARNING`, `INFO` or `DEBUG` (`DEBUG` shows raw packets) |

Global options go before the command:

```sh
pro-os-connect-cli -d bofa.local --json get_time
```

```json
{
  "time": "2026-11-09T16:14:04"
}
```

In JSON mode, commands that return a single value use the command name without its
`get_`/`is_` prefix as the key (`{"time": ...}`, `{"running": false}`), and commands
that perform an action return `{"success": true}`. Errors are written as
`{"success": false, "error": "..."}`. In text mode, errors go to stderr.

### Exit codes

| Code | Meaning |
|---|---|
| 0 | Success |
| 2 | Invalid command-line arguments |
| 5 | Request error: the connection failed or the device did not respond in time |
| 6 | Response error: the response was invalid, could not be decoded, or reported an error status |
| 7 | Internal error: the device responded with an unsupported command |
| 8 | Other client error |
| 9 | Command failed: invalid command, incorrect echo response |

## Library

```python
from pro_os_connect import ProOSConnect, ProOSConnectError

poc = ProOSConnect("bofa.local")
try:
    telemetry = poc.get_telemetry()
    print(f"Flow rate: {telemetry.flow_rate:.1f}, running: {bool(telemetry.is_running)}")

    poc.set_setpoint(300)
    poc.pump_start()
except ProOSConnectError as e:
    print(f"Device error: {e}")
finally:
    poc.disconnect()
```

`ProOSConnect(host, port=2345, timeout=2.0)` connects on the first request and keeps
the connection open for later requests until `disconnect()` is called. If a request
fails, the connection is closed and the next request opens a new one.

### Methods

| Method | Returns |
|---|---|
| `get_telemetry()` | `TelemetryFields` |
| `get_uptime()` | `int`, seconds |
| `is_running()` | `bool` |
| `pump_start()`, `pump_stop()` | `bool` |
| `set_setpoint(setpoint: int)` | `bool` |
| `get_time()` | `datetime` |
| `set_time(date_obj: datetime)` | `bool`, sent without fractional seconds or time zone |
| `get_software_version()` | `str` |
| `get_serial_number()` | `str` |
| `get_cpu_serial_number()` | `str`, hex |
| `get_network_configuration()` | `dict` |
| `get_protocol_version()` | `int` |
| `echo(test_payload: bytes \| None = None)` | `bool`, whether the device sent the payload back unchanged |
| `reboot()` | `bool` |
| `connect(force=False)`, `disconnect()` | Manage the connection explicitly |

Errors are raised as exceptions (see below).

`TelemetryFields` is a dataclass with these fields:

| Field | Type | Notes |
|---|---|---|
| `timestamp` | `int` | Device uptime in hundredths of a second |
| `alarms` | `int` | Alarm flags (bit map) |
| `setpoint` | `int` | Target flow rate [m³/h] |
| `flow_rate` | `float` | Actual flow rate [m³/h] |
| `combined_pressure`, `pre_pressure`, `inlet_pressure` | `float` | [Pa] |
| `pump_level` | `int` | Drive level (0 - 1000) |
| `real_combined_blockage`, `real_pre_blockage`, `real_inlet_blockage` | `int` | [%] |
| `compensated_combined_blockage`, `compensated_pre_blockage` | `int` | Blockage of the combined filter/pre-filter after accounting for the expected pressure drop across a new filter [%] |
| `is_running` | `int` | 1 while the pump is running, 0 when stopped |

### Errors

All errors raised by `ProOSConnect` derive from `ProOSConnectError`:

```
ProOSConnectError
├── ProOSConnectRequestError      sending the request failed
│   ├── ProOSConnectConnectError  connection refused, closed or broken
│   └── ProOSConnectTimeoutError  no response within the timeout
├── ProOSConnectResponseError     invalid response, undecodable payload or error status
└── ProOSConnectInternalError     response command not supported by the library
```

## Protocol notes

The device's payload checksum is CRC-32/MPEG-2 computed over the data **zero-padded to
a multiple of 4 bytes**, as a 32-bit hardware CRC unit would compute it. A standard
CRC-32/MPEG-2 only matches when the length is already a multiple of 4. The device
silently ignores requests with any other checksum.

## Development

```sh
uv sync
uv run pytest
```

The tests do not need a device: they run against a simulated device on localhost.

## License

MIT
