Update general device information
This commit is contained in:
@ -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),
|
||||
|
@ -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
|
||||
|
Reference in New Issue
Block a user