Get state of relay on device page
This commit is contained in:
		@@ -187,7 +187,11 @@ pub async fn secure_server(energy_actor: EnergyActorAddr) -> anyhow::Result<()>
 | 
			
		||||
            )
 | 
			
		||||
            .route(
 | 
			
		||||
                "/web_api/relays/status",
 | 
			
		||||
                web::get().to(relays_controller::get_status_all),
 | 
			
		||||
                web::get().to(relays_controller::status_all),
 | 
			
		||||
            )
 | 
			
		||||
            .route(
 | 
			
		||||
                "/web_api/relay/{id}/status",
 | 
			
		||||
                web::get().to(relays_controller::status_single),
 | 
			
		||||
            )
 | 
			
		||||
            // Devices API
 | 
			
		||||
            .route(
 | 
			
		||||
 
 | 
			
		||||
@@ -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))
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user