This commit is contained in:
Mateusz Gruszczyński
2026-09-17 12:55:29 +02:00
parent 4bdcf1b8dd
commit cd8d3fab95
42 changed files with 286 additions and 842 deletions
+2 -20
View File
@@ -264,18 +264,6 @@ fn flow_compare_value(actual: &Value, operator: &str, expected: &Value) -> bool
if operator == "neq" { !equal } else { equal }
}
fn flow_louver_compat_value(field: &str, value: Value) -> Value {
if !matches!(field, "swing_vertical" | "swing_horizontal") {
return value;
}
match value {
Value::Bool(value) => json!(u8::from(value)),
Value::String(value) if value.eq_ignore_ascii_case("true") => json!(1),
Value::String(value) if value.eq_ignore_ascii_case("false") => json!(0),
value => value,
}
}
fn flow_device_state_value(device: &Device, field: &str) -> Option<Value> {
Some(match field {
"enabled" => json!(device.enabled),
@@ -615,14 +603,8 @@ async fn flow_leaf_observation(
"device_state" => {
let id = c.get("device_id").and_then(Value::as_str).unwrap_or("");
let field = c.get("field").and_then(Value::as_str).unwrap_or("");
let actual = flow_louver_compat_value(
field,
override_value.unwrap_or_else(|| devices.iter().find(|device| device.id == id).and_then(|device| flow_device_state_value(device, field)).unwrap_or(Value::Null)),
);
let expected = flow_louver_compat_value(
field,
c.get("value").cloned().unwrap_or(Value::Null),
);
let actual = override_value.unwrap_or_else(|| devices.iter().find(|device| device.id == id).and_then(|device| flow_device_state_value(device, field)).unwrap_or(Value::Null));
let expected = c.get("value").cloned().unwrap_or(Value::Null);
(flow_compare_value(&actual, c.get("operator").and_then(Value::as_str).unwrap_or("eq"), &expected), actual)
}
"zone_state" => {