Files
gree-controller/src/models/automation.rs
T

100 lines
3.4 KiB
Rust

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Schedule {
pub id: String,
pub zone_id: String,
pub name: String,
#[serde(default = "default_true")]
pub enabled: bool,
/// ISO weekday numbers, Monday=1, Sunday=7.
pub weekdays: Vec<u32>,
/// Local time HH:MM.
pub start_time: String,
/// Local time HH:MM. Ranges crossing midnight are supported.
pub end_time: String,
/// comfort/sleep/away/custom. Non-custom profiles resolve their target from the zone.
#[serde(default = "default_schedule_preset")]
pub preset: String,
pub setpoint: f64,
pub created_at: DateTime<Utc>,
pub updated_at: DateTime<Utc>,
/// Present for records generated by the visual Flow editor. Generated records are read-only
/// in the legacy schedule/automation editors; the Flow remains the source of truth.
#[serde(default)]
pub flow_id: Option<String>,
#[serde(default)]
pub flow_node_id: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq)]
pub struct FlowRuntimeNodeState {
#[serde(default)]
pub since: Option<DateTime<Utc>>,
#[serde(default)]
pub samples: Vec<FlowRuntimeSample>,
/// Last observed raw/result value for edge/change detection blocks.
#[serde(default)]
pub last_value: Option<Value>,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct FlowRuntimeSample {
pub at: DateTime<Utc>,
pub value: f64,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Automation {
pub id: String,
pub name: String,
#[serde(default = "default_true")]
pub enabled: bool,
/// temperature_above, temperature_below, time, flow
pub trigger_kind: String,
#[serde(default)]
pub trigger_device_id: Option<String>,
#[serde(default)]
pub threshold: Option<f64>,
#[serde(default)]
pub at_time: Option<String>,
/// Legacy/direct-device target. Empty when this automation targets a group.
#[serde(default)]
pub action_device_id: String,
/// Optional climate group target. When set, the action is applied to every member zone/device.
#[serde(default)]
pub action_group_id: Option<String>,
/// Optional thermostat preset used only for group actions.
#[serde(default)]
pub action_preset: Option<String>,
#[serde(default)]
pub action: DeviceCommand,
#[serde(default = "default_cooldown")]
pub cooldown_seconds: u64,
#[serde(default)]
pub last_fired_at: Option<DateTime<Utc>>,
/// Optional Flow-owned thermostat zone target.
#[serde(default)]
pub action_zone_id: Option<String>,
#[serde(default)]
pub action_zone_preset: Option<String>,
#[serde(default)]
pub action_ha_domain: Option<String>,
#[serde(default)]
pub action_ha_service: Option<String>,
#[serde(default)]
pub action_ha_entity_id: Option<String>,
#[serde(default)]
pub action_ha_data: Value,
/// Topologically ordered condition/logic program compiled from the visual Flow graph.
#[serde(default)]
pub flow_conditions: Vec<FlowCondition>,
#[serde(default)]
pub flow_id: Option<String>,
#[serde(default)]
pub flow_node_id: Option<String>,
/// Durable state for stateful Flow blocks (timers, change detection, rate limits and rolling samples).
#[serde(default)]
pub flow_runtime: BTreeMap<String, FlowRuntimeNodeState>,
pub created_at: DateTime<Utc>,
pub updated_at: DateTime<Utc>,
}