Trait AranetDevice

Source
pub trait AranetDevice: Send + Sync {
Show 16 methods // Required methods async fn is_connected(&self) -> bool; async fn disconnect(&self) -> Result<()>; fn name(&self) -> Option<&str>; fn address(&self) -> &str; fn device_type(&self) -> Option<DeviceType>; async fn read_current(&self) -> Result<CurrentReading>; async fn read_device_info(&self) -> Result<DeviceInfo>; async fn read_rssi(&self) -> Result<i16>; async fn read_battery(&self) -> Result<u8>; async fn get_history_info(&self) -> Result<HistoryInfo>; async fn download_history(&self) -> Result<Vec<HistoryRecord>>; async fn download_history_with_options( &self, options: HistoryOptions, ) -> Result<Vec<HistoryRecord>>; async fn get_interval(&self) -> Result<MeasurementInterval>; async fn set_interval(&self, interval: MeasurementInterval) -> Result<()>; async fn get_calibration(&self) -> Result<CalibrationData>; // Provided method async fn connect(&self) -> Result<()> { ... }
}
Expand description

Trait abstracting Aranet device operations.

This trait enables writing code that works with both real Bluetooth devices and mock devices for testing. Implement this trait for any type that can provide Aranet sensor data.

§Example

use aranet_core::{AranetDevice, Result};

async fn print_reading<D: AranetDevice>(device: &D) -> Result<()> {
    let reading = device.read_current().await?;
    println!("CO2: {} ppm", reading.co2);
    Ok(())
}

Required Methods§

Source

async fn is_connected(&self) -> bool

Check if the device is connected.

Source

async fn disconnect(&self) -> Result<()>

Disconnect from the device.

Source

fn name(&self) -> Option<&str>

Get the device name, if available.

Source

fn address(&self) -> &str

Get the device address or identifier.

On Linux/Windows this is typically the MAC address. On macOS this is a UUID since MAC addresses are not exposed.

Source

fn device_type(&self) -> Option<DeviceType>

Get the detected device type, if available.

Source

async fn read_current(&self) -> Result<CurrentReading>

Read the current sensor values.

Source

async fn read_device_info(&self) -> Result<DeviceInfo>

Read device information (model, serial, firmware version, etc.).

Source

async fn read_rssi(&self) -> Result<i16>

Read the current RSSI (signal strength) in dBm.

More negative values indicate weaker signals. Typical values range from -30 (strong) to -90 (weak).

Source

async fn read_battery(&self) -> Result<u8>

Read the battery level (0-100).

Source

async fn get_history_info(&self) -> Result<HistoryInfo>

Get information about stored history.

Source

async fn download_history(&self) -> Result<Vec<HistoryRecord>>

Download all historical readings.

Source

async fn download_history_with_options( &self, options: HistoryOptions, ) -> Result<Vec<HistoryRecord>>

Download historical readings with custom options.

Source

async fn get_interval(&self) -> Result<MeasurementInterval>

Get the current measurement interval.

Source

async fn set_interval(&self, interval: MeasurementInterval) -> Result<()>

Set the measurement interval.

Source

async fn get_calibration(&self) -> Result<CalibrationData>

Read calibration data from the device.

Provided Methods§

Source

async fn connect(&self) -> Result<()>

Connect to the device.

For devices that are already connected, this should be a no-op. For devices that support reconnection, this should attempt to reconnect.

The default implementation returns Ok(()) for backwards compatibility.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§