fix: double url appended, chore: lint cleanups
This commit is contained in:
parent
2bd682de6a
commit
009ae67734
|
@ -19,10 +19,7 @@ url = "2.2"
|
|||
serde = { version = "1.0", features = ["derive"] }
|
||||
serde_json = "1.0"
|
||||
rustls = "0.20"
|
||||
sha256 = "1.0"
|
||||
base64 = "0.13"
|
||||
rand = "0.8"
|
||||
regex = "1.5"
|
||||
chrono = { version = "0.4", features = ["serde"] }
|
||||
strum = { version = "0.24.1", features = ["derive"] }
|
||||
urlencoding = "2.1.0"
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
use clap::Parser;
|
||||
use std::env;
|
||||
use teslatte::auth::AccessToken;
|
||||
use teslatte::vehicles::SetChargeLimit;
|
||||
use teslatte::Api;
|
||||
|
||||
#[tokio::main]
|
||||
|
@ -10,7 +8,11 @@ async fn main() {
|
|||
|
||||
let api = match env::var("TESLA_ACCESS_TOKEN") {
|
||||
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();
|
||||
|
|
|
@ -3,15 +3,13 @@ mod cli_vehicle;
|
|||
use chrono::DateTime;
|
||||
use clap::{Args, Parser, Subcommand};
|
||||
use cli_vehicle::VehicleArgs;
|
||||
use miette::{miette, IntoDiagnostic, WrapErr};
|
||||
use miette::{IntoDiagnostic, WrapErr};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use teslatte::auth::{AccessToken, RefreshToken};
|
||||
use teslatte::calendar_history::{CalendarHistoryValues, HistoryKind, HistoryPeriod};
|
||||
use teslatte::energy::EnergySiteId;
|
||||
use teslatte::powerwall::{PowerwallEnergyHistoryValues, PowerwallId};
|
||||
use teslatte::vehicles::{SetChargeLimit, SetChargingAmps};
|
||||
use teslatte::{Api, VehicleId};
|
||||
use tracing_subscriber::util::SubscriberInitExt;
|
||||
use teslatte::Api;
|
||||
|
||||
/// Teslatte
|
||||
///
|
||||
|
|
|
@ -1,7 +1,11 @@
|
|||
use clap::{Args, Parser, Subcommand};
|
||||
use clap::{Args, Subcommand};
|
||||
use teslatte::vehicles::{SetChargeLimit, SetChargingAmps};
|
||||
use teslatte::{Api, VehicleId};
|
||||
|
||||
pub fn main() {
|
||||
todo!()
|
||||
}
|
||||
|
||||
#[derive(Debug, Args)]
|
||||
pub struct VehicleArgs {
|
||||
pub id: VehicleId,
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
use crate::TeslatteError::UnhandledReqwestError;
|
||||
use crate::{Api, TeslatteError};
|
||||
use derive_more::{Display, FromStr};
|
||||
use rand::Rng;
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
use crate::energy::EnergySiteId;
|
||||
use crate::Values;
|
||||
use crate::{get_args, join_query_pairs, rfc3339, Api};
|
||||
use crate::{TeslatteError, Values};
|
||||
use chrono::{DateTime, FixedOffset};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde::Deserialize;
|
||||
use strum::{Display, EnumString, IntoStaticStr};
|
||||
use urlencoding::encode;
|
||||
|
||||
#[rustfmt::skip]
|
||||
impl Api {
|
||||
|
|
|
@ -1,14 +1,9 @@
|
|||
use crate::error::TeslatteError;
|
||||
use crate::powerwall::PowerwallId;
|
||||
use crate::vehicles::VehicleData;
|
||||
use crate::{
|
||||
get, get_arg, get_args, post_arg, post_arg_empty, Api, Empty, ExternalVehicleId, VehicleId,
|
||||
};
|
||||
use chrono::{DateTime, FixedOffset};
|
||||
use crate::{get, Api};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::str::FromStr;
|
||||
use strum::{Display, EnumString};
|
||||
use url::{Url, UrlQuery};
|
||||
|
||||
#[rustfmt::skip]
|
||||
impl Api {
|
||||
|
@ -90,6 +85,7 @@ mod tests {
|
|||
use super::*;
|
||||
use crate::calendar_history::{CalendarHistoryValues, HistoryKind, HistoryPeriod};
|
||||
use crate::Values;
|
||||
use chrono::DateTime;
|
||||
|
||||
#[test]
|
||||
fn energy_match_powerwall() {
|
||||
|
|
11
src/lib.rs
11
src/lib.rs
|
@ -2,11 +2,10 @@ use crate::auth::{AccessToken, RefreshToken};
|
|||
use crate::error::TeslatteError;
|
||||
use chrono::{DateTime, SecondsFormat, TimeZone};
|
||||
use derive_more::{Display, FromStr};
|
||||
use miette::IntoDiagnostic;
|
||||
use reqwest::Client;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::fmt::{Debug, Display, Formatter};
|
||||
use tracing::{debug, instrument, trace};
|
||||
use std::fmt::{Debug, Display};
|
||||
use tracing::{instrument, trace};
|
||||
|
||||
pub mod auth;
|
||||
pub mod calendar_history;
|
||||
|
@ -52,17 +51,15 @@ impl Api {
|
|||
}
|
||||
|
||||
#[instrument(skip(self))]
|
||||
async fn get<D>(&self, path: &str) -> Result<D, TeslatteError>
|
||||
async fn get<D>(&self, url: &str) -> Result<D, TeslatteError>
|
||||
where
|
||||
// I don't understand but it works: https://stackoverflow.com/a/60131725/11125
|
||||
D: for<'de> Deserialize<'de> + Debug,
|
||||
{
|
||||
let url = format!("{}{}", API_URL, path);
|
||||
let request = || format!("GET {url}");
|
||||
trace!(?url, "Fetching");
|
||||
let response = self
|
||||
.client
|
||||
.get(&url)
|
||||
.get(url)
|
||||
.header("Authorization", format!("Bearer {}", self.access_token.0))
|
||||
.header("Accept", "application/json")
|
||||
.send()
|
||||
|
|
|
@ -1,15 +1,9 @@
|
|||
use crate::calendar_history::{HistoryKind, HistoryPeriod};
|
||||
use crate::energy::GatewayId;
|
||||
use crate::error::TeslatteError;
|
||||
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 crate::{get_arg, get_args, join_query_pairs, rfc3339, Api, Values};
|
||||
use chrono::{DateTime, FixedOffset};
|
||||
use derive_more::{Display, FromStr};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::fmt::{Display, Formatter};
|
||||
|
||||
#[rustfmt::skip]
|
||||
impl Api {
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
///
|
||||
/// 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.
|
||||
use crate::error::TeslatteError;
|
||||
use crate::{get, get_arg, post_arg, post_arg_empty, Api, Empty, ExternalVehicleId, VehicleId};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
|
|
Loading…
Reference in a new issue