Display relay consumption history

This commit is contained in:
2024-09-26 22:51:43 +02:00
parent 903f1fa8ce
commit 7895b9eca8
10 changed files with 101 additions and 12 deletions

View File

@ -139,6 +139,10 @@ pub async fn secure_server(energy_actor: EnergyActorAddr) -> anyhow::Result<()>
"/web_api/energy/cached_consumption",
web::get().to(energy_controller::cached_consumption),
)
.route(
"/web_api/energy/relays_consumption",
web::get().to(energy_controller::relays_consumption),
)
.route(
"/web_api/energy/relays_consumption/history",
web::get().to(energy_controller::relays_consumption_history),

View File

@ -1,4 +1,5 @@
use crate::app_config::ConsumptionHistoryType;
use crate::energy::consumption::EnergyConsumption;
use crate::energy::consumption_history_file::ConsumptionHistoryFile;
use crate::energy::{consumption, energy_actor};
use crate::server::custom_error::HttpResult;
@ -36,6 +37,14 @@ pub async fn cached_consumption(energy_actor: WebEnergyActor) -> HttpResult {
Ok(HttpResponse::Ok().json(Consumption { consumption }))
}
/// Get current relays consumption
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 }))
}
pub async fn relays_consumption_history() -> HttpResult {
let history = ConsumptionHistoryFile::get_history(
ConsumptionHistoryType::RelayConsumption,