doc: document calendar history a bit

This commit is contained in:
gak 2023-08-29 13:55:02 +10:00
parent 8881d0fa59
commit f1f2c2e566
No known key found for this signature in database
5 changed files with 36 additions and 23 deletions

View file

@ -12,6 +12,11 @@ fancy-errors = ["miette/fancy"]
cli = ["dep:clap", "dep:tracing-subscriber"] cli = ["dep:clap", "dep:tracing-subscriber"]
cli-pretty-json = ["dep:colored_json"] cli-pretty-json = ["dep:colored_json"]
[[bin]]
name = "teslatte"
path = "src/main.rs"
required-features = ["cli"]
[dependencies] [dependencies]
miette = { version = "5.10.0", features = ["fancy"] } miette = { version = "5.10.0", features = ["fancy"] }
thiserror = "1.0.44" thiserror = "1.0.44"

View file

@ -8,4 +8,5 @@ no_token_test:
# These tests require an access token saved in a file called "cli.json" # These tests require an access token saved in a file called "cli.json"
token_tests: token_tests:
cargo run -- api vehicles cargo run -- api vehicles
cargo run --no-default-features --features cli -- api vehicles
cargo run -- api energy-sites cargo run -- api energy-sites

View file

@ -1,10 +1,9 @@
use crate::Data;
pub mod calendar_history;
pub mod energy; pub mod energy;
pub mod powerwall; pub mod powerwall;
pub mod vehicle; pub mod vehicle;
use crate::Data;
pub fn print_json<T>(data: Data<T>) { pub fn print_json<T>(data: Data<T>) {
#[cfg(feature = "cli-pretty-json")] #[cfg(feature = "cli-pretty-json")]
{ {
@ -14,7 +13,6 @@ pub fn print_json<T>(data: Data<T>) {
#[cfg(not(feature = "cli-pretty-json"))] #[cfg(not(feature = "cli-pretty-json"))]
{ {
println!("{:#?}", data.body()); println!("{}", data.body());
panic!();
} }
} }

View file

@ -1,16 +0,0 @@
use crate::calendar_history::{HistoryKind, HistoryPeriod};
use clap::Args;
#[derive(Debug, Args)]
pub struct CalendarHistoryArgs {
pub kind: HistoryKind,
#[clap(short, long, default_value = "day")]
pub period: HistoryPeriod,
#[clap(short, long)]
pub start: Option<String>,
#[clap(short, long)]
pub end: Option<String>,
}

View file

@ -1,5 +1,4 @@
use crate::calendar_history::CalendarHistoryValues; use crate::calendar_history::{CalendarHistoryValues, HistoryKind, HistoryPeriod};
use crate::cli::calendar_history::CalendarHistoryArgs;
use crate::cli::print_json; use crate::cli::print_json;
use crate::energy::EnergySiteId; use crate::energy::EnergySiteId;
use crate::Api; use crate::Api;
@ -49,3 +48,29 @@ impl EnergySiteArgs {
Ok(()) Ok(())
} }
} }
/// Show the calendar history of an energy site. This is the same data that is shown in the Tesla app.
///
/// Use `energy_site_id` as the ID.
///
/// The `kind` argument must be `energy` or `power`.
///
/// Example:
///
/// teslatte api energy-site 1234567890 calendar-history power -s "2022-01-01T00:00:00Z" -e 2023-01-01T00:00:00Z -p month
#[derive(Debug, Args)]
pub struct CalendarHistoryArgs {
/// `energy` or `power`
pub kind: HistoryKind,
#[clap(short, long, default_value = "day")]
pub period: HistoryPeriod,
/// ISO8601 date-time for the start of the period, e.g. 2000-01-01T00:00:00Z
#[clap(short, long)]
pub start: Option<String>,
/// ISO8601 date-time for the end of the period, e.g. 2025-01-01T00:00:00Z
#[clap(short, long)]
pub end: Option<String>,
}