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§
Sourceasync fn is_connected(&self) -> bool
async fn is_connected(&self) -> bool
Check if the device is connected.
Sourceasync fn disconnect(&self) -> Result<()>
async fn disconnect(&self) -> Result<()>
Disconnect from the device.
Sourcefn address(&self) -> &str
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.
Sourcefn device_type(&self) -> Option<DeviceType>
fn device_type(&self) -> Option<DeviceType>
Get the detected device type, if available.
Sourceasync fn read_current(&self) -> Result<CurrentReading>
async fn read_current(&self) -> Result<CurrentReading>
Read the current sensor values.
Sourceasync fn read_device_info(&self) -> Result<DeviceInfo>
async fn read_device_info(&self) -> Result<DeviceInfo>
Read device information (model, serial, firmware version, etc.).
Sourceasync fn read_rssi(&self) -> Result<i16>
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).
Sourceasync fn read_battery(&self) -> Result<u8>
async fn read_battery(&self) -> Result<u8>
Read the battery level (0-100).
Sourceasync fn get_history_info(&self) -> Result<HistoryInfo>
async fn get_history_info(&self) -> Result<HistoryInfo>
Get information about stored history.
Sourceasync fn download_history(&self) -> Result<Vec<HistoryRecord>>
async fn download_history(&self) -> Result<Vec<HistoryRecord>>
Download all historical readings.
Sourceasync fn download_history_with_options(
&self,
options: HistoryOptions,
) -> Result<Vec<HistoryRecord>>
async fn download_history_with_options( &self, options: HistoryOptions, ) -> Result<Vec<HistoryRecord>>
Download historical readings with custom options.
Sourceasync fn get_interval(&self) -> Result<MeasurementInterval>
async fn get_interval(&self) -> Result<MeasurementInterval>
Get the current measurement interval.
Sourceasync fn set_interval(&self, interval: MeasurementInterval) -> Result<()>
async fn set_interval(&self, interval: MeasurementInterval) -> Result<()>
Set the measurement interval.
Sourceasync fn get_calibration(&self) -> Result<CalibrationData>
async fn get_calibration(&self) -> Result<CalibrationData>
Read calibration data from the device.
Provided Methods§
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.