Improved the mechanism for extracting the presence device name

This commit is contained in:
Dreaded_X 2023-01-06 05:31:47 +01:00
parent 47afda8dee
commit 9fd3890c45
Signed by: Dreaded_X
GPG Key ID: 76BDEC4E165D8AD9

View File

@ -44,8 +44,8 @@ impl OnMqtt for Presence {
return;
}
// @TODO More robust mechanism for splitting
let device_name = message.topic.rsplit_once("/").unwrap().1;
let offset = self.mqtt.topic.find('+').or(self.mqtt.topic.find('#')).unwrap();
let device_name = &message.topic[offset..];
if message.payload.len() == 0 {
// Remove the device from the map