diff --git a/Cargo.lock b/Cargo.lock index 9455765..8f0fed7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1533,7 +1533,7 @@ dependencies = [ [[package]] name = "mqtt-gateway" -version = "0.4.2" +version = "0.4.3" dependencies = [ "anyhow", "async-std", diff --git a/Cargo.toml b/Cargo.toml index 3064763..0ea9df0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "mqtt-gateway" -version = "0.4.2" +version = "0.4.3" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/src/data/openmqttgateway/mod.rs b/src/data/openmqttgateway/mod.rs index 50cdb71..2864ed4 100644 --- a/src/data/openmqttgateway/mod.rs +++ b/src/data/openmqttgateway/mod.rs @@ -103,7 +103,7 @@ impl OpenMqttGatewayParser { } } - if fields.contains_key("rssi") && fields.len() > 1 && tags.len() > base_tag_count { + if fields.contains_key("rssi") && fields.len() == 1 && tags.len() == base_tag_count { tags.insert(String::from("type"),String::from("NONE")); } else if !tags.contains_key("type") { tags.insert(String::from("type"),String::from("UNKN")); @@ -141,7 +141,7 @@ mod tests { } #[test] - fn test_parse_ignored() -> Result<()> { + fn test_parse_none_type() -> Result<()> { let mut parser = OpenMqttGatewayParser::new(); let message = Message::new( "blegateway/D12331654712/BTtoMQTT/283146C17616", @@ -150,7 +150,32 @@ mod tests { ); let result = parser.parse(&message)?; - assert!(result.is_none()); + assert!(result.is_some()); + let data = result.unwrap(); + let tags = data.tags; + assert_eq!(tags.get("device").unwrap(), "283146C17616"); + assert_eq!(tags.get("gateway").unwrap(), "D12331654712"); + assert_eq!(tags.get("type").unwrap(), "NONE"); + + Ok(()) + } + + #[test] + fn test_parse_unknown_type() -> Result<()> { + let mut parser = OpenMqttGatewayParser::new(); + let message = Message::new( + "blegateway/D12331654712/BTtoMQTT/283146C17616", + "{\"id\":\"28:31:46:C1:76:16\",\"rssi\":-92,\"name\":\"foo\"}", + QOS_1, + ); + let result = parser.parse(&message)?; + + assert!(result.is_some()); + let data = result.unwrap(); + let tags = data.tags; + assert_eq!(tags.get("device").unwrap(), "283146C17616"); + assert_eq!(tags.get("gateway").unwrap(), "D12331654712"); + assert_eq!(tags.get("type").unwrap(), "UNKN"); Ok(()) }