From d2bc889b53829b579a78848c7e9f15f41c5bdf7b Mon Sep 17 00:00:00 2001 From: Alex Janka Date: Sat, 9 Mar 2024 08:19:12 +1100 Subject: [PATCH] filter by characteristic rather than service --- homekit-exporter/src/main.rs | 24 +++++++++++------------- homekit-exporter/src/server.rs | 9 ++++----- 2 files changed, 15 insertions(+), 18 deletions(-) diff --git a/homekit-exporter/src/main.rs b/homekit-exporter/src/main.rs index a591cdb..e4b781c 100644 --- a/homekit-exporter/src/main.rs +++ b/homekit-exporter/src/main.rs @@ -5,7 +5,9 @@ use std::{collections::HashMap, path::PathBuf, time::Duration}; use clap::{Parser, Subcommand}; use futures_util::{pin_mut, StreamExt}; -use homekit_controller::{spawn_discover_thread, DeviceConnection, HomekitError, ServiceType}; +use homekit_controller::{ + spawn_discover_thread, CharacteristicType, DeviceConnection, HomekitError, +}; use server::launch; mod server; @@ -29,18 +31,14 @@ enum Commands { Discover, } -const SENSORS: [ServiceType; 11] = [ - ServiceType::AirQualitySensor, - ServiceType::CarbonDioxideSensor, - ServiceType::CarbonMonoxideSensor, - ServiceType::ContactSensor, - ServiceType::HumiditySensor, - ServiceType::LeakSensor, - ServiceType::LightSensor, - ServiceType::MotionSensor, - ServiceType::OccupancySensor, - ServiceType::SmokeSensor, - ServiceType::TemperatureSensor, +const MONITORED_CHARACTERISTICS: [CharacteristicType; 7] = [ + CharacteristicType::CurrentTemperature, + CharacteristicType::PM2_5Density, + CharacteristicType::PM10Density, + CharacteristicType::AirQuality, + CharacteristicType::CurrentRelativeHumidity, + CharacteristicType::AirParticulateDensity, + CharacteristicType::AirParticulateSize, ]; #[launch] diff --git a/homekit-exporter/src/server.rs b/homekit-exporter/src/server.rs index 6c9caaa..e43bba5 100644 --- a/homekit-exporter/src/server.rs +++ b/homekit-exporter/src/server.rs @@ -3,7 +3,7 @@ use rocket::State; use std::{collections::HashMap, ops::DerefMut}; use tokio::sync::Mutex; -use crate::SENSORS; +use crate::MONITORED_CHARACTERISTICS; pub fn launch( paired: HashMap, @@ -25,11 +25,10 @@ pub async fn metrics(state: &State>>) -> for (aid, accessory) in &connected.accessories { for service in accessory.services.values() { - if !SENSORS.contains(&service.service_type) { - continue; - } - for (cid, characteristic) in &service.characteristics { + if !MONITORED_CHARACTERISTICS.contains(&characteristic.characteristic_type) { + continue; + } if let Some(value) = &characteristic.value { if !shown_types.contains(&characteristic.characteristic_type) { s.push_str(