Moved some stuff from main into the libary

This commit is contained in:
2022-12-28 04:17:23 +01:00
parent 2b4ddf82b6
commit 3b6a5e4c07
3 changed files with 59 additions and 47 deletions

View File

@@ -1,8 +1,11 @@
use std::{fs, error::Error, collections::HashMap};
use log::debug;
use log::{debug, trace};
use rumqttc::AsyncClient;
use serde::Deserialize;
use crate::devices::{DeviceBox, IkeaOutlet, WakeOnLAN};
#[derive(Debug, Deserialize)]
pub struct Config {
pub mqtt: MQTTConfig,
@@ -67,3 +70,18 @@ impl Config {
Ok(config)
}
}
impl Device {
pub fn into(self, identifier: String, client: AsyncClient) -> DeviceBox {
match self {
Device::IkeaOutlet { info, mqtt, kettle } => {
trace!("\tIkeaOutlet [{} in {:?}]", info.name, info.room);
Box::new(IkeaOutlet::new(identifier, info, mqtt, kettle, client))
},
Device::WakeOnLAN { info, mqtt, mac_address } => {
trace!("\tWakeOnLan [{} in {:?}]", info.name, info.room);
Box::new(WakeOnLAN::new(identifier, info, mqtt, mac_address, client))
},
}
}
}