Moved some stuff from main into the libary
This commit is contained in:
@@ -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))
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user