Display relay consumption history
This commit is contained in:
@ -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),
|
||||
|
@ -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,
|
||||
|
Reference in New Issue
Block a user