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