Logic Machine Forum
Comparing object names with Json list - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: Comparing object names with Json list (/showthread.php?tid=3281)



Comparing object names with Json list - Kai-Roger - 02.04.2021

Hi.

Is it possible to compare the names of the objets in LM with a newer Json file that i have exported and converted from ETS/KNX? And somehow get a print of every objects with wrong names in LM?


RE: Comparing object names with Json list - admin - 06.04.2021

Put your JSON data into the script and run once. It will log all objects that are present in JSON but not in LM and objects that have mismatching names.
Code:
require('json')

data = [[
PUT_JSON_DATA_HERE
]]

objects = json.decode(data).objects
for id, obj in pairs(objects) do
  id = tonumber(id)
  curr = grp.find(id)
  addr = buslib.decodega(id)

  if curr then
    if obj.name and curr.name ~= obj.name then
      log('name mismatch ' .. addr, curr.name, obj.name)
    end
  else
    log('missing object ' .. addr)
  end
end



RE: Comparing object names with Json list - Kai-Roger - 18.04.2021

(06.04.2021, 06:23)admin Wrote: Put your JSON data into the script and run once. It will log all objects that are present in JSON but not in LM and objects that have mismatching names.
Code:
require('json')

data = [[
PUT_JSON_DATA_HERE
]]

objects = json.decode(data).objects
for id, obj in pairs(objects) do
  id = tonumber(id)
  curr = grp.find(id)
  addr = buslib.decodega(id)

  if curr then
    if obj.name and curr.name ~= obj.name then
      log('name mismatch ' .. addr, curr.name, obj.name)
    end
  else
    log('missing object ' .. addr)
  end
end

Thank you


RE: Comparing object names with Json list - Tokatubs - 23.04.2021

Worked like a charm. This makes updating group text really easy. 

But is there a possbility to make the log not show unassigned Group addresses, like this

* string: missing object 25/2/165

Want only the * string: name mismatch 8/3/1

Thanks in advance Smile


RE: Comparing object names with Json list - admin - 23.04.2021

Remove the relevant log call:
Code:
require('json')

data = [[
PUT_JSON_DATA_HERE
]]

objects = json.decode(data).objects
for id, obj in pairs(objects) do
  id = tonumber(id)
  curr = grp.find(id)
  addr = buslib.decodega(id)

  if curr and obj.name and curr.name ~= obj.name then
    log('name mismatch ' .. addr, curr.name, obj.name)
  end
end