switchbot_api2/api/
humidity.rs

1use anyhow::Result;
2use serde::Deserialize;
3
4use crate::{Dev, Device, SwitchBot};
5
6/// Humidity status.
7#[derive(Clone, Debug, Deserialize, PartialEq)]
8pub struct HumidityStatus {
9    /// Humidity (%).
10    humidity: f64,
11}
12
13impl SwitchBot {
14    /// Get humidity (%).
15    pub async fn get_humidity(&self, dev: &Device) -> Result<Option<f64>> {
16        match dev.typ {
17            Dev::Hub2 | Dev::IOThermoHygrometer => Ok(Some(
18                self.get::<HumidityStatus>(&format!("v1.1/devices/{}/status", dev.id))
19                    .await?
20                    .humidity,
21            )),
22            Dev::Other(_) => Ok(None),
23        }
24    }
25}