Improved how devices are created, ntfy and presence are now treated like any other device

This commit is contained in:
2024-04-27 02:55:53 +02:00
parent 5069d1b0e7
commit 3e4ea8952a
22 changed files with 423 additions and 528 deletions

View File

@@ -8,7 +8,6 @@ use serde::{Deserialize, Deserializer};
use tracing::debug;
use crate::auth::OpenIDConfig;
use crate::devices::PresenceConfig;
use crate::error::{ConfigParseError, MissingEnv};
#[derive(Debug, Deserialize)]
@@ -18,8 +17,6 @@ pub struct Config {
pub mqtt: MqttOptions,
#[serde(default)]
pub fullfillment: FullfillmentConfig,
pub ntfy: Option<NtfyConfig>,
pub presence: PresenceConfig,
}
#[derive(Debug, Clone, Deserialize)]
@@ -85,23 +82,22 @@ fn default_fullfillment_port() -> u16 {
7878
}
#[derive(Debug, Deserialize)]
pub struct NtfyConfig {
#[serde(default = "default_ntfy_url")]
pub url: String,
pub topic: String,
}
fn default_ntfy_url() -> String {
"https://ntfy.sh".into()
}
#[derive(Debug, Clone, Deserialize)]
pub struct InfoConfig {
pub name: String,
pub room: Option<String>,
}
impl InfoConfig {
pub fn identifier(&self) -> String {
(if let Some(room) = &self.room {
room.to_ascii_lowercase().replace(' ', "_") + "_"
} else {
String::new()
}) + &self.name.to_ascii_lowercase().replace(' ', "_")
}
}
#[derive(Debug, Clone, Deserialize)]
pub struct MqttDeviceConfig {
pub topic: String,