Some cleanup and added light sensor

This commit is contained in:
2023-01-03 20:46:37 +01:00
parent cfd10a7daf
commit c9b2127eed
10 changed files with 182 additions and 43 deletions

View File

@@ -3,7 +3,7 @@ use std::{time::Duration, sync::{Arc, RwLock}, process, net::SocketAddr};
use axum::{Router, Json, routing::post, http::StatusCode};
use automation::{config::Config, presence::Presence, ntfy::Ntfy};
use automation::{config::Config, presence::Presence, ntfy::Ntfy, light_sensor::{self, LightSensor}};
use dotenv::dotenv;
use rumqttc::{MqttOptions, Transport, AsyncClient};
use tracing::{error, info, metadata::LevelFilter};
@@ -58,6 +58,12 @@ async fn main() {
let presence = Arc::new(RwLock::new(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));
let light_sensor = Arc::new(RwLock::new(light_sensor));
mqtt.add_listener(Arc::downgrade(&light_sensor));
// Start mqtt, this spawns a seperate async task
mqtt.start();