Can set device desired version
This commit is contained in:
central_backend/src
central_frontend/src
esp32_device
@ -1,7 +1,10 @@
|
||||
use crate::constants;
|
||||
use crate::devices::device::DeviceId;
|
||||
use crate::energy::energy_actor;
|
||||
use crate::ota::ota_manager;
|
||||
use crate::ota::ota_update::OTAPlatform;
|
||||
use crate::server::custom_error::HttpResult;
|
||||
use crate::server::WebEnergyActor;
|
||||
use actix_multipart::form::tempfile::TempFile;
|
||||
use actix_multipart::form::MultipartForm;
|
||||
use actix_web::{web, HttpResponse};
|
||||
@ -49,3 +52,48 @@ pub async fn upload_firmware(
|
||||
|
||||
Ok(HttpResponse::Accepted().body("OTA update successfully saved."))
|
||||
}
|
||||
|
||||
#[derive(serde::Deserialize)]
|
||||
pub struct SetDesiredDeviceVersion {
|
||||
devices: Option<Vec<DeviceId>>,
|
||||
platform: Option<OTAPlatform>,
|
||||
version: semver::Version,
|
||||
}
|
||||
|
||||
pub async fn set_desired_version(
|
||||
actor: WebEnergyActor,
|
||||
body: web::Json<SetDesiredDeviceVersion>,
|
||||
) -> HttpResult {
|
||||
if body.devices.is_none() && body.platform.is_none() {
|
||||
return Ok(
|
||||
HttpResponse::BadRequest().json("Must specify one filter to select target devices!")
|
||||
);
|
||||
}
|
||||
|
||||
let devices = actor.send(energy_actor::GetDeviceLists).await?;
|
||||
|
||||
for d in devices {
|
||||
// Filter per platform
|
||||
if let Some(p) = body.platform {
|
||||
if d.info.reference != p.to_string() {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// Filter per device
|
||||
if let Some(ids) = &body.devices {
|
||||
if !ids.contains(&d.id) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
actor
|
||||
.send(energy_actor::SetDesiredVersion(
|
||||
d.id,
|
||||
Some(body.version.clone()),
|
||||
))
|
||||
.await??;
|
||||
}
|
||||
|
||||
Ok(HttpResponse::Ok().finish())
|
||||
}
|
||||
|
Reference in New Issue
Block a user