Files
gree-controller/src/models/automation.rs
T
2026-10-17 20:00:28 +02:00

120 lines
4.5 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>,
/// Latched change event waiting for its downstream action to execute successfully.
#[serde(default)]
pub pending: bool,
}
#[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>>,
/// Snapshot of the evaluated Flow condition trace from the most recent execution attempt.
/// Empty for legacy/direct automations and for Flow automations that have never executed.
#[serde(default)]
pub last_trigger_trace: Vec<Value>,
/// Optional Flow-owned thermostat zone target.
#[serde(default)]
pub action_zone_id: Option<String>,
#[serde(default)]
pub action_zone_preset: Option<String>,
/// Optional soft-coast parameters set by a Flow thermostat action.
#[serde(default)]
pub action_zone_heat_anticipation_c: Option<f64>,
#[serde(default)]
pub action_zone_standby_offset_c: Option<f64>,
#[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,
/// Optional numeric value produced by a Flow value block (currently heating_curve).
/// The engine resolves this value from the Flow trace immediately before executing the action.
#[serde(default)]
pub flow_value_source_id: Option<String>,
/// Action field that receives the numeric Flow value. For Home Assistant actions this is
/// the top-level service-data key; native actions use "target_temperature"/"setpoint".
#[serde(default)]
pub flow_value_target: Option<String>,
/// 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>,
}