-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin_orig/main'
- Loading branch information
Showing
10 changed files
with
117 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
use std::process::Command; | ||
fn main() { | ||
// runs git describe --always --dirty | ||
if let Ok(output) = Command::new("git") | ||
.args(["describe", "--always", "--dirty"]) | ||
.output() | ||
{ | ||
let git_hash = String::from_utf8(output.stdout).unwrap(); | ||
println!("cargo:rustc-env=GIT_HASH={git_hash}"); | ||
} else { | ||
println!("cargo:rustc-env=GIT_HASH=UNKNOWN"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,4 +8,4 @@ pub mod simple_mqtt; | |
|
||
// internal interfaces | ||
mod home_assistant_config; | ||
mod protos; | ||
mod protos; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,5 @@ | ||
use std::io::Write; | ||
|
||
use chrono::Local; | ||
use env_logger::Builder; | ||
use log::LevelFilter; | ||
use env_logger::{Builder, Env}; | ||
|
||
pub fn init_logger() { | ||
Builder::new() | ||
.format(|buf, record| { | ||
writeln!( | ||
buf, | ||
"{} [{}] - {}", | ||
Local::now().format("%Y-%m-%dT%H:%M:%S"), | ||
record.level(), | ||
record.args() | ||
) | ||
}) | ||
.filter(None, LevelFilter::Info) | ||
.init(); | ||
Builder::from_env(Env::default().default_filter_or("info")).init(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
use hms2mqtt::{mqtt_config::MqttConfig, mqtt_wrapper::MqttWrapper}; | ||
|
||
struct MqttTester { | ||
published_values: Vec<(String, Vec<u8>)>, | ||
} | ||
|
||
impl MqttTester { | ||
pub fn len(&self) -> usize { | ||
self.published_values.len() | ||
} | ||
|
||
#[must_use] | ||
pub fn is_empty(&self) -> bool { | ||
self.len() == 0 | ||
} | ||
} | ||
|
||
impl MqttWrapper for MqttTester { | ||
fn subscribe(&mut self, _topic: &str, _qos: hms2mqtt::mqtt_wrapper::QoS) -> anyhow::Result<()> { | ||
Ok(()) | ||
} | ||
|
||
fn publish<S, V>( | ||
&mut self, | ||
topic: S, | ||
_qos: hms2mqtt::mqtt_wrapper::QoS, | ||
_retain: bool, | ||
payload: V, | ||
) -> anyhow::Result<()> | ||
where | ||
S: Into<String>, | ||
V: Into<Vec<u8>>, | ||
{ | ||
self.published_values.push((topic.into(), payload.into())); | ||
Ok(()) | ||
} | ||
|
||
fn new(_config: &hms2mqtt::mqtt_config::MqttConfig, _suffix: &str) -> Self { | ||
Self { | ||
published_values: Vec::new(), | ||
} | ||
} | ||
} | ||
|
||
#[test] | ||
fn publish_one_message() { | ||
let mut mqtt = MqttTester::new( | ||
&MqttConfig { | ||
host: "frob".to_owned(), | ||
port: Some(1234), | ||
username: None, | ||
password: None, | ||
}, | ||
"-test", | ||
); | ||
let result = mqtt.publish( | ||
"foo", | ||
hms2mqtt::mqtt_wrapper::QoS::AtMostOnce, | ||
true, | ||
"Hooray".to_string(), | ||
); | ||
assert!(result.is_ok()); | ||
assert!(!mqtt.is_empty()); | ||
assert_eq!(mqtt.len(), 1); | ||
} |