Skip to content

Commit

Permalink
Fix discovery message topic creation #50
Browse files Browse the repository at this point in the history
  • Loading branch information
fsaris committed Jan 7, 2024
1 parent c93099a commit 7e13452
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion components/awox_mesh/mesh_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,14 @@ static int convert_value_to_available_range(int value, int min_from, int max_fro
return std::max(new_value, min_to);
}

static std::string str_sanitize_macadres(const std::string &str) {
std::string out;
std::copy_if(str.begin(), str.end(), std::back_inserter(out), [](const char &c) {
return (c >= '0' && c <= '9') || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z');
});
return out;
}

void MeshDevice::on_shutdown() {
// todo assure this message is published
for (int i = 0; i < this->devices_.size(); i++) {
Expand Down Expand Up @@ -451,7 +459,7 @@ std::string MeshDevice::device_state_as_string(Device *device) {

std::string MeshDevice::get_discovery_topic_(const MQTTDiscoveryInfo &discovery_info, Device *device) const {
return discovery_info.prefix + "/" + device->device_info->get_component_type() + "/awox-" +
str_sanitize(device->mac) + "/config";
str_sanitize_macadres(device->mac) + "/config";
}

std::string MeshDevice::get_mqtt_topic_for_(Device *device, const std::string &suffix) const {
Expand Down

0 comments on commit 7e13452

Please sign in to comment.