openhab / openhab-js

openHAB JavaScript Library for JavaScript Scripting Automation
https://www.openhab.org/addons/automation/jsscripting/
Eclipse Public License 2.0
38 stars 31 forks source link

[items] removeItem() fails with error message #120

Closed JacekKac closed 2 years ago

JacekKac commented 2 years ago

if i put .itemReplace in a loop to create 50 items it works ok. Then i do :

var cleanup_items = true; 
if (cleanup_items) {

  var item_list = items.getItemsByTag('_DYNAMIC_'); 
  item_list.forEach((item) => {
      items.removeItem(item.name)
      console.log('Usuwam:' + item.name)
  })
}

and it does remove some items but few of them, and gives

Error during evaluation of script 'file:/etc/openhab/automation/js/rulesCreator.js': org.openhab.core.items.ItemNotFoundException: Item 'gRoom1' could not be found in the item registry...

item gRoom1 was properly deleted. When i run the script again it works for a few items, then it give the same error for another item. Ofcourse the items are created properly and exist in items registry, and they are included in items.getItemsByTag.

when i run the script many times it sucesfully remove all of them.

florian-h05 commented 2 years ago

Hello @JacekKac,

I did some further testing and was able to fix the issue in #122.