Get state of relay on device page

This commit is contained in:
2024-09-25 21:56:54 +02:00
parent 3c2fa18d9a
commit e0f0067e89
6 changed files with 70 additions and 16 deletions

View File

@ -95,8 +95,18 @@ pub async fn delete(actor: WebEnergyActor, path: web::Path<RelayIDInPath>) -> Ht
}
/// Get the status of all relays
pub async fn get_status_all(actor: WebEnergyActor) -> HttpResult {
pub async fn status_all(actor: WebEnergyActor) -> HttpResult {
let list = actor.send(energy_actor::GetAllRelaysState).await?;
Ok(HttpResponse::Ok().json(list))
}
/// Get the state of a single relay
pub async fn status_single(actor: WebEnergyActor, path: web::Path<RelayIDInPath>) -> HttpResult {
let list = actor.send(energy_actor::GetAllRelaysState).await?;
let Some(state) = list.into_iter().find(|r| r.id == path.id) else {
return Ok(HttpResponse::NotFound().json("Relay not found!"));
};
Ok(HttpResponse::Ok().json(state))
}