Trait AranetDevice

Source
pub trait AranetDevice: Send + Sync {
Show 16 methods // Required methods fn is_connected<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = bool> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn disconnect<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn name(&self) -> Option<&str>; fn address(&self) -> &str; fn device_type(&self) -> Option<DeviceType>; fn read_current<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<CurrentReading>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn read_device_info<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<DeviceInfo>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn read_rssi<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<i16>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn read_battery<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<u8>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn get_history_info<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<HistoryInfo>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn download_history<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<Vec<HistoryRecord>>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn download_history_with_options<'life0, 'async_trait>( &'life0 self, options: HistoryOptions, ) -> Pin<Box<dyn Future<Output = Result<Vec<HistoryRecord>>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn get_interval<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<MeasurementInterval>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn set_interval<'life0, 'async_trait>( &'life0 self, interval: MeasurementInterval, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn get_calibration<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<CalibrationData>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; // Provided method fn connect<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait { ... }
}
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

fn is_connected<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = bool> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Check if the device is connected.

Source

fn disconnect<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

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

fn read_current<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<CurrentReading>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Read the current sensor values.

Source

fn read_device_info<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<DeviceInfo>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

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

Source

fn read_rssi<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<i16>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Read the current RSSI (signal strength) in dBm.

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

Source

fn read_battery<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<u8>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Read the battery level (0-100).

Source

fn get_history_info<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<HistoryInfo>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Get information about stored history.

Source

fn download_history<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<Vec<HistoryRecord>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Download all historical readings.

Source

fn download_history_with_options<'life0, 'async_trait>( &'life0 self, options: HistoryOptions, ) -> Pin<Box<dyn Future<Output = Result<Vec<HistoryRecord>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Download historical readings with custom options.

Source

fn get_interval<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<MeasurementInterval>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Get the current measurement interval.

Source

fn set_interval<'life0, 'async_trait>( &'life0 self, interval: MeasurementInterval, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Set the measurement interval.

Source

fn get_calibration<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<CalibrationData>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Read calibration data from the device.

Provided Methods§

Source

fn connect<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

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.

Implementors§