Update general device information

This commit is contained in:
2024-09-09 21:43:57 +02:00
parent a97614ce44
commit 36ba4efd9f
8 changed files with 109 additions and 30 deletions

View File

@ -301,7 +301,7 @@ impl Handler<SynchronizeDevice> for EnergyActor {
#[derive(serde::Serialize)]
pub struct ResDevState {
id: DeviceId,
pub id: DeviceId,
last_ping: u64,
online: bool,
}

View File

@ -152,6 +152,10 @@ pub async fn secure_server(energy_actor: EnergyActorAddr) -> anyhow::Result<()>
"/web_api/device/{id}",
web::get().to(devices_controller::get_single),
)
.route(
"/web_api/device/{id}/state",
web::get().to(devices_controller::state_single),
)
.route(
"/web_api/device/{id}/validate",
web::post().to(devices_controller::validate_device),

View File

@ -52,6 +52,17 @@ pub async fn get_single(actor: WebEnergyActor, id: web::Path<DeviceInPath>) -> H
Ok(HttpResponse::Ok().json(dev))
}
/// Get a single device state
pub async fn state_single(actor: WebEnergyActor, id: web::Path<DeviceInPath>) -> HttpResult {
let states = actor.send(energy_actor::GetDevicesState).await?;
let Some(state) = states.into_iter().find(|s| s.id == id.id) else {
return Ok(HttpResponse::NotFound().body("Requested device not found!"));
};
Ok(HttpResponse::Ok().json(state))
}
/// Validate a device
pub async fn validate_device(actor: WebEnergyActor, id: web::Path<DeviceInPath>) -> HttpResult {
actor