Change relay number to needed setting value

This commit is contained in:
Tobias Reisinger 2024-05-05 22:45:59 +02:00
parent c3b185b592
commit e9ea0b625d
Signed by: serguzim
GPG key ID: 13AD60C237A28DFE

View file

@ -11,7 +11,7 @@ use crate::driver::Driver;
pub struct Relay { pub struct Relay {
pub driver: Driver, pub driver: Driver,
pub name: String, pub name: String,
pub number: Option<i64>, pub number: i64,
pub pin: u8, pub pin: u8,
pub inverted: bool, pub inverted: bool,
pub pulse: Option<u64>, pub pulse: Option<u64>,
@ -58,20 +58,12 @@ impl Default for Relay {
} }
pub fn init() -> Result<Settings, EmgauwaError> { pub fn init() -> Result<Settings, EmgauwaError> {
let mut settings: Settings = settings::load("controller", "CONTROLLER")?; settings::load("controller", "CONTROLLER")
for (num, relay) in settings.relays.iter_mut().enumerate() {
if relay.number.is_none() {
relay.number = Some(num as i64);
}
}
Ok(settings)
} }
impl Settings { impl Settings {
pub fn get_relay(&self, number: i64) -> Option<&Relay> { pub fn get_relay(&self, number: i64) -> Option<&Relay> {
self.relays.iter().find(|r| r.number == Some(number)) self.relays.iter().find(|r| r.number == number)
} }
pub fn relays_make_drivers( pub fn relays_make_drivers(