filter by characteristic rather than service
This commit is contained in:
parent
589542ec0b
commit
d2bc889b53
|
@ -5,7 +5,9 @@ use std::{collections::HashMap, path::PathBuf, time::Duration};
|
||||||
|
|
||||||
use clap::{Parser, Subcommand};
|
use clap::{Parser, Subcommand};
|
||||||
use futures_util::{pin_mut, StreamExt};
|
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;
|
use server::launch;
|
||||||
|
|
||||||
mod server;
|
mod server;
|
||||||
|
@ -29,18 +31,14 @@ enum Commands {
|
||||||
Discover,
|
Discover,
|
||||||
}
|
}
|
||||||
|
|
||||||
const SENSORS: [ServiceType; 11] = [
|
const MONITORED_CHARACTERISTICS: [CharacteristicType; 7] = [
|
||||||
ServiceType::AirQualitySensor,
|
CharacteristicType::CurrentTemperature,
|
||||||
ServiceType::CarbonDioxideSensor,
|
CharacteristicType::PM2_5Density,
|
||||||
ServiceType::CarbonMonoxideSensor,
|
CharacteristicType::PM10Density,
|
||||||
ServiceType::ContactSensor,
|
CharacteristicType::AirQuality,
|
||||||
ServiceType::HumiditySensor,
|
CharacteristicType::CurrentRelativeHumidity,
|
||||||
ServiceType::LeakSensor,
|
CharacteristicType::AirParticulateDensity,
|
||||||
ServiceType::LightSensor,
|
CharacteristicType::AirParticulateSize,
|
||||||
ServiceType::MotionSensor,
|
|
||||||
ServiceType::OccupancySensor,
|
|
||||||
ServiceType::SmokeSensor,
|
|
||||||
ServiceType::TemperatureSensor,
|
|
||||||
];
|
];
|
||||||
|
|
||||||
#[launch]
|
#[launch]
|
||||||
|
|
|
@ -3,7 +3,7 @@ use rocket::State;
|
||||||
use std::{collections::HashMap, ops::DerefMut};
|
use std::{collections::HashMap, ops::DerefMut};
|
||||||
use tokio::sync::Mutex;
|
use tokio::sync::Mutex;
|
||||||
|
|
||||||
use crate::SENSORS;
|
use crate::MONITORED_CHARACTERISTICS;
|
||||||
|
|
||||||
pub fn launch(
|
pub fn launch(
|
||||||
paired: HashMap<String, DeviceConnection>,
|
paired: HashMap<String, DeviceConnection>,
|
||||||
|
@ -25,11 +25,10 @@ pub async fn metrics(state: &State<Mutex<HashMap<String, DeviceConnection>>>) ->
|
||||||
|
|
||||||
for (aid, accessory) in &connected.accessories {
|
for (aid, accessory) in &connected.accessories {
|
||||||
for service in accessory.services.values() {
|
for service in accessory.services.values() {
|
||||||
if !SENSORS.contains(&service.service_type) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (cid, characteristic) in &service.characteristics {
|
for (cid, characteristic) in &service.characteristics {
|
||||||
|
if !MONITORED_CHARACTERISTICS.contains(&characteristic.characteristic_type) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if let Some(value) = &characteristic.value {
|
if let Some(value) = &characteristic.value {
|
||||||
if !shown_types.contains(&characteristic.characteristic_type) {
|
if !shown_types.contains(&characteristic.characteristic_type) {
|
||||||
s.push_str(
|
s.push_str(
|
||||||
|
|
Loading…
Reference in a new issue