Compare commits

...

3 commits

Author SHA1 Message Date
Alex Janka af3a618529 version bump 2024-03-09 08:20:20 +11:00
Alex Janka d2bc889b53 filter by characteristic rather than service 2024-03-09 08:19:12 +11:00
Alex Janka 589542ec0b derive debug 2024-03-09 08:19:07 +11:00
7 changed files with 22 additions and 21 deletions

2
Cargo.lock generated
View file

@ -1143,7 +1143,7 @@ dependencies = [
[[package]] [[package]]
name = "homekit-exporter" name = "homekit-exporter"
version = "0.3.0" version = "0.4.0"
dependencies = [ dependencies = [
"clap", "clap",
"env_logger", "env_logger",

View file

@ -21,6 +21,7 @@ use crate::{
ConnectionError, HomekitError, ConnectionError, HomekitError,
}; };
#[derive(Debug)]
pub(super) struct AccessorySocket { pub(super) struct AccessorySocket {
socket: TcpStream, socket: TcpStream,
ip: String, ip: String,
@ -28,6 +29,7 @@ pub(super) struct AccessorySocket {
socket_encryption: Option<SocketEncryption>, socket_encryption: Option<SocketEncryption>,
} }
#[derive(Debug)]
struct SocketEncryption { struct SocketEncryption {
controller_to_accessory_key: [u8; 32], controller_to_accessory_key: [u8; 32],
controller_to_accessory_counter: u64, controller_to_accessory_counter: u64,

View file

@ -60,6 +60,7 @@ impl PythonPairingData {
} }
} }
#[derive(Debug)]
struct DevicePairingData { struct DevicePairingData {
accessory_pairing_id: String, accessory_pairing_id: String,
accessory_ip: String, accessory_ip: String,
@ -69,6 +70,7 @@ struct DevicePairingData {
ios_device_ltsk: [u8; 32], ios_device_ltsk: [u8; 32],
} }
#[derive(Debug)]
pub struct DeviceConnection { pub struct DeviceConnection {
pub accessories: HashMap<usize, Accessory>, pub accessories: HashMap<usize, Accessory>,
discovered: MdnsDiscoveredList, discovered: MdnsDiscoveredList,

View file

@ -1,6 +1,6 @@
[package] [package]
name = "homekit-exporter" name = "homekit-exporter"
version = "0.3.0" version = "0.4.0"
edition = "2021" edition = "2021"
license = "Apache-2.0" license = "Apache-2.0"
description = "Prometheus exporter for HomeKit sensors" description = "Prometheus exporter for HomeKit sensors"

View file

@ -1,7 +1,7 @@
# Maintainer: Alex Janka <alex@alexjanka.com> # Maintainer: Alex Janka <alex@alexjanka.com>
pkgname=homekit-logger pkgname=homekit-logger
pkgver=0.3.0 pkgver=0.4.0
pkgrel=1 pkgrel=1
pkgdesc="Prometheus exporter for HomeKit sensors" pkgdesc="Prometheus exporter for HomeKit sensors"
arch=('x86_64' 'aarch64') arch=('x86_64' 'aarch64')

View file

@ -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]

View file

@ -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(