Struct ReconnectingDevice

Source
pub struct ReconnectingDevice { /* private fields */ }
Expand description

A device wrapper that automatically handles reconnection.

This wrapper caches the device name and type upon initial connection so they can be accessed synchronously via the AranetDevice trait, even while reconnecting.

Implementations§

Source§

impl ReconnectingDevice

Source

pub async fn connect( identifier: &str, options: ReconnectOptions, ) -> Result<Self>

Create a new reconnecting device wrapper.

Source

pub async fn connect_with_events( identifier: &str, options: ReconnectOptions, event_sender: EventSender, ) -> Result<Self>

Create with an event sender for notifications.

Source

pub fn cancel_reconnect(&self)

Cancel any ongoing reconnection attempts.

This will cause the reconnect loop to exit on its next iteration.

Source

pub fn is_cancelled(&self) -> bool

Check if reconnection has been cancelled.

Source

pub fn reset_cancellation(&self)

Reset the cancellation flag.

Call this before starting a new reconnection attempt if you want to clear a previous cancellation. The reconnect() method will check if cancelled at the start of each iteration, so this allows re-using a previously cancelled ReconnectingDevice.

Source

pub async fn state(&self) -> ConnectionState

Get the current connection state.

Source

pub async fn is_connected(&self) -> bool

Check if currently connected.

Source

pub fn identifier(&self) -> &str

Get the identifier.

Source

pub async fn with_device<F, Fut, T>(&self, f: F) -> Result<T>
where F: Fn(&Device) -> Fut, Fut: Future<Output = Result<T>>,

Execute an operation, reconnecting if necessary.

The closure is called with a reference to the device. If the operation fails due to a connection issue, the device will attempt to reconnect and retry the operation.

§Example
let reading = device.with_device(|d| async { d.read_current().await }).await?;
Source

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

Attempt to reconnect to the device.

This loop can be cancelled by calling cancel_reconnect() from another task. When cancelled, returns Error::Cancelled.

Note: If cancel_reconnect() was called before this method, reconnection will still proceed. Call reset_cancellation() explicitly if you want to clear a previous cancellation before starting a new reconnection attempt.

Source

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

Disconnect from the device.

Source

pub async fn attempt_count(&self) -> u32

Get the number of reconnection attempts made.

Source

pub async fn name(&self) -> Option<String>

Get the device name, if available and connected.

Source

pub async fn address(&self) -> String

Get the device address (returns identifier if not connected).

Source

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

Get the detected device type, if available.

Trait Implementations§

Source§

impl AranetDevice for ReconnectingDevice

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 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§

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.

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