Skip to main content

OheaLock

Struct OheaLock 

Source
pub struct OheaLock<T: Transport> { /* private fields */ }
Expand description

High-level interface for controlling an Ohea Lock device.

This struct wraps a Transport implementation and provides convenient methods for common lock operations.

§Example

ⓘ
let lock = OheaLock::new(transport);
let state = lock.get_lock_state().await?;
if state.is_locked() {
    lock.unlock().await?;
}

Implementations§

Source§

impl<T: Transport> OheaLock<T>

Source

pub const fn new(transport: T) -> Self

Create a new OheaLock instance with the given transport.

Source

pub const fn transport(&self) -> &T

Get the underlying transport.

Source

pub fn transport_mut(&mut self) -> &mut T

Get a mutable reference to the underlying transport.

Source

pub async fn initialize(&mut self) -> Result<()>

Initialize the session with the lock.

This sends the initialization command to the command register. Should be called after connecting to a newly paired device.

§Errors

Returns an error if the write fails.

Source

pub async fn get_lock_state(&self) -> Result<LockState>

Get the current lock state.

§Errors

Returns an error if the read fails or returns invalid data.

Source

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

Get the current lock position.

This may differ from lock state during transitions.

§Errors

Returns an error if the read fails.

Source

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

Unlock the lock.

§Errors

Returns an error if the write fails.

Source

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

Lock the lock.

§Errors

Returns an error if the write fails.

Source

pub async fn set_lock_state(&self, state: LockState) -> Result<()>

Set the lock state.

§Errors

Returns an error if the write fails.

Source

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

Get the battery level as a percentage (0-100).

§Errors

Returns an error if the read fails.

Source

pub async fn get_firmware_version(&self) -> Result<String>

Get the firmware version string.

§Errors

Returns an error if the read fails or the response is not valid UTF-8.

Source

pub async fn get_device_name(&self) -> Result<String>

Get the device name.

First attempts to read from the Device Name characteristic (0x2A00). Falls back to the local name from advertising data if the characteristic is not available.

§Errors

Returns an error if both methods fail.

Source

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

Get comprehensive device information.

§Errors

Returns an error if any of the underlying reads fail.

Source

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

Get the current status byte.

§Errors

Returns an error if the read fails.

Source

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

Subscribe to lock state notifications.

§Errors

Returns an error if subscription fails.

Source

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

Subscribe to status notifications.

§Errors

Returns an error if subscription fails.

Source

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

Subscribe to battery level notifications.

§Errors

Returns an error if subscription fails.

Source

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

Unsubscribe from all notifications.

§Errors

Returns an error if any unsubscription fails.

Auto Trait Implementations§

§

impl<T> Freeze for OheaLock<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for OheaLock<T>
where T: RefUnwindSafe,

§

impl<T> Send for OheaLock<T>

§

impl<T> Sync for OheaLock<T>

§

impl<T> Unpin for OheaLock<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for OheaLock<T>
where T: UnsafeUnpin,

§

impl<T> UnwindSafe for OheaLock<T>
where T: UnwindSafe,

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.

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.