This commit is contained in:
Mateusz Gruszczyński
2026-09-03 10:26:18 +02:00
parent 8f6169fbe3
commit 4c9f8ff403
31 changed files with 673 additions and 71 deletions
+33 -6
View File
@@ -208,14 +208,41 @@ async fn poll_device(State(state): State<AppState>, Path(id): Path<String>) -> R
Ok(Json(engine::poll_one(&state, &id).await?))
}
async fn command_device(State(state): State<AppState>, Path(id): Path<String>, Json(command): Json<DeviceCommand>) -> Result<Json<Device>, AppError> {
Ok(Json(engine::send_manual_command(&state, &id, command, "device.manual_control").await?))
async fn probe_device(State(state): State<AppState>, Path(id): Path<String>) -> Result<Json<Value>, AppError> {
let device = state.db.get_device(&id)?.ok_or_else(|| AppError::NotFound(format!("device {id}")))?;
let response_time_ms = state.gree.probe(&device).await.map_err(|err| AppError::Device(err.to_string()))?;
Ok(Json(json!({
"device_id": device.id,
"response_time_ms": response_time_ms,
"ok": true
})))
}
#[derive(Debug, Deserialize)]
struct ManualDeviceCommandRequest {
#[serde(flatten)]
command: DeviceCommand,
#[serde(default)]
manual_override: bool,
}
async fn command_device(State(state): State<AppState>, Path(id): Path<String>, Json(request): Json<ManualDeviceCommandRequest>) -> Result<Json<Device>, AppError> {
Ok(Json(engine::send_manual_command(
&state,
&id,
request.command,
"device.manual_control",
request.manual_override,
).await?))
}
async fn command_home_assistant_device(State(state): State<AppState>, Path(id): Path<String>, Json(command): Json<DeviceCommand>) -> Result<Json<Device>, AppError> {
if state.db.list_zones()?.iter().any(|zone| zone.device_id == id && !zone.enabled) {
return Err(AppError::BadRequest("device belongs to a disabled thermostat zone; use Manual control in the web UI for explicit direct operation".into()));
}
Ok(Json(engine::send_manual_command(&state, &id, command, "home_assistant.device_manual_control").await?))
Ok(Json(engine::send_manual_command(
&state,
&id,
command,
"home_assistant.device_manual_control",
false,
).await?))
}