use serde::{Deserialize, Serialize};
use crate::responses::TapoResponseExt;
#[derive(Debug, Clone, Serialize, Deserialize)]
#[cfg_attr(feature = "python", pyo3::prelude::pyclass(from_py_object, get_all))]
pub struct Preset {
pub id: String,
pub name: String,
pub pan: f64,
pub tilt: f64,
pub read_only: bool,
}
#[cfg(feature = "python")]
crate::impl_to_dict!(Preset);
#[derive(Debug, Clone, Serialize, Deserialize)]
pub(crate) struct PresetRaw {
#[serde(default)]
pub id: Vec<String>,
#[serde(default)]
pub name: Vec<String>,
#[serde(default)]
pub position_pan: Vec<String>,
#[serde(default)]
pub position_tilt: Vec<String>,
#[serde(default)]
pub read_only: Vec<String>,
}
impl TapoResponseExt for PresetRaw {}
impl PresetRaw {
pub fn into_presets(self) -> Vec<Preset> {
self.id
.into_iter()
.zip(self.name)
.zip(self.position_pan)
.zip(self.position_tilt)
.zip(self.read_only)
.filter_map(|((((id, name), pan), tilt), read_only)| {
Some(Preset {
id,
name,
pan: pan.parse().ok()?,
tilt: tilt.parse().ok()?,
read_only: read_only != "0",
})
})
.collect()
}
}