Fix examples remove uniqueness

This commit is contained in:
Theo Arends 2025-09-24 17:04:25 +02:00
parent 0d7c9439c0
commit c901fa0832
2 changed files with 12 additions and 7 deletions

View File

@ -63,11 +63,13 @@ class mqttdata_cls
var ipaddress = config['ip'] var ipaddress = config['ip']
var devicename = config['dn'] var devicename = config['dn']
var line = format("%s,%s,%s,%s", topic, hostname, ipaddress, devicename) var line = format("%s,%s,%s,%s", topic, hostname, ipaddress, devicename)
# tasmota.log(format("STD: 111 Size %03d, Topic '%s', Line '%s'", self.list_config.size(), topic, line), 3)
if self.list_config.size() if self.list_config.size()
var list_index = 0 var list_index = 0
var list_size = size(self.list_config) var list_size = size(self.list_config)
var topic_comma = format("%s,", topic) # Add find delimiter
while list_index < list_size # Use while loop as counter is decremented while list_index < list_size # Use while loop as counter is decremented
if 0 == string.find(self.list_config[list_index], topic) if 0 == string.find(self.list_config[list_index], topic_comma)
self.list_config.remove(list_index) # Remove current config self.list_config.remove(list_index) # Remove current config
list_size -= 1 # Continue for duplicates list_size -= 1 # Continue for duplicates
end end
@ -75,7 +77,7 @@ class mqttdata_cls
end end
end end
self.list_config.push(line) # Add (re-discovered) config as last entry self.list_config.push(line) # Add (re-discovered) config as last entry
# tasmota.log(format("STD: Size %d, Line '%s'", self.list_config.size(), line), 3) # tasmota.log(format("STD: 222 Size %03d, Topic '%s', Line '%s'", self.list_config.size(), topic, line), 3)
end end
end end
@ -93,6 +95,7 @@ class mqttdata_cls
break break
end end
end end
# tasmota.log(format("STD: Topic '%s', Index %d, Size %d, Line '%s'", topic, topic_index, self.list_config.size(), self.list_config[topic_index]), 3)
if topic_index == -1 return true end # Assume topic is in retained discovery list if topic_index == -1 return true end # Assume topic is in retained discovery list
var state = json.load(data) var state = json.load(data)
@ -114,8 +117,9 @@ class mqttdata_cls
if self.list_buffer.size() if self.list_buffer.size()
var list_index = 0 var list_index = 0
var list_size = size(self.list_buffer) var list_size = size(self.list_buffer)
var topic_comma = format("%s,", topic) # Add find delimiter
while list_index < list_size # Use while loop as counter is decremented while list_index < list_size # Use while loop as counter is decremented
if 0 == string.find(self.list_buffer[list_index], topic) if 0 == string.find(self.list_buffer[list_index], topic_comma)
self.list_buffer.remove(list_index) # Remove current state self.list_buffer.remove(list_index) # Remove current state
list_size -= 1 # Continue for duplicates list_size -= 1 # Continue for duplicates
end end

View File

@ -69,8 +69,9 @@ class mqttdata_cls
if self.list_buffer.size() if self.list_buffer.size()
var list_index = 0 var list_index = 0
var list_size = size(self.list_buffer) var list_size = size(self.list_buffer)
var topic_comma = format("%s,", topic) # Add find delimiter
while list_index < list_size # Use while loop as counter is decremented while list_index < list_size # Use while loop as counter is decremented
if 0 == string.find(self.list_buffer[list_index], topic) if 0 == string.find(self.list_buffer[list_index], topic_comma)
self.list_buffer.remove(list_index) # Remove current state self.list_buffer.remove(list_index) # Remove current state
list_size -= 1 # Continue for duplicates list_size -= 1 # Continue for duplicates
end end
@ -150,14 +151,14 @@ class mqttdata_cls
msg += "<tr>" msg += "<tr>"
if ipaddress if ipaddress
msg += format("<td><a target=_blank href='http://%s.'>%s</a></td><td><a target=_blank href='http://%s'>%s</a></td>", msg += format("<td><a target=_blank href='http://%s.'>%s&nbsp</a></td><td><a target=_blank href='http://%s'>%s&nbsp</a></td>",
topic, topic, ipaddress, ipaddress) topic, topic, ipaddress, ipaddress)
else else
if self.line_topic_is_hostname if self.line_topic_is_hostname
msg += format("<td><a target=_blank href='http://%s.'>%s</a></td><td>&nbsp</td>", msg += format("<td><a target=_blank href='http://%s.'>%s&nbsp</a></td><td>&nbsp</td>",
topic, topic) topic, topic)
else else
msg += format("<td>%s</td><td>&nbsp</td>", topic) msg += format("<td>%s&nbsp</td><td>&nbsp</td>", topic)
end end
end end