2023-08-29 11:33:03 +10:00
|
|
|
use crate::calendar_history::{HistoryKind, HistoryPeriod};
|
2023-08-29 16:13:43 +10:00
|
|
|
use crate::cli::print_json_data;
|
2023-08-29 11:33:03 +10:00
|
|
|
use crate::powerwall::{PowerwallEnergyHistoryValues, PowerwallId};
|
|
|
|
use crate::Api;
|
|
|
|
use clap::{Args, Subcommand};
|
|
|
|
|
|
|
|
#[derive(Debug, Subcommand)]
|
|
|
|
pub enum PowerwallCommand {
|
|
|
|
/// Show the status of the Powerwall.
|
|
|
|
Status,
|
|
|
|
|
|
|
|
History,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, Args)]
|
|
|
|
pub struct PowerwallArgs {
|
|
|
|
pub id: PowerwallId,
|
|
|
|
|
|
|
|
#[clap(subcommand)]
|
|
|
|
pub command: PowerwallCommand,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl PowerwallArgs {
|
|
|
|
pub async fn run(&self, api: &Api) -> miette::Result<()> {
|
|
|
|
match self.command {
|
|
|
|
PowerwallCommand::Status => {
|
2023-08-29 16:13:43 +10:00
|
|
|
print_json_data(api.powerwall_status(&self.id).await?);
|
2023-08-29 11:33:03 +10:00
|
|
|
}
|
|
|
|
PowerwallCommand::History => {
|
2023-08-29 16:13:43 +10:00
|
|
|
print_json_data(
|
2023-08-29 11:33:03 +10:00
|
|
|
api.powerwall_energy_history(&PowerwallEnergyHistoryValues {
|
|
|
|
powerwall_id: self.id.clone(),
|
|
|
|
period: HistoryPeriod::Day,
|
|
|
|
kind: HistoryKind::Power,
|
|
|
|
start_date: None,
|
2023-08-29 13:11:28 +10:00
|
|
|
end_date: None,
|
2023-08-29 11:33:03 +10:00
|
|
|
})
|
2023-08-29 13:11:28 +10:00
|
|
|
.await?,
|
2023-08-29 11:33:03 +10:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|