Devices and some settings are now loaded from the config file instead of hardcoded
This commit is contained in:
@@ -1,21 +1,56 @@
|
||||
use std::{fs, error::Error};
|
||||
use std::{fs, error::Error, collections::HashMap};
|
||||
|
||||
use log::debug;
|
||||
use serde::Deserialize;
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct Config {
|
||||
pub mqtt: MQTT,
|
||||
pub mqtt: MQTTConfig,
|
||||
pub fullfillment: FullfillmentConfig,
|
||||
#[serde(default)]
|
||||
pub devices: HashMap<String, Device>
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct MQTT {
|
||||
pub struct MQTTConfig {
|
||||
pub host: String,
|
||||
pub port: u16,
|
||||
pub username: String,
|
||||
pub password: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct FullfillmentConfig {
|
||||
pub port: u16,
|
||||
pub username: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct InfoConfig {
|
||||
pub name: String,
|
||||
pub room: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct ZigbeeDeviceConfig {
|
||||
pub topic: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct KettleConfig {
|
||||
// @TODO Add options for the kettle
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
#[serde(tag = "type")]
|
||||
pub enum Device {
|
||||
IkeaOutlet {
|
||||
info: InfoConfig,
|
||||
zigbee: ZigbeeDeviceConfig,
|
||||
kettle: Option<KettleConfig>,
|
||||
},
|
||||
}
|
||||
|
||||
impl Config {
|
||||
pub fn build(filename: &str) -> Result<Self, Box<dyn Error>> {
|
||||
debug!("Loading config: {filename}");
|
||||
|
||||
Reference in New Issue
Block a user