v0.9.7
This commit is contained in:
+11
-3
@@ -36,11 +36,16 @@ fn flow_f64(config: &Value, key: &str) -> Option<f64> { config.get(key).and_then
|
||||
fn flow_u8(config: &Value, key: &str) -> Option<u8> { config.get(key).and_then(Value::as_u64).and_then(|value| u8::try_from(value).ok()) }
|
||||
fn flow_bool(config: &Value, key: &str) -> Option<bool> { config.get(key).and_then(Value::as_bool) }
|
||||
|
||||
fn generated_flow_name(flow_id: &str, action_node_id: &str) -> String {
|
||||
let digest = Sha256::digest(format!("{flow_id}:{action_node_id}").as_bytes());
|
||||
format!("flow-{}", URL_SAFE_NO_PAD.encode(&digest[..12]))
|
||||
}
|
||||
|
||||
fn flow_condition_kind(kind: &str) -> bool {
|
||||
matches!(kind,
|
||||
"weekday" | "time_range" | "date_range" | "outdoor_temperature" | "device_temperature" |
|
||||
"zone_temperature" | "ha_state" | "ha_numeric" | "ha_attribute" | "ha_available" | "house_mode" |
|
||||
"device_state" | "zone_state" | "group_state" | "night_mode" | "constant"
|
||||
"device_state" | "zone_state" | "group_state" | "night_mode" | "constant" | "shared_input"
|
||||
)
|
||||
}
|
||||
fn flow_logic_kind(kind: &str) -> bool { matches!(kind, "logic_and" | "logic_or" | "logic_not") }
|
||||
@@ -215,6 +220,9 @@ fn validate_condition(condition: &crate::models::FlowCondition, state: &AppState
|
||||
"constant" => {
|
||||
if condition.config.get("value").and_then(Value::as_bool).is_none() { return Err(AppError::BadRequest("constant block needs a boolean value".into())); }
|
||||
}
|
||||
"shared_input" => {
|
||||
if flow_string(&condition.config, "input_id").is_none() { return Err(AppError::BadRequest("shared Flow input block needs input_id".into())); }
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
Ok(())
|
||||
@@ -271,7 +279,7 @@ fn compile_flow(state: &AppState, mut flow: crate::models::Flow) -> Result<(crat
|
||||
let id = format!("flow:{}:schedule:{}", flow.id, action_node.id);
|
||||
let created_at = previous_schedules.get(&id).map(|item| item.created_at.clone()).unwrap_or_else(|| now.clone());
|
||||
let schedule = Schedule {
|
||||
id, zone_id, name: format!("{} · {}", flow.name, zone.name), enabled: flow.enabled,
|
||||
id, zone_id, name: generated_flow_name(&flow.id, &action_node.id), enabled: flow.enabled,
|
||||
weekdays, start_time: flow_string(&time.config, "start").unwrap(), end_time: flow_string(&time.config, "end").unwrap(), preset, setpoint,
|
||||
created_at, updated_at: now.clone(), flow_id: Some(flow.id.clone()), flow_node_id: Some(action_node.id.clone()),
|
||||
};
|
||||
@@ -283,7 +291,7 @@ fn compile_flow(state: &AppState, mut flow: crate::models::Flow) -> Result<(crat
|
||||
let created_at = previous_automations.get(&id).map(|item| item.created_at.clone()).unwrap_or_else(|| now.clone());
|
||||
let last_fired_at = previous_automations.get(&id).and_then(|item| item.last_fired_at.clone());
|
||||
let mut item = Automation {
|
||||
id, name: format!("{} · {}", flow.name, action_node.id), enabled: flow.enabled,
|
||||
id, name: generated_flow_name(&flow.id, &action_node.id), enabled: flow.enabled,
|
||||
trigger_kind: "flow".into(), trigger_device_id: None, threshold: None, at_time: None,
|
||||
action_device_id: String::new(), action_group_id: None, action_preset: None, action: DeviceCommand::default(), cooldown_seconds: 60,
|
||||
last_fired_at, action_zone_id: None, action_zone_preset: None, flow_conditions: conditions,
|
||||
|
||||
Reference in New Issue
Block a user