Struct MockDevice

Source
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

Source

pub fn new(name: &str, device_type: DeviceType) -> Self

Create a new mock device with default values.

Source

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

Connect to the mock device.

Source

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

Disconnect from the mock device.

Source

pub fn is_connected_sync(&self) -> bool

Check if connected (sync method for internal use).

Source

pub fn name(&self) -> &str

Get the device name.

Source

pub fn address(&self) -> &str

Get the device address.

Source

pub fn device_type(&self) -> DeviceType

Get the device type.

Source

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

Read current sensor values.

Source

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

Read battery level.

Source

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

Read RSSI (signal strength).

Source

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

Read device info.

Source

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

Get history info.

Source

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

Download history.

Source

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

Download history with options.

Source

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

Get the measurement interval.

Source

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

Set the measurement interval.

Source

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

Get calibration data.

Source

pub async fn set_reading(&self, reading: CurrentReading)

Set the current reading for testing.

Source

pub async fn set_co2(&self, co2: u16)

Set CO2 level directly.

Source

pub async fn set_temperature(&self, temp: f32)

Set temperature directly.

Source

pub async fn set_battery(&self, level: u8)

Set battery level.

Source

pub async fn set_radon(&self, radon: u32)

Set radon concentration in Bq/m³ (AranetRn+ devices).

Source

pub async fn set_radon_averages(&self, avg_24h: u32, avg_7d: u32, avg_30d: u32)

Set radon averages (AranetRn+ devices).

Source

pub async fn set_radiation(&self, rate: f32, total: f64)

Set radiation values (Aranet Radiation devices).

Source

pub fn set_rssi(&self, rssi: i16)

Set RSSI (signal strength) for testing.

Source

pub async fn add_history(&self, records: Vec<HistoryRecord>)

Add history records.

Source

pub async fn set_should_fail(&self, fail: bool, message: Option<&str>)

Make the device fail on next operation.

Source

pub fn read_count(&self) -> u32

Get the number of read operations performed.

Source

pub fn reset_read_count(&self)

Reset read count.

Source

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.

Source

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.

Source

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);
Source

pub fn reset_transient_failures(&self)

Reset transient failure counter.

Source

pub fn remaining_failures(&self) -> u32

Get the number of remaining transient failures.

Trait Implementations§

Source§

impl AranetDevice for MockDevice

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. Read more
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. Read more
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.
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. Read more
Source§

impl Debug for MockDevice

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more