!# devices.fn 1.4
!#
!# Dieses Homematic-Script gibt eine Liste aller Geraete/Kanaele als JSON String aus
!#
!# 3'2013-7'2013 hobbyquaker https://github.com/hobbyquaker
!#

string sDevId;
string sChnId;

Write('{');

boolean dFirst = true;

foreach (sDevId, root.Devices().EnumUsedIDs()) {

    object oDevice   = dom.GetObject(sDevId);
    boolean bDevReady = oDevice.ReadyConfig();
    string sDevInterfaceId = oDevice.Interface();
    string sDevInterface   = dom.GetObject(sDevInterfaceId).Name();
    
    if (bDevReady) {

        if (dFirst) {
          dFirst = false;
        } else {
          WriteLine(',');
        }

        Write('"' # oDevice.Address() # '":{"Name":"');
        WriteURL(oDevice.Name());
        Write('","Interface":"' # sDevInterface # '"}');
        
        foreach(sChnId, oDevice.Channels()) {
        	object oChannel = dom.GetObject(sChnId);
            WriteLine(',');
          	Write('"' # oChannel.Address() # '":{"Name":"');
        	WriteURL(oChannel.Name());
        	Write('","Interface":"' # sDevInterface # '"}');
        }
      
    }
}

Write('}');