Made hue_bridge and ntfy optional
This commit is contained in:
parent
0b22d0c6b7
commit
cf88768c15
|
@ -1,4 +1,44 @@
|
||||||
|
[openid]
|
||||||
|
base_url = "https://login.huizinga.dev/api/oidc"
|
||||||
|
|
||||||
[mqtt]
|
[mqtt]
|
||||||
host="olympus.vpn.huizinga.dev"
|
host="olympus.vpn.huizinga.dev"
|
||||||
port=8883
|
port=8883
|
||||||
username="mqtt"
|
username="mqtt"
|
||||||
|
password="${MQTT_PASSWORD}"
|
||||||
|
|
||||||
|
[ntfy]
|
||||||
|
topic = "${NTFY_TOPIC}"
|
||||||
|
|
||||||
|
[presence]
|
||||||
|
topic = "automation_dev/presence/+/#"
|
||||||
|
|
||||||
|
[light_sensor]
|
||||||
|
topic = "zigbee2mqtt_dev/living/light"
|
||||||
|
min = 23_000
|
||||||
|
max = 25_000
|
||||||
|
|
||||||
|
[devices.kitchen_kettle]
|
||||||
|
type = "IkeaOutlet"
|
||||||
|
name = "Kettle"
|
||||||
|
room = "Kitchen"
|
||||||
|
topic = "zigbee2mqtt/kitchen/kettle"
|
||||||
|
kettle = { timeout = 5 }
|
||||||
|
|
||||||
|
[devices.living_workbench]
|
||||||
|
type = "IkeaOutlet"
|
||||||
|
name = "Workbench"
|
||||||
|
room = "Living Room"
|
||||||
|
topic = "zigbee2mqtt/living/workbench"
|
||||||
|
|
||||||
|
[devices.living_zeus]
|
||||||
|
type = "WakeOnLAN"
|
||||||
|
name = "Zeus"
|
||||||
|
room = "Living Room"
|
||||||
|
topic = "automation/appliance/living_room/zeus"
|
||||||
|
mac_address = "30:9c:23:60:9c:13"
|
||||||
|
|
||||||
|
[devices.hallway_frontdoor]
|
||||||
|
type = "ContactSensor"
|
||||||
|
topic = "zigbee2mqtt/hallway/frontdoor"
|
||||||
|
presence = { timeout = 10 }
|
||||||
|
|
|
@ -15,10 +15,10 @@ pub struct Config {
|
||||||
pub mqtt: MqttConfig,
|
pub mqtt: MqttConfig,
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub fullfillment: FullfillmentConfig,
|
pub fullfillment: FullfillmentConfig,
|
||||||
pub ntfy: NtfyConfig,
|
pub ntfy: Option<NtfyConfig>,
|
||||||
pub presence: MqttDeviceConfig,
|
pub presence: MqttDeviceConfig,
|
||||||
pub light_sensor: LightSensorConfig,
|
pub light_sensor: LightSensorConfig,
|
||||||
pub hue_bridge: HueBridgeConfig,
|
pub hue_bridge: Option<HueBridgeConfig>,
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub devices: HashMap<String, Device>
|
pub devices: HashMap<String, Device>
|
||||||
}
|
}
|
||||||
|
|
20
src/main.rs
20
src/main.rs
|
@ -76,20 +76,26 @@ async fn main() {
|
||||||
// Register devices as presence listener
|
// Register devices as presence listener
|
||||||
presence.add_listener(Arc::downgrade(&devices));
|
presence.add_listener(Arc::downgrade(&devices));
|
||||||
|
|
||||||
let ntfy = Arc::new(RwLock::new(Ntfy::new(config.ntfy)));
|
let mut light_sensor = LightSensor::new(config.light_sensor, client.clone());
|
||||||
presence.add_listener(Arc::downgrade(&ntfy));
|
light_sensor.add_listener(Arc::downgrade(&devices));
|
||||||
|
|
||||||
let hue_bridge = Arc::new(RwLock::new(HueBridge::new(config.hue_bridge)));
|
let ntfy;
|
||||||
|
if let Some(ntfy_config) = config.ntfy {
|
||||||
|
ntfy = Arc::new(RwLock::new(Ntfy::new(ntfy_config)));
|
||||||
|
presence.add_listener(Arc::downgrade(&ntfy));
|
||||||
|
}
|
||||||
|
|
||||||
|
let hue_bridge;
|
||||||
|
if let Some(hue_bridge_config) = config.hue_bridge {
|
||||||
|
hue_bridge = Arc::new(RwLock::new(HueBridge::new(hue_bridge_config)));
|
||||||
presence.add_listener(Arc::downgrade(&hue_bridge));
|
presence.add_listener(Arc::downgrade(&hue_bridge));
|
||||||
|
light_sensor.add_listener(Arc::downgrade(&hue_bridge));
|
||||||
|
}
|
||||||
|
|
||||||
// Register presence as mqtt listener
|
// Register presence as mqtt listener
|
||||||
let presence = Arc::new(RwLock::new(presence));
|
let presence = Arc::new(RwLock::new(presence));
|
||||||
mqtt.add_listener(Arc::downgrade(&presence));
|
mqtt.add_listener(Arc::downgrade(&presence));
|
||||||
|
|
||||||
let mut light_sensor = LightSensor::new(config.light_sensor, client.clone());
|
|
||||||
light_sensor.add_listener(Arc::downgrade(&devices));
|
|
||||||
light_sensor.add_listener(Arc::downgrade(&hue_bridge));
|
|
||||||
|
|
||||||
let light_sensor = Arc::new(RwLock::new(light_sensor));
|
let light_sensor = Arc::new(RwLock::new(light_sensor));
|
||||||
mqtt.add_listener(Arc::downgrade(&light_sensor));
|
mqtt.add_listener(Arc::downgrade(&light_sensor));
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use tracing::{warn, error};
|
use tracing::{warn, error, debug};
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
use serde_repr::*;
|
use serde_repr::*;
|
||||||
use pollster::FutureExt as _;
|
use pollster::FutureExt as _;
|
||||||
|
@ -116,6 +116,8 @@ impl OnPresence for Ntfy {
|
||||||
.add_action(action)
|
.add_action(action)
|
||||||
.set_priority(Priority::Low);
|
.set_priority(Priority::Low);
|
||||||
|
|
||||||
|
debug!("Notifying presence as {presence}");
|
||||||
|
|
||||||
// Create the request
|
// Create the request
|
||||||
let res = reqwest::Client::new()
|
let res = reqwest::Client::new()
|
||||||
.post(self.base_url.clone())
|
.post(self.base_url.clone())
|
||||||
|
|
Loading…
Reference in New Issue
Block a user