chore: clippy

This commit is contained in:
gak 2023-08-29 11:41:40 +10:00
parent e3c1044dd3
commit 1c3a002a94
No known key found for this signature in database
6 changed files with 16 additions and 16 deletions

View file

@ -18,7 +18,7 @@ async fn main() {
let vehicles = api.vehicles().await.unwrap(); let vehicles = api.vehicles().await.unwrap();
dbg!(&vehicles); dbg!(&vehicles);
if vehicles.len() > 0 { if !vehicles.is_empty() {
let vehicle_data = api.vehicle_data(&vehicles[0].id).await.unwrap(); let vehicle_data = api.vehicle_data(&vehicles[0].id).await.unwrap();
dbg!(vehicle_data); dbg!(vehicle_data);

View file

@ -37,7 +37,7 @@ impl Api {
} }
pub async fn from_refresh_token(refresh_token: &RefreshToken) -> Result<Api, TeslatteError> { pub async fn from_refresh_token(refresh_token: &RefreshToken) -> Result<Api, TeslatteError> {
let response = Self::refresh_token(&refresh_token).await?; let response = Self::refresh_token(refresh_token).await?;
Ok(Api::new( Ok(Api::new(
response.access_token, response.access_token,
Some(response.refresh_token), Some(response.refresh_token),
@ -82,7 +82,7 @@ impl Api {
match &self.refresh_token { match &self.refresh_token {
None => Err(TeslatteError::NoRefreshToken), None => Err(TeslatteError::NoRefreshToken),
Some(refresh_token) => { Some(refresh_token) => {
let response = Self::refresh_token(&refresh_token).await?; let response = Self::refresh_token(refresh_token).await?;
self.access_token = response.access_token; self.access_token = response.access_token;
self.refresh_token = Some(response.refresh_token); self.refresh_token = Some(response.refresh_token);
Ok(()) Ok(())

View file

@ -26,13 +26,13 @@ impl EnergySiteArgs {
let start_date = args let start_date = args
.start .start
.as_ref() .as_ref()
.map(|s| DateTime::parse_from_rfc3339(&s).into_diagnostic()) .map(|s| DateTime::parse_from_rfc3339(s).into_diagnostic())
.transpose() .transpose()
.wrap_err("start_date")?; .wrap_err("start_date")?;
let end_date = args let end_date = args
.end .end
.as_ref() .as_ref()
.map(|s| DateTime::parse_from_rfc3339(&s).into_diagnostic()) .map(|s| DateTime::parse_from_rfc3339(s).into_diagnostic())
.transpose() .transpose()
.wrap_err("end_date")?; .wrap_err("end_date")?;
let values = CalendarHistoryValues { let values = CalendarHistoryValues {

View file

@ -119,19 +119,19 @@ mod tests {
if let EnergySite::Powerwall(data) = serde_json::from_str(json).unwrap() { if let EnergySite::Powerwall(data) = serde_json::from_str(json).unwrap() {
assert_eq!(data.battery_type, "ac_powerwall"); assert_eq!(data.battery_type, "ac_powerwall");
assert_eq!(data.backup_capable, true); assert!(data.backup_capable);
assert_eq!(data.battery_power, -280); assert_eq!(data.battery_power, -280);
assert_eq!(data.sync_grid_alert_enabled, true); assert!(data.sync_grid_alert_enabled);
assert_eq!(data.breaker_alert_enabled, false); assert!(!data.breaker_alert_enabled);
assert_eq!(data.components.battery, true); assert!(data.components.battery);
assert_eq!( assert_eq!(
data.components.battery_type, data.components.battery_type,
Some("ac_powerwall".to_string()) Some("ac_powerwall".to_string())
); );
assert_eq!(data.components.solar, true); assert!(data.components.solar);
assert_eq!(data.components.solar_type, Some("pv_panel".to_string())); assert_eq!(data.components.solar_type, Some("pv_panel".to_string()));
assert_eq!(data.components.grid, true); assert!(data.components.grid);
assert_eq!(data.components.load_meter, true); assert!(data.components.load_meter);
assert_eq!(data.components.market_type, "residential"); assert_eq!(data.components.market_type, "residential");
} else { } else {
panic!("Expected PowerwallData"); panic!("Expected PowerwallData");
@ -220,8 +220,8 @@ mod tests {
assert_eq!(v.access_type, "OWNER"); assert_eq!(v.access_type, "OWNER");
assert_eq!(v.tokens, vec!["asdf1234"]); assert_eq!(v.tokens, vec!["asdf1234"]);
assert_eq!(v.state, "online"); assert_eq!(v.state, "online");
assert_eq!(v.in_service, false); assert!(!v.in_service);
assert_eq!(v.calendar_enabled, true); assert!(v.calendar_enabled);
assert_eq!(v.api_version, 42); assert_eq!(v.api_version, 42);
assert_eq!(v.backseat_token, None); assert_eq!(v.backseat_token, None);
assert_eq!(v.backseat_token_updated_at, None); assert_eq!(v.backseat_token_updated_at, None);

View file

@ -285,7 +285,7 @@ where
pub(crate) fn join_query_pairs(pairs: &[(&str, String)]) -> String { pub(crate) fn join_query_pairs(pairs: &[(&str, String)]) -> String {
pairs pairs
.iter() .iter()
.map(|(k, v)| format!("{}={}", k, v.replace("+", "%2B"))) .map(|(k, v)| format!("{}={}", k, v.replace('+', "%2B")))
.collect::<Vec<_>>() .collect::<Vec<_>>()
.join("&") .join("&")
} }

View file

@ -35,7 +35,7 @@ pub struct PowerwallEnergyHistoryValues {
impl Values for PowerwallEnergyHistoryValues { impl Values for PowerwallEnergyHistoryValues {
fn format(&self, url: &str) -> String { fn format(&self, url: &str) -> String {
let url = url.replace("{}", &format!("{}", self.powerwall_id.0)); let url = url.replace("{}", &self.powerwall_id.0.to_string());
let mut pairs: Vec<(&str, String)> = vec![ let mut pairs: Vec<(&str, String)> = vec![
("period", self.period.to_string()), ("period", self.period.to_string()),
("kind", self.kind.to_string()), ("kind", self.kind.to_string()),