v0.13.2
This commit is contained in:
@@ -293,6 +293,7 @@ async fn bind_device(
|
||||
device.last_error = None;
|
||||
device.updated_at = Utc::now();
|
||||
state.db.save_device(&device)?;
|
||||
state.broadcast("device.updated", serde_json::to_value(&device)?);
|
||||
state.log(
|
||||
"info",
|
||||
"device.bound",
|
||||
|
||||
@@ -161,9 +161,9 @@ async fn run_automations(state: &AppState) -> Result<()> {
|
||||
item.last_fired_at = Some(fired_at);
|
||||
item.updated_at = Utc::now();
|
||||
state.db.save_automation(&item)?;
|
||||
// last_fired_at/next_ready_at are part of ControlPlan.rules. Runtime execution
|
||||
// does not emit automation.updated, so invalidate the plan directly.
|
||||
state.invalidate_control_plan();
|
||||
// Keep connected clients in sync with runtime metadata such as last_fired_at.
|
||||
// automation.updated also invalidates the materialized control plan.
|
||||
state.broadcast("automation.updated", serde_json::to_value(&item)?);
|
||||
state.log("info", "automation.fired", &format!("Automation {} fired", item.name), json!({
|
||||
"automation_id": item.id, "flow_id": item.flow_id, "flow_node_id": item.flow_node_id, "group_id": item.action_group_id, "device_id": item.action_device_id
|
||||
}));
|
||||
@@ -184,7 +184,7 @@ async fn run_automations(state: &AppState) -> Result<()> {
|
||||
item.last_fired_at = Some(Utc::now());
|
||||
item.updated_at = Utc::now();
|
||||
state.db.save_automation(&item)?;
|
||||
state.invalidate_control_plan();
|
||||
state.broadcast("automation.updated", serde_json::to_value(&item)?);
|
||||
state.log("error", "automation.error", &err.to_string(), json!({"automation_id": item.id, "flow_id": item.flow_id, "flow_node_id": item.flow_node_id}));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -198,9 +198,8 @@ fn record_poll_failure(device: &mut Device, error: &str) {
|
||||
fn register_device_failure(state: &AppState, device: &mut Device, error: &str) -> Result<(), AppError> {
|
||||
record_poll_failure(device, error);
|
||||
state.db.save_device(device)?;
|
||||
// Command failures can change online/communication health without a device.updated frame.
|
||||
// Keep the materialized plan current explicitly instead of relying on log-event prefixes.
|
||||
state.invalidate_control_plan();
|
||||
// Command failures change live communication health; publish the updated snapshot immediately.
|
||||
state.broadcast("device.updated", serde_json::to_value(&*device)?);
|
||||
state.log("warn", "device.communication_error", &format!("{}: {error}", device.name), json!({
|
||||
"device_id": device.id,
|
||||
"consecutive_failures": device.communication_failures,
|
||||
|
||||
Reference in New Issue
Block a user