diff --git a/Cargo.toml b/Cargo.toml index 8d6436d..7aad866 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,6 +12,11 @@ fancy-errors = ["miette/fancy"] cli = ["dep:clap", "dep:tracing-subscriber"] cli-pretty-json = ["dep:colored_json"] +[[bin]] +name = "teslatte" +path = "src/main.rs" +required-features = ["cli"] + [dependencies] miette = { version = "5.10.0", features = ["fancy"] } thiserror = "1.0.44" diff --git a/justfile b/justfile index 8efed08..83549a6 100644 --- a/justfile +++ b/justfile @@ -8,4 +8,5 @@ no_token_test: # These tests require an access token saved in a file called "cli.json" token_tests: cargo run -- api vehicles + cargo run --no-default-features --features cli -- api vehicles cargo run -- api energy-sites diff --git a/src/cli.rs b/src/cli.rs index 48f1f53..c29da1a 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -1,10 +1,9 @@ -use crate::Data; - -pub mod calendar_history; pub mod energy; pub mod powerwall; pub mod vehicle; +use crate::Data; + pub fn print_json(data: Data) { #[cfg(feature = "cli-pretty-json")] { @@ -14,7 +13,6 @@ pub fn print_json(data: Data) { #[cfg(not(feature = "cli-pretty-json"))] { - println!("{:#?}", data.body()); - panic!(); + println!("{}", data.body()); } } diff --git a/src/cli/calendar_history.rs b/src/cli/calendar_history.rs deleted file mode 100644 index 081a431..0000000 --- a/src/cli/calendar_history.rs +++ /dev/null @@ -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, - - #[clap(short, long)] - pub end: Option, -} diff --git a/src/cli/energy.rs b/src/cli/energy.rs index e3c2c1d..6fb955b 100644 --- a/src/cli/energy.rs +++ b/src/cli/energy.rs @@ -1,5 +1,4 @@ -use crate::calendar_history::CalendarHistoryValues; -use crate::cli::calendar_history::CalendarHistoryArgs; +use crate::calendar_history::{CalendarHistoryValues, HistoryKind, HistoryPeriod}; use crate::cli::print_json; use crate::energy::EnergySiteId; use crate::Api; @@ -49,3 +48,29 @@ impl EnergySiteArgs { 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, + + /// ISO8601 date-time for the end of the period, e.g. 2025-01-01T00:00:00Z + #[clap(short, long)] + pub end: Option, +}