Based on yur suggestion I have wrote the following script (001_initialize_items.py
) Comments are more than welcome:
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Init items
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
from personal.metadata import Metadata
from core.log import logging, LOG_PREFIX
# Module logger
log = logging.getLogger(LOG_PREFIX + ".init_items")
log.info("Initialize items default value")
for item in ir.getItems():
'''
Iterate all items and initialize item which:
- Is NULL
- Has metatdata { default="default" [value=<value>] }
'''
if item.state == UnDefType.NULL:
m = Metadata(item.name, "default")
if m.is_namespace_exist() != None:
value = m.get_configuration_value_for_key("value")
if value != None:
events.sendCommand(item.name, value)
log.info("Completed")
Metadata class is based on this