// Liest die ioBroker Adapter aus und legt verschiedenen State's an.
schedule('*/10 * * * * *', function (obj) {
//on({id:"system.adapter.admin.0.uptime",change:'any'}, function (obj) {
createState('0_userdata.0.adapter_infos.Anzahl', 0, { name: 'Anzahl', desc: 'Anzahl der Adapter', type: 'number', unit: '', min: '0', max: '255', role: '',read: true, write: true });
createState('0_userdata.0.adapter_infos.AdapterNummer', 0, { name: 'Adapter zum schalten', desc: 'Adapter zum schalten', type: 'number', unit: '', min: '0', max: '255', role: '',read: true, write: true });
//var counterAlt = getState("javascript.0.Adapter.Anzahl").val;
//Variablen zurücksetzen
var counter =0;
var on = 0
var manuell=0
var cacheSelector = $('[id=system.adapter.*.alive]');
cacheSelector.each(function(id, i) {
//Instanzen ausklammer
var check1 = id.indexOf('system.adapter.coronavirus-statistics.0.alive');
var check2 = id.indexOf('system.adapter.daswetter.0.alive');
var check3 = id.indexOf('system.adapter.dwd.0.alive');
var check4 = id.indexOf('system.adapter.ical.0.alive');
var check5 = id.indexOf('system.adapter.ical.1.alive');
var check6 = id.indexOf('system.adapter.ical.2.alive');
var check7 = id.indexOf('system.adapter.feiertage.0.alive');
var check8 = id.indexOf('system.adapter.kodi.0.alive');
var check9 = id.indexOf('system.adapter.snmp.1.alive');
var check10 = id.indexOf('system.adapter.synology.1.alive');
var check11 = id.indexOf('system.adapter.yamaha.0.alive');
var check12 = id.indexOf('system.adapter.vis.0.alive');
var check = check1 + check2 + check3 + check4 + check5 + check6 + check7 + check8 + check9 + check10 + check11 + check12;
//Abfrage nur ausführen, wenn Instanz nicht ausgeklammert ist
if(check == -12){
var devicename = getObject(id).common.name;
//console.log(devicename);
var devicenameName=devicename;
var instanzname=getObject(id).common.name;
var test = devicenameName;
var devicename_array = devicenameName.split(' ');
devicenameName = devicename_array[0];
counter = counter+1;
var strStatePath = "system.adapter." + devicenameName + ".alive";
//Uptime
var uptime = getState("system.adapter." + devicenameName + ".uptime").val;
var tage = Math.floor(uptime / (24*3600));
var stunden = Math.floor((uptime % (24*3600))/3600);
var minuten = Math.floor((uptime % (3600))/60);
if (stunden < 10) {stunden = "0"+stunden};
if (minuten < 10) {minuten = "0"+minuten};
if (tage == 1) {uptime = tage.toString()+" Tag, "+stunden.toString()+" Std, "+minuten.toString()+" Min ";};
if (tage != 1) {uptime = tage.toString()+" Tage, "+stunden.toString()+" Std, "+minuten.toString()+" Min ";}
//Arbeitsspeicher etc.
//var total = getState("system.adapter." + devicenameName + ".memHeapTotal").val;
//var used = getState("system.adapter." + devicenameName + ".memHeapUsed").val;
//var rss = getState("system.adapter." + devicenameName + ".memRss").val;
//Connection Status
var connect = getState("system.adapter." + devicenameName + ".alive").val;
if(connect == false){var con = 0;}
else {
var con = 1;
var strStatePath = devicenameName + ".info.connection";
if (isState(strStatePath, true)) {
var connectS = getState(devicenameName + ".info.connection").val;
if (connectS == false) {
con = 2;
}
}
}
if(con==1) {on = on + 1}
devicename="0_userdata.0.adapter_infos.Adapter"+counter.toString()+".KompletterNameAdapter";
createState(devicename, 'empty', { name: 'Kompletter Name des Adapters', desc: '', type: 'string', role: '',read: true, write: true });
setStateDelayed(devicename, devicenameName, 800);
var contentstring = devicenameName;
var suchstring = /(ical)/g;
var suchergebnis = suchstring.test( contentstring );
if (suchergebnis != true) {
var devicename_array = devicenameName.split('.');
devicenameName = devicename_array[0];
}
if (devicenameName == "daswetter") {
var bild = "/" + devicenameName + ".admin/" + devicenameName + "com.png";
} else if (suchergebnis != false) {
var devicename_array = devicenameName.split('.');
var icalName = devicename_array[0];
var bild = "/" + icalName + ".admin/" + icalName + ".png";
} else {
var bild = "/" + devicenameName + ".admin/" + devicenameName + ".png";
}
//////////////////////////
// Icon-Pfad definieren //
//////////////////////////
//Alexa2
if (devicenameName == 'alexa2') {var bild = "/" + devicenameName + ".admin/" + "alexa.png";}
//FritzDECT
if (devicenameName == 'fritzdect') {var bild = "/" + devicenameName + ".admin/" + "fritzdect_logo.png";}
//FullyBrowser
if (devicenameName == 'fullybrowser') {var bild = "/" + devicenameName + ".admin/" + "fully.png";}
//HM-Rega
if (devicenameName == 'hm-rega') {var bild = "/vis.0/VIS_v3/Meine_Icons/Adapter_Icons/homematic.png";}
//HomeMatic
if (instanzname == 'hm-rpc.0 alive') {var bild = "/vis.0/VIS_v3/Meine_Icons/Adapter_Icons/homematic.png";}
//HomeMatic-IP
if (instanzname == 'hm-rpc.1 alive') {var bild = "/vis.0/VIS_v3/Meine_Icons/Adapter_Icons/homematic_ip.jpg";}
//Homepilot
if (instanzname == 'homepilot20.0 alive') {var bild = "/vis.0/VIS_v3/Meine_Icons/Adapter_Icons/homepilot.png";}
//UPNP
if (devicenameName == 'upnp') {var bild = "/" + devicenameName + ".admin/" + "upnp-discovery.png";}
//Pushover.1
if (instanzname == 'pushover.1 alive') {var bild = "/mihome-vacuum.admin/mihome-vacuum.png";}
//Pushover.2
if (instanzname == 'pushover.2 alive') {var bild = "/daswetter.admin/daswettercom.png";}
///////////////////////
//AdapterName anpassen
////////////////////////
//Corona-Statistics
if (instanzname == 'coronavirus-statistics.0 alive') {devicenameName='Corona'; manuell=1}
//DasWetter
if (instanzname == 'daswetter.0 alive') {devicenameName='DasWetter'; manuell=1}
//DWD
if (instanzname == 'dwd.0 alive') {devicenameName='DWD'; manuell=1}
//Fullybrowser
if (instanzname == 'fullybrowser.0 alive') {devicenameName='FullyKiosk'; manuell=1}
//HM-REGA
if (instanzname == 'hm-rega.0 alive') {devicenameName='HM-Rega'; manuell=1}
//HM-RPC.0
if (instanzname == 'hm-rpc.0 alive') {devicenameName='HomeMatic'; manuell=1}
//HM-RPC.1
if (instanzname == 'hm-rpc.1 alive') {devicenameName='HM-IP'; manuell=1}
//Homepilot
if (instanzname == 'homepilot20.0 alive') {devicenameName='Homepilot'; manuell=1}
//Linux-Control
if (instanzname == 'linux-control.0 alive') {devicenameName='Linux-Ctr.'; manuell=1}
//MiHome-Vacuum -> NoNo
if (instanzname == 'mihome-vacuum.0 alive') {devicenameName='Nono'; manuell=1}
//MiHome-Vacuum -> Dusty
if (instanzname == 'mihome-vacuum.1 alive') {devicenameName='Dusty'; manuell=1}
//Pushover
if (instanzname == 'pushover.0 alive') {devicenameName='Pushover.0'; manuell=1}
if (instanzname == 'pushover.1 alive') {devicenameName='Pushover.1'; manuell=1}
if (instanzname == 'pushover.2 alive') {devicenameName='Pushover.2'; manuell=1}
//Simple-API
if (instanzname == 'simple-api.0 alive') {devicenameName='Simple-API'; manuell=1}
//SNMP.0
if (instanzname == 'snmp.0 alive') {devicenameName='QNAP-B'; manuell=1}
//SNMP.1
if (instanzname == 'snmp.1 alive') {devicenameName='QNAP-Archiv'; manuell=1}
//SNMP.2
if (instanzname == 'snmp.2 alive') {devicenameName='Brother'; manuell=1}
//Spotify
if (instanzname == 'spotify-premium.0 alive') {devicenameName='Spotify'; manuell=1}
// Synology
if (instanzname == 'synology.0 alive') {devicenameName='XPEnology'; manuell=1}
//Tankerkoenig
if (instanzname == 'tankerkoenig.0 alive') {devicenameName='Tankerk.'; manuell=1}
//Tashscheduler
if (instanzname == 'trashschedule.0 alive') {devicenameName='Trashsched.'; manuell=1}
//TR-064.0
if (instanzname == 'tr-064.0 alive') {devicenameName='TR-064.0'; manuell=1}
//TR-064.1
if (instanzname == 'tr-064.1 alive') {devicenameName='TR-064.1'; manuell=1}
//XPEnology
if (instanzname == 'synology.1 alive') {devicenameName='XPEnology'; manuell=1}
//Instanz-Namen setzen
if(manuell!=1) {devicenameName = devicenameName.substring(0, 1).toUpperCase() + devicenameName.substring(1).toLowerCase();}
//devicenameName = devicenameName.substring(0, 1).toUpperCase() + devicenameName.substring(1).toLowerCase();
devicename="0_userdata.0.adapter_infos.Adapter"+counter.toString()+".NameInstanz";
createState(devicename, 'empty', { name: 'Name des Geräts', desc: '', type: 'string', role: '',read: true, write: true });
setStateDelayed(devicename, devicenameName, 800);
//Bild Pfad setzen
devicename="0_userdata.0.adapter_infos.Adapter"+counter.toString()+".Bild";
createState(devicename, 'empty', { name: 'Speicherort Bild', desc: '', type: 'string', role: '',read: true, write: true });
setStateDelayed(devicename, bild, 800);
//Uptime setzen
devicename="0_userdata.0.adapter_infos.Adapter"+counter.toString()+".Uptime";
createState(devicename, 'empty', { name: 'Uptime', desc: '', type: 'string', role: '',read: true, write: true });
setStateDelayed(devicename, uptime, 800);
//MemUsed setzen
//devicename="0_userdata.0.adapter_infos.Adapter"+counter.toString()+".MemUsed";
//createState(devicename, 0, { name: 'Link MemUsed', desc: '', type: 'number', role: '',read: true, write: true });
//setStateDelayed(devicename, used, 800);
//MemToal setzen
//devicename="0_userdata.0.adapter_infos.Adapter"+counter.toString()+".MemTotal";
//createState(devicename, 0, { name: 'Link MemTotal', desc: '', type: 'number', role: '',read: true, write: true });
//setStateDelayed(devicename, total, 800);
//MemRSS setzen
//devicename="0_userdata.0.adapter_infos.Adapter"+counter.toString()+".MemRSS";
//createState(devicename, 0, { name: 'Link MemRSS', desc: '', type: 'number', role: '',read: true, write: true });
//setStateDelayed(devicename, rss, 800);
//Connected setzen
devicename="0_userdata.0.adapter_infos.Adapter"+counter.toString()+".Connected";
createState(devicename, 0, { name: 'Status Adapter', desc: '', type: 'number', role: '',read: true, write: true });
setStateDelayed(devicename, con, 800);
//Wert zurücksetzen
var manuell=0
};
});
//Adaptet Icon Übersicht
visstatus="0_userdata.0.vis-status.alle_adapter_gestartet";
if(on == counter){setState(visstatus, true);}
//if(on == counter -1){setState(visstatus, true);}
else{setState(visstatus, false);}
setStateDelayed('0_userdata.0.adapter_infos.Anzahl', counter, 800);
function isState(strStatePath, strict) {
let mSelector;
if (strict) {
mSelector = $('state[id=' + strStatePath + '$]');
} else {
mSelector = $('state[id=' + strStatePath + ']');
}
if (mSelector.length > 0) {
return true;
} else {
return false;
}
}
});
on({id:"0_userdata.0.adapter_infos.AdapterNummer", change: 'any'}, function (dpobj) {
if (getState("javascript.0.Adapter.AdapterNummer").val != 0) {
const instanz = "javascript." + instance;
var adapterNummer = getState(instanz + ".Adapter.AdapterNummer").val;
var adapter = getState(instanz + ".Adapter.Adapter" + adapterNummer + ".KompletterNameAdapter").val; // Name und Instanz des Adapters
var idAdapter = "system.adapter." + adapter;
var obj = getObject(idAdapter);
if (dpobj.state.val == false) {
obj.common.enabled = true; // Adapter einschalten
} else if (dpobj.state.val == true) {
obj.common.enabled = false; // Adapter ausschalten
}
setObject(idAdapter, obj);
setStateDelayed('javascript.0.Adapter.AdapterNummer', 0, 800);
}
});