fix: double url appended, chore: lint cleanups

This commit is contained in:
gak 2023-08-29 10:29:06 +10:00
parent 2bd682de6a
commit 009ae67734
No known key found for this signature in database
10 changed files with 21 additions and 36 deletions

View file

@ -19,10 +19,7 @@ url = "2.2"
serde = { version = "1.0", features = ["derive"] } serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0" serde_json = "1.0"
rustls = "0.20" rustls = "0.20"
sha256 = "1.0"
base64 = "0.13"
rand = "0.8" rand = "0.8"
regex = "1.5"
chrono = { version = "0.4", features = ["serde"] } chrono = { version = "0.4", features = ["serde"] }
strum = { version = "0.24.1", features = ["derive"] } strum = { version = "0.24.1", features = ["derive"] }
urlencoding = "2.1.0" urlencoding = "2.1.0"

View file

@ -1,7 +1,5 @@
use clap::Parser;
use std::env; use std::env;
use teslatte::auth::AccessToken; use teslatte::auth::AccessToken;
use teslatte::vehicles::SetChargeLimit;
use teslatte::Api; use teslatte::Api;
#[tokio::main] #[tokio::main]
@ -10,7 +8,11 @@ async fn main() {
let api = match env::var("TESLA_ACCESS_TOKEN") { let api = match env::var("TESLA_ACCESS_TOKEN") {
Ok(t) => Api::new(AccessToken(t), None), Ok(t) => Api::new(AccessToken(t), None),
Err(_) => Api::from_interactive_url().await.unwrap(), Err(_) => {
let api = Api::from_interactive_url().await.unwrap();
println!("TOKEN: {:?}", api.access_token);
api
}
}; };
let vehicles = api.vehicles().await.unwrap(); let vehicles = api.vehicles().await.unwrap();

View file

@ -3,15 +3,13 @@ mod cli_vehicle;
use chrono::DateTime; use chrono::DateTime;
use clap::{Args, Parser, Subcommand}; use clap::{Args, Parser, Subcommand};
use cli_vehicle::VehicleArgs; use cli_vehicle::VehicleArgs;
use miette::{miette, IntoDiagnostic, WrapErr}; use miette::{IntoDiagnostic, WrapErr};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use teslatte::auth::{AccessToken, RefreshToken}; use teslatte::auth::{AccessToken, RefreshToken};
use teslatte::calendar_history::{CalendarHistoryValues, HistoryKind, HistoryPeriod}; use teslatte::calendar_history::{CalendarHistoryValues, HistoryKind, HistoryPeriod};
use teslatte::energy::EnergySiteId; use teslatte::energy::EnergySiteId;
use teslatte::powerwall::{PowerwallEnergyHistoryValues, PowerwallId}; use teslatte::powerwall::{PowerwallEnergyHistoryValues, PowerwallId};
use teslatte::vehicles::{SetChargeLimit, SetChargingAmps}; use teslatte::Api;
use teslatte::{Api, VehicleId};
use tracing_subscriber::util::SubscriberInitExt;
/// Teslatte /// Teslatte
/// ///

View file

@ -1,7 +1,11 @@
use clap::{Args, Parser, Subcommand}; use clap::{Args, Subcommand};
use teslatte::vehicles::{SetChargeLimit, SetChargingAmps}; use teslatte::vehicles::{SetChargeLimit, SetChargingAmps};
use teslatte::{Api, VehicleId}; use teslatte::{Api, VehicleId};
pub fn main() {
todo!()
}
#[derive(Debug, Args)] #[derive(Debug, Args)]
pub struct VehicleArgs { pub struct VehicleArgs {
pub id: VehicleId, pub id: VehicleId,

View file

@ -1,4 +1,3 @@
use crate::TeslatteError::UnhandledReqwestError;
use crate::{Api, TeslatteError}; use crate::{Api, TeslatteError};
use derive_more::{Display, FromStr}; use derive_more::{Display, FromStr};
use rand::Rng; use rand::Rng;

View file

@ -1,10 +1,9 @@
use crate::energy::EnergySiteId; use crate::energy::EnergySiteId;
use crate::Values;
use crate::{get_args, join_query_pairs, rfc3339, Api}; use crate::{get_args, join_query_pairs, rfc3339, Api};
use crate::{TeslatteError, Values};
use chrono::{DateTime, FixedOffset}; use chrono::{DateTime, FixedOffset};
use serde::{Deserialize, Serialize}; use serde::Deserialize;
use strum::{Display, EnumString, IntoStaticStr}; use strum::{Display, EnumString, IntoStaticStr};
use urlencoding::encode;
#[rustfmt::skip] #[rustfmt::skip]
impl Api { impl Api {

View file

@ -1,14 +1,9 @@
use crate::error::TeslatteError; use crate::error::TeslatteError;
use crate::powerwall::PowerwallId; use crate::powerwall::PowerwallId;
use crate::vehicles::VehicleData; use crate::vehicles::VehicleData;
use crate::{ use crate::{get, Api};
get, get_arg, get_args, post_arg, post_arg_empty, Api, Empty, ExternalVehicleId, VehicleId,
};
use chrono::{DateTime, FixedOffset};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::str::FromStr; use std::str::FromStr;
use strum::{Display, EnumString};
use url::{Url, UrlQuery};
#[rustfmt::skip] #[rustfmt::skip]
impl Api { impl Api {
@ -90,6 +85,7 @@ mod tests {
use super::*; use super::*;
use crate::calendar_history::{CalendarHistoryValues, HistoryKind, HistoryPeriod}; use crate::calendar_history::{CalendarHistoryValues, HistoryKind, HistoryPeriod};
use crate::Values; use crate::Values;
use chrono::DateTime;
#[test] #[test]
fn energy_match_powerwall() { fn energy_match_powerwall() {

View file

@ -2,11 +2,10 @@ use crate::auth::{AccessToken, RefreshToken};
use crate::error::TeslatteError; use crate::error::TeslatteError;
use chrono::{DateTime, SecondsFormat, TimeZone}; use chrono::{DateTime, SecondsFormat, TimeZone};
use derive_more::{Display, FromStr}; use derive_more::{Display, FromStr};
use miette::IntoDiagnostic;
use reqwest::Client; use reqwest::Client;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::fmt::{Debug, Display, Formatter}; use std::fmt::{Debug, Display};
use tracing::{debug, instrument, trace}; use tracing::{instrument, trace};
pub mod auth; pub mod auth;
pub mod calendar_history; pub mod calendar_history;
@ -52,17 +51,15 @@ impl Api {
} }
#[instrument(skip(self))] #[instrument(skip(self))]
async fn get<D>(&self, path: &str) -> Result<D, TeslatteError> async fn get<D>(&self, url: &str) -> Result<D, TeslatteError>
where where
// I don't understand but it works: https://stackoverflow.com/a/60131725/11125
D: for<'de> Deserialize<'de> + Debug, D: for<'de> Deserialize<'de> + Debug,
{ {
let url = format!("{}{}", API_URL, path);
let request = || format!("GET {url}"); let request = || format!("GET {url}");
trace!(?url, "Fetching"); trace!(?url, "Fetching");
let response = self let response = self
.client .client
.get(&url) .get(url)
.header("Authorization", format!("Bearer {}", self.access_token.0)) .header("Authorization", format!("Bearer {}", self.access_token.0))
.header("Accept", "application/json") .header("Accept", "application/json")
.send() .send()

View file

@ -1,15 +1,9 @@
use crate::calendar_history::{HistoryKind, HistoryPeriod}; use crate::calendar_history::{HistoryKind, HistoryPeriod};
use crate::energy::GatewayId; use crate::energy::GatewayId;
use crate::error::TeslatteError; use crate::{get_arg, get_args, join_query_pairs, rfc3339, Api, Values};
use crate::vehicles::VehicleData;
use crate::{
get, get_arg, get_args, join_query_pairs, post_arg, post_arg_empty, rfc3339, Api, Empty,
ExternalVehicleId, Values, VehicleId,
};
use chrono::{DateTime, FixedOffset}; use chrono::{DateTime, FixedOffset};
use derive_more::{Display, FromStr}; use derive_more::{Display, FromStr};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::fmt::{Display, Formatter};
#[rustfmt::skip] #[rustfmt::skip]
impl Api { impl Api {

View file

@ -2,7 +2,6 @@
/// ///
/// Sometimes the API will return a null for a field where I've put in a non Option type, which /// Sometimes the API will return a null for a field where I've put in a non Option type, which
/// will cause the deserializer to fail. Please log an issue to fix these if you come across it. /// will cause the deserializer to fail. Please log an issue to fix these if you come across it.
use crate::error::TeslatteError;
use crate::{get, get_arg, post_arg, post_arg_empty, Api, Empty, ExternalVehicleId, VehicleId}; use crate::{get, get_arg, post_arg, post_arg_empty, Api, Empty, ExternalVehicleId, VehicleId};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};