Skip to content

Commit

Permalink
skip ble data without fields
Browse files Browse the repository at this point in the history
  • Loading branch information
wuan committed Dec 3, 2024
1 parent 88fdbac commit 6f442cf
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/data/openmqttgateway/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,11 @@ impl OpenMqttGatewayParser {
} else if !tags.contains_key("type") {
tags.insert(String::from("type"),String::from("UNKN"));
}
data = Some(Data { fields, tags });
if fields.len() > 0 {
data = Some(Data { fields, tags });
} else {
warn!("skip without fields {:?}", tags)
}
}
}
Ok(data)
Expand Down Expand Up @@ -160,6 +164,21 @@ mod tests {
Ok(())
}

#[test]
fn test_parse_missing_fields() -> Result<()> {
let mut parser = OpenMqttGatewayParser::new();
let message = Message::new(
"blegateway/D12331654712/BTtoMQTT/283146C17616",
"{\"id\":\"28:31:46:C1:76:16\"}",
QOS_1,
);
let result = parser.parse(&message)?;

assert!(result.is_none());

Ok(())
}

#[test]
fn test_parse_unknown_type() -> Result<()> {
let mut parser = OpenMqttGatewayParser::new();
Expand Down

0 comments on commit 6f442cf

Please sign in to comment.