Don't block home widget if live consumption is unavailable
	
		
			
	
		
	
	
		
	
		
			All checks were successful
		
		
	
	
		
			
				
	
				continuous-integration/drone/push Build is passing
				
			
		
		
	
	
				
					
				
			
		
			All checks were successful
		
		
	
	continuous-integration/drone/push Build is passing
				
			This commit is contained in:
		@@ -9,14 +9,20 @@ use actix_web::HttpResponse;
 | 
			
		||||
 | 
			
		||||
#[derive(serde::Serialize)]
 | 
			
		||||
struct Consumption {
 | 
			
		||||
    consumption: i32,
 | 
			
		||||
    consumption: Option<i32>,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/// Get current energy consumption
 | 
			
		||||
pub async fn curr_consumption() -> HttpResult {
 | 
			
		||||
    let consumption = consumption::get_curr_consumption().await?;
 | 
			
		||||
 | 
			
		||||
    Ok(HttpResponse::Ok().json(Consumption { consumption }))
 | 
			
		||||
    Ok(match consumption::get_curr_consumption().await {
 | 
			
		||||
        Ok(v) => HttpResponse::Ok().json(Consumption {
 | 
			
		||||
            consumption: Some(v),
 | 
			
		||||
        }),
 | 
			
		||||
        Err(e) => {
 | 
			
		||||
            log::error!("Failed to fetch current consumption! {e}");
 | 
			
		||||
            HttpResponse::Ok().json(Consumption { consumption: None })
 | 
			
		||||
        }
 | 
			
		||||
    })
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/// Get curr consumption history
 | 
			
		||||
@@ -34,7 +40,9 @@ pub async fn curr_consumption_history() -> HttpResult {
 | 
			
		||||
pub async fn cached_consumption(energy_actor: WebEnergyActor) -> HttpResult {
 | 
			
		||||
    let consumption = energy_actor.send(energy_actor::GetCurrConsumption).await?;
 | 
			
		||||
 | 
			
		||||
    Ok(HttpResponse::Ok().json(Consumption { consumption }))
 | 
			
		||||
    Ok(HttpResponse::Ok().json(Consumption {
 | 
			
		||||
        consumption: Some(consumption),
 | 
			
		||||
    }))
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/// Get current relays consumption
 | 
			
		||||
@@ -42,7 +50,9 @@ pub async fn relays_consumption(energy_actor: WebEnergyActor) -> HttpResult {
 | 
			
		||||
    let consumption =
 | 
			
		||||
        energy_actor.send(energy_actor::RelaysConsumption).await? as EnergyConsumption;
 | 
			
		||||
 | 
			
		||||
    Ok(HttpResponse::Ok().json(Consumption { consumption }))
 | 
			
		||||
    Ok(HttpResponse::Ok().json(Consumption {
 | 
			
		||||
        consumption: Some(consumption),
 | 
			
		||||
    }))
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
pub async fn relays_consumption_history() -> HttpResult {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user