Format code a bit

This commit is contained in:
Tobias Reisinger 2024-05-23 20:16:44 +02:00
parent c524d089ad
commit bf3192ec65
Signed by: serguzim
GPG key ID: 13AD60C237A28DFE
7 changed files with 31 additions and 23 deletions

BIN
Cargo.lock generated

Binary file not shown.

View file

@ -2,6 +2,7 @@ pub use gpio::GpioDriver;
pub use null::NullDriver;
pub use piface::PiFaceDriver;
use serde::{Deserialize, Deserializer};
use crate::errors::EmgauwaControllerError;
mod gpio;

View file

@ -11,7 +11,9 @@ pub struct PiFaceDriver {
impl PiFaceDriver {
pub fn new(pin: u8, pfd: &Option<PiFaceDigital>) -> Result<Self, EmgauwaControllerError> {
let pfd = pfd.as_ref().ok_or(EmgauwaControllerError::Hardware(String::from(
let pfd = pfd
.as_ref()
.ok_or(EmgauwaControllerError::Hardware(String::from(
"PiFaceDigital not initialized",
)))?;
let pfd_pin = pfd.get_output_pin(pin)?;

View file

@ -1,10 +1,10 @@
use std::fmt::{Display, Formatter};
use emgauwa_common::errors::EmgauwaError;
use rppal::gpio;
use rppal_mcp23s17::Mcp23s17Error;
use rppal_pfd::PiFaceDigitalError;
use emgauwa_common::errors::EmgauwaError;
#[derive(Debug)]
pub enum EmgauwaControllerError {
Hardware(String),

View file

@ -15,11 +15,11 @@ use crate::ws::run_ws_loop;
mod app_state;
mod drivers;
mod errors;
mod relay_loop;
mod settings;
mod utils;
mod ws;
mod errors;
async fn create_this_controller(
conn: &mut PoolConnection<Sqlite>,
@ -80,11 +80,7 @@ async fn main() -> Result<(), std::io::Error> {
};
for relay in &settings.relays {
if DbRelay::get_by_controller_and_num(
&mut conn,
&db_controller,
relay.number,
)
if DbRelay::get_by_controller_and_num(&mut conn, &db_controller, relay.number)
.await
.map_err(EmgauwaError::from)?
.is_none()
@ -103,7 +99,11 @@ async fn main() -> Result<(), std::io::Error> {
let this = Controller::from_db_model(&mut conn, db_controller).map_err(EmgauwaError::from)?;
let now = chrono::Local::now().time();
let initial_states: Vec<bool> = this.relays.iter().map(|r| r.active_schedule.is_on(&now)).collect();
let initial_states: Vec<bool> = this
.relays
.iter()
.map(|r| r.active_schedule.is_on(&now))
.collect();
let mut pfd: Option<PiFaceDigital> = None;
let drivers = settings.relays_make_drivers(&mut pfd, initial_states)?;

View file

@ -2,6 +2,7 @@ use emgauwa_common::errors::EmgauwaError;
use emgauwa_common::settings;
use rppal_pfd::PiFaceDigital;
use serde_derive::Deserialize;
use crate::drivers;
#[derive(Clone, Debug, Deserialize)]
@ -71,7 +72,11 @@ impl Settings {
initial_states: Vec<bool>,
) -> Result<Vec<Box<dyn drivers::RelayDriver>>, EmgauwaError> {
let mut drivers = Vec::new();
let result: Result<(), EmgauwaError> = self.relays.iter().zip(initial_states).try_for_each(|(relay, state)| {
let result: Result<(), EmgauwaError> =
self.relays
.iter()
.zip(initial_states)
.try_for_each(|(relay, state)| {
let driver = relay.make_driver(pfd, state)?;
drivers.push(driver);
Ok(())

View file

@ -7,8 +7,8 @@ use emgauwa_common::types::ControllerWsAction;
use futures::{future, pin_mut, SinkExt, StreamExt};
use sqlx::{Pool, Sqlite};
use tokio::time;
use tokio_tungstenite::tungstenite::Message;
use tokio_tungstenite::connect_async;
use tokio_tungstenite::tungstenite::Message;
use crate::app_state::AppState;
use crate::utils::{app_state_get_relay_notifier, app_state_get_this};