Start to implement energy consumption backend

This commit is contained in:
2024-06-29 10:11:31 +02:00
parent 9d3e2beb81
commit 49a3e3a669
8 changed files with 66 additions and 2 deletions

View File

@ -0,0 +1,18 @@
use crate::app_config::{AppConfig, ConsumptionBackend};
use rand::{thread_rng, Rng};
pub type EnergyConsumption = i32;
/// Get current electrical energy consumption
pub async fn get_curr_consumption() -> anyhow::Result<EnergyConsumption> {
let backend = AppConfig::get()
.consumption_backend
.as_ref()
.unwrap_or(&ConsumptionBackend::Constant { value: 300 });
match backend {
ConsumptionBackend::Constant { value } => Ok(*value),
ConsumptionBackend::Random { min, max } => Ok(thread_rng().gen_range(*min..*max)),
}
}