Skip to content

Commit

Permalink
Cleanup and add readme
Browse files Browse the repository at this point in the history
  • Loading branch information
ptorsten committed Jan 21, 2024
1 parent ed07e0a commit 0c18098
Show file tree
Hide file tree
Showing 5 changed files with 221 additions and 10 deletions.
206 changes: 203 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,9 @@ clokwerk = "0.4.0"
byte-unit = { version = "5.1.2" }
flexi_logger = { version = "0.27.3", features = ["compress"] }
rumqttc = { version = "0.23.0", features = ["url"] }
test-log = "0.2.14"

[dev-dependencies]
env_logger = "*"
tracing = {version = "0.1", default-features = false}
tracing-subscriber = {version = "0.3", default-features = false, features = ["env-filter", "fmt"]}
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
[![Docker Image CI](https://github.com/ptorsten/aw-gateway-rs/actions/workflows/docker-image.yml/badge.svg)](https://github.com/ptorsten/aw-gateway-rs/actions/workflows/docker-image.yml)

Service to poll AW gateways (like OBSERVER IP) and report sensors to Home Assistant

TODO
- Supports custom sensor definitions
- Supports auto-discovery for Home Assistant for sensors
- Docker support

TODO:

- Testing
4 changes: 2 additions & 2 deletions src/gateway.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Protocol:
// https://osswww.ecowitt.net/uploads/20210716/WN1900%20GW1000,1100%20WH2680,2650%20telenet%20v1.6.0%20.pdf
//
use std::{collections::HashMap, sync::{Arc, Mutex}, time::Duration};
use std::{collections::HashMap, time::Duration};
use std::net::{TcpStream, SocketAddr, Ipv4Addr};
use std::str::{self, FromStr};
use std::io::{Read, Write, Error, ErrorKind};
Expand Down Expand Up @@ -128,7 +128,7 @@ impl SensorGateway {
mac_address: Option::None,
};

gateway.update_sensor_metadata();
let _not_used = gateway.update_sensor_metadata();
if let Ok(firmware) = gateway.get_firmware_version() {
gateway.firmware = Some(firmware);
}
Expand Down
6 changes: 2 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::{fs::File, io::BufReader, collections::HashMap, sync::{Mutex, Arc}, time::Duration};
use clokwerk::Interval;
use flexi_logger::{LoggerHandle, Logger, Criterion, FileSpec, Naming, Cleanup, Duplicate};
use gateway::{SensorGateway, SensorData, SensorValue, SensorMetadata};
use gateway::{SensorGateway, SensorData, SensorValue};
use rumqttc::{MqttOptions, Client, QoS, NetworkOptions};
use serde::{Deserialize, Serialize};
use serde_json::json;
Expand Down Expand Up @@ -137,7 +137,6 @@ struct Gateway {
gateway: SensorGateway,
sensor_config: Mutex<HashMap<String, SensorConfig>>,
discovered_sensor: Mutex<HashMap<String, DiscoverySensor>>,
metadata: Mutex<HashMap<u32, SensorMetadata>>,
}

struct Gateways {
Expand All @@ -154,7 +153,6 @@ impl Gateway {
sensor_config: Mutex::new(sensor_config),
discovered_sensor: Mutex::new(HashMap::new()),
mqtt: mqtt,
metadata: Mutex::new(HashMap::new()),
}
}

Expand All @@ -175,7 +173,7 @@ impl Gateway {
}

fn sent_discovery(&self, name: &str) -> bool {
let l_discovered = self.discovered_sensor.lock().expect("Failed to lock discovery mutex");
let l_discovered: std::sync::MutexGuard<'_, HashMap<String, DiscoverySensor>> = self.discovered_sensor.lock().expect("Failed to lock discovery mutex");
l_discovered.contains_key(name)
}

Expand Down

0 comments on commit 0c18098

Please sign in to comment.