switchbot_api2/api/
climate.rs

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