1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
use serde::{Deserialize, Serialize};
use crate::tapo_vendor::error::Error;
use crate::tapo_vendor::requests::{DaysOfWeek, ScheduleRule, ScheduleTime};
use crate::tapo_vendor::responses::{PowerState, TapoResponseExt};
/// A plug schedule rule read back from the device (the "Schedule" feature in
/// the Tapo app).
///
/// This is the lenient counterpart of [`ScheduleRule`]: it reports whatever
/// the device holds, so a rule written by a newer app or firmware does not
/// stop the rest of the listing from being read. Convert one into a validated
/// [`ScheduleRule`] with [`ScheduleRuleResult::to_editable`] to edit it.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[cfg_attr(any(), pyo3::prelude::pyclass(from_py_object, get_all, frozen))]
pub struct ScheduleRuleResult {
/// Device-assigned id.
pub id: String,
/// Whether the rule is currently active. Disabled rules are kept on the
/// device but do not fire.
pub enabled: bool,
/// When the rule fires within a day.
pub time: ScheduleTime,
/// The days a repeating rule fires on, or `None` when it fires once.
pub days: Option<DaysOfWeek>,
/// The state the plug transitions to when the rule fires.
pub desired_state: PowerState,
}
#[cfg_attr(any(), pyo3::pymethods)]
impl ScheduleRuleResult {
/// Returns this rule as a validated [`ScheduleRule`], carrying its id
/// across, ready to be changed with `with_*` and passed to
/// `edit_schedule_rule`.
///
/// Fallible because this type is parsed leniently and may hold values the
/// write type refuses, such as a repeating rule the device stored with no
/// days set.
pub fn to_editable(&self) -> Result<ScheduleRule, Error> {
ScheduleRule::try_from(self)
}
}
#[cfg(any())]
crate::tapo_vendor::impl_to_dict!(ScheduleRuleResult);
#[derive(Debug, Clone, Deserialize)]
pub(crate) struct ScheduleRuleListResultRaw {
#[serde(default)]
pub rule_list: Vec<crate::tapo_vendor::requests::ScheduleRuleRaw>,
/// How many rules the device holds in total, across all pages.
pub sum: u32,
/// How many rules the device can store in total.
pub schedule_rule_max_count: u32,
}
impl TapoResponseExt for ScheduleRuleListResultRaw {}
#[derive(Debug, Clone, Deserialize)]
pub(crate) struct AddScheduleRuleResult {
pub id: String,
}
impl TapoResponseExt for AddScheduleRuleResult {}