This commit is contained in:
Mateusz Gruszczyński
2026-09-17 11:21:49 +02:00
parent 32f8a32bd2
commit df10ead47e
38 changed files with 655 additions and 210 deletions
+20 -2
View File
@@ -264,6 +264,18 @@ 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),
@@ -603,8 +615,14 @@ 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 = 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);
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),
);
(flow_compare_value(&actual, c.get("operator").and_then(Value::as_str).unwrap_or("eq"), &expected), actual)
}
"zone_state" => {