Struct mijia::MijiaSession[][src]

pub struct MijiaSession {
    pub bt_session: BluetoothSession,
}

A wrapper around a Bluetooth session which adds some methods for dealing with Mijia sensors. This is the main entry point to the library.

The underlying Bluetooth session may still be accessed. For example, to scan for sensors:

// Create a new session. This establishes the D-Bus connection. In this case we ignore the join
// handle, as we don't intend to run indefinitely.
let (_, session) = MijiaSession::new().await?;

// Start scanning for Bluetooth devices, and wait a few seconds for some to be discovered.
session.bt_session.start_discovery().await?;
time::sleep(Duration::from_secs(5)).await;

// Get the list of sensors which are currently known.
let sensors = session.get_sensors().await?;

Fields

bt_session: BluetoothSession

The underlying BluetoothSession. You can use this for Bluetooth operations which are not specific to Mijia sensors, such as connecting and disconnecting.

Implementations

impl MijiaSession[src]

pub async fn new(
) -> Result<(impl Future<Output = Result<(), SpawnError>>, Self), BluetoothError>
[src]

Returns a tuple of (join handle, Self). If the join handle ever completes then you’re in trouble and should probably restart the process.

pub async fn get_sensors(&self) -> Result<Vec<SensorProps>, BluetoothError>[src]

Get a list of all Mijia sensors which have currently been discovered.

pub async fn get_time(&self, id: &DeviceId) -> Result<SystemTime, MijiaError>[src]

Get the current time of the sensor.

pub async fn set_time(
    &self,
    id: &DeviceId,
    time: SystemTime
) -> Result<(), MijiaError>
[src]

Set the current time of the sensor.

pub async fn get_temperature_unit(
    &self,
    id: &DeviceId
) -> Result<TemperatureUnit, MijiaError>
[src]

Get the temperature unit which the sensor uses for its display.

pub async fn set_temperature_unit(
    &self,
    id: &DeviceId,
    unit: TemperatureUnit
) -> Result<(), BluetoothError>
[src]

Set the temperature unit which the sensor uses for its display.

pub async fn get_comfort_level(
    &self,
    id: &DeviceId
) -> Result<ComfortLevel, MijiaError>
[src]

Get the comfort level configuration which determines when the sensor displays a happy face.

pub async fn set_comfort_level(
    &self,
    id: &DeviceId,
    comfort_level: &ComfortLevel
) -> Result<(), MijiaError>
[src]

Set the comfort level configuration which determines when the sensor displays a happy face.

pub async fn get_history_range(
    &self,
    id: &DeviceId
) -> Result<Range<u32>, MijiaError>
[src]

Get the range of indices for historical data stored on the sensor.

pub async fn delete_history(&self, id: &DeviceId) -> Result<(), BluetoothError>[src]

Delete all historical data stored on the sensor.

pub async fn get_last_history_record(
    &self,
    id: &DeviceId
) -> Result<HistoryRecord, MijiaError>
[src]

Get the last historical record stored on the sensor.

pub async fn start_notify_history(
    &self,
    id: &DeviceId,
    start_index: Option<u32>
) -> Result<(), BluetoothError>
[src]

Start receiving historical records from the sensor.

Arguments

  • id: The ID of the sensor to request records from.
  • start_index: The record index to start at. If this is not specified then all records which have not yet been received from the sensor since it was connected will be requested.

pub async fn stop_notify_history(
    &self,
    id: &DeviceId
) -> Result<(), BluetoothError>
[src]

Stop receiving historical records from the sensor.

pub async fn get_all_history(
    &self,
    id: &DeviceId
) -> Result<Vec<Option<HistoryRecord>>, MijiaError>
[src]

Try to get all historical records for the sensor.

pub async fn start_notify_sensor(
    &self,
    id: &DeviceId
) -> Result<(), BluetoothError>
[src]

Assuming that the given device ID refers to a Mijia sensor device and that it has already been connected, subscribe to notifications of temperature/humidity readings, and adjust the connection interval to save power.

Notifications will be delivered as events by MijiaSession::event_stream().

pub async fn event_stream(
    &self
) -> Result<impl Stream<Item = MijiaEvent>, BluetoothError>
[src]

Get a stream of reading/history/disconnected events for all sensors.

Trait Implementations

impl Debug for MijiaSession[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.