From 9d12bce4529466bb850d3c2ad9fe71cb6ce31c5b Mon Sep 17 00:00:00 2001 From: Alex Janka Date: Sat, 18 Jan 2025 11:58:22 +1100 Subject: [PATCH] tcc: fix clippy lints --- tesla-charge-controller/src/api/http.rs | 1 + tesla-charge-controller/src/api/mod.rs | 6 +++--- tesla-charge-controller/src/config.rs | 2 +- tesla-charge-controller/src/control.rs | 14 +++++++++++--- tesla-charge-controller/src/main.rs | 2 ++ tesla-charge-controller/src/server/mod.rs | 2 +- .../src/server/static_handler.rs | 10 ++++++---- 7 files changed, 25 insertions(+), 12 deletions(-) diff --git a/tesla-charge-controller/src/api/http.rs b/tesla-charge-controller/src/api/http.rs index 477db16..3cb3552 100644 --- a/tesla-charge-controller/src/api/http.rs +++ b/tesla-charge-controller/src/api/http.rs @@ -95,6 +95,7 @@ impl Vehicle { Ok(state.charge_state) } + #[expect(dead_code, reason = "active charge control not yet implemented")] pub async fn set_charging_amps(&self, charging_amps: i64) -> eyre::Result<()> { self.client .post(format!( diff --git a/tesla-charge-controller/src/api/mod.rs b/tesla-charge-controller/src/api/mod.rs index c3777d9..0e7cd18 100644 --- a/tesla-charge-controller/src/api/mod.rs +++ b/tesla-charge-controller/src/api/mod.rs @@ -42,11 +42,11 @@ impl Car { } } - pub fn vehicle(&self) -> &http::Vehicle { + pub const fn vehicle(&self) -> &http::Vehicle { &self.vehicle } - pub fn state(&self) -> &tokio::sync::RwLock { + pub const fn state(&self) -> &tokio::sync::RwLock { &self.state } } @@ -153,7 +153,7 @@ impl ChargeState { } } -#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq)] +#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)] pub enum ChargingState { Charging, Stopped, diff --git a/tesla-charge-controller/src/config.rs b/tesla-charge-controller/src/config.rs index 579612c..30a257d 100644 --- a/tesla-charge-controller/src/config.rs +++ b/tesla-charge-controller/src/config.rs @@ -60,7 +60,7 @@ impl ConfigWatcher { async fn overwrite_config(config: Config) -> eyre::Result<()> { *CONFIG .get() - .ok_or(eyre::eyre!("could not get config"))? + .ok_or_else(|| eyre::eyre!("could not get config"))? .write() .await = config; Ok(()) diff --git a/tesla-charge-controller/src/control.rs b/tesla-charge-controller/src/control.rs index 5769d40..065695c 100644 --- a/tesla-charge-controller/src/control.rs +++ b/tesla-charge-controller/src/control.rs @@ -4,6 +4,7 @@ pub struct VehicleController { control_state: ChargeRateControllerState, } +#[expect(dead_code, reason = "not all states are currently in use")] pub enum ChargeRateControllerState { Inactive, Charging { rate_amps: i64 }, @@ -14,7 +15,7 @@ pub enum InterfaceRequest { } impl VehicleController { - pub fn new( + pub const fn new( car: std::sync::Arc, requests: tokio::sync::mpsc::UnboundedReceiver, ) -> Self { @@ -50,7 +51,10 @@ impl VehicleController { } match self.control_state { ChargeRateControllerState::Inactive => { - if let Some(state) = self.car.state().read().await.charge_state().await { + let car_state = self.car.state().read().await; + let state = car_state.charge_state().await; + + if let Some(state) = state { if state.is_charging() { self.control_state = ChargeRateControllerState::Charging { rate_amps: state.charge_amps, @@ -58,10 +62,14 @@ impl VehicleController { } } } - ChargeRateControllerState::Charging { rate_amps } => todo!(), + ChargeRateControllerState::Charging { rate_amps: _ } => todo!(), } } + #[expect( + clippy::needless_pass_by_ref_mut, + reason = "this will eventually need to mutate self" + )] pub async fn process_requests(&mut self, req: InterfaceRequest) { if let Err(e) = match req { InterfaceRequest::FlashLights => self.car.vehicle().flash_lights().await, diff --git a/tesla-charge-controller/src/main.rs b/tesla-charge-controller/src/main.rs index 42ad162..372dd3a 100644 --- a/tesla-charge-controller/src/main.rs +++ b/tesla-charge-controller/src/main.rs @@ -1,3 +1,5 @@ +#![allow(clippy::significant_drop_tightening)] + use std::path::PathBuf; use clap::Parser; diff --git a/tesla-charge-controller/src/server/mod.rs b/tesla-charge-controller/src/server/mod.rs index 1684acc..21ebc7f 100644 --- a/tesla-charge-controller/src/server/mod.rs +++ b/tesla-charge-controller/src/server/mod.rs @@ -27,7 +27,7 @@ pub struct ServerState { } impl ServerState { - pub fn new(car: Arc, api_requests: UnboundedSender) -> Self { + pub const fn new(car: Arc, api_requests: UnboundedSender) -> Self { Self { car, api_requests } } } diff --git a/tesla-charge-controller/src/server/static_handler.rs b/tesla-charge-controller/src/server/static_handler.rs index 9f72a45..ee7c771 100644 --- a/tesla-charge-controller/src/server/static_handler.rs +++ b/tesla-charge-controller/src/server/static_handler.rs @@ -52,10 +52,12 @@ impl Handler for UiStatic { data: v.contents().to_vec(), name: p, }) - .or(UI_DIR_FILES.get_file(&plus_index).map(|v| RawHtml { - data: v.contents().to_vec(), - name: plus_index, - })); + .or_else(|| { + UI_DIR_FILES.get_file(&plus_index).map(|v| RawHtml { + data: v.contents().to_vec(), + name: plus_index, + }) + }); file.respond_to(req).or_forward((data, Status::NotFound)) } }