pub struct MockDevice { /* private fields */ }Expand description
A mock Aranet device for testing.
Implements AranetDevice trait for use in generic code and testing.
§Example
use aranet_core::{MockDevice, AranetDevice};
use aranet_types::DeviceType;
#[tokio::main]
async fn main() {
let device = MockDevice::new("Test", DeviceType::Aranet4);
device.connect().await.unwrap();
// Can use through trait
async fn read_via_trait<D: AranetDevice>(d: &D) {
let _ = d.read_current().await;
}
read_via_trait(&device).await;
}Implementations§
Source§impl MockDevice
impl MockDevice
Sourcepub fn new(name: &str, device_type: DeviceType) -> Self
pub fn new(name: &str, device_type: DeviceType) -> Self
Create a new mock device with default values.
Sourcepub async fn disconnect(&self) -> Result<()>
pub async fn disconnect(&self) -> Result<()>
Disconnect from the mock device.
Sourcepub fn is_connected_sync(&self) -> bool
pub fn is_connected_sync(&self) -> bool
Check if connected (sync method for internal use).
Sourcepub fn device_type(&self) -> DeviceType
pub fn device_type(&self) -> DeviceType
Get the device type.
Sourcepub async fn read_current(&self) -> Result<CurrentReading>
pub async fn read_current(&self) -> Result<CurrentReading>
Read current sensor values.
Sourcepub async fn read_battery(&self) -> Result<u8>
pub async fn read_battery(&self) -> Result<u8>
Read battery level.
Sourcepub async fn read_device_info(&self) -> Result<DeviceInfo>
pub async fn read_device_info(&self) -> Result<DeviceInfo>
Read device info.
Sourcepub async fn get_history_info(&self) -> Result<HistoryInfo>
pub async fn get_history_info(&self) -> Result<HistoryInfo>
Get history info.
Sourcepub async fn download_history(&self) -> Result<Vec<HistoryRecord>>
pub async fn download_history(&self) -> Result<Vec<HistoryRecord>>
Download history.
Sourcepub async fn download_history_with_options(
&self,
options: HistoryOptions,
) -> Result<Vec<HistoryRecord>>
pub async fn download_history_with_options( &self, options: HistoryOptions, ) -> Result<Vec<HistoryRecord>>
Download history with options.
Sourcepub async fn get_interval(&self) -> Result<MeasurementInterval>
pub async fn get_interval(&self) -> Result<MeasurementInterval>
Get the measurement interval.
Sourcepub async fn set_interval(&self, interval: MeasurementInterval) -> Result<()>
pub async fn set_interval(&self, interval: MeasurementInterval) -> Result<()>
Set the measurement interval.
Sourcepub async fn get_calibration(&self) -> Result<CalibrationData>
pub async fn get_calibration(&self) -> Result<CalibrationData>
Get calibration data.
Sourcepub async fn set_reading(&self, reading: CurrentReading)
pub async fn set_reading(&self, reading: CurrentReading)
Set the current reading for testing.
Sourcepub async fn set_temperature(&self, temp: f32)
pub async fn set_temperature(&self, temp: f32)
Set temperature directly.
Sourcepub async fn set_battery(&self, level: u8)
pub async fn set_battery(&self, level: u8)
Set battery level.
Sourcepub async fn set_radon(&self, radon: u32)
pub async fn set_radon(&self, radon: u32)
Set radon concentration in Bq/m³ (AranetRn+ devices).
Sourcepub async fn set_radon_averages(&self, avg_24h: u32, avg_7d: u32, avg_30d: u32)
pub async fn set_radon_averages(&self, avg_24h: u32, avg_7d: u32, avg_30d: u32)
Set radon averages (AranetRn+ devices).
Sourcepub async fn set_radiation(&self, rate: f32, total: f64)
pub async fn set_radiation(&self, rate: f32, total: f64)
Set radiation values (Aranet Radiation devices).
Sourcepub async fn add_history(&self, records: Vec<HistoryRecord>)
pub async fn add_history(&self, records: Vec<HistoryRecord>)
Add history records.
Sourcepub async fn set_should_fail(&self, fail: bool, message: Option<&str>)
pub async fn set_should_fail(&self, fail: bool, message: Option<&str>)
Make the device fail on next operation.
Sourcepub fn read_count(&self) -> u32
pub fn read_count(&self) -> u32
Get the number of read operations performed.
Sourcepub fn reset_read_count(&self)
pub fn reset_read_count(&self)
Reset read count.
Sourcepub fn set_read_latency(&self, latency: Duration)
pub fn set_read_latency(&self, latency: Duration)
Set simulated read latency.
Each read operation will be delayed by this duration.
Set to Duration::ZERO to disable latency simulation.
Sourcepub fn set_connect_latency(&self, latency: Duration)
pub fn set_connect_latency(&self, latency: Duration)
Set simulated connect latency.
Connect operations will be delayed by this duration.
Set to Duration::ZERO to disable latency simulation.
Sourcepub fn set_transient_failures(&self, count: u32)
pub fn set_transient_failures(&self, count: u32)
Configure transient failures.
The device will fail the next count operations, then succeed.
This is useful for testing retry logic.
§Example
use aranet_core::MockDevice;
use aranet_types::DeviceType;
let device = MockDevice::new("Test", DeviceType::Aranet4);
// First 3 connect attempts will fail, 4th will succeed
device.set_transient_failures(3);Sourcepub fn reset_transient_failures(&self)
pub fn reset_transient_failures(&self)
Reset transient failure counter.
Sourcepub fn remaining_failures(&self) -> u32
pub fn remaining_failures(&self) -> u32
Get the number of remaining transient failures.