Code: Alles auswählen
!- letzen Kontakt zu einem Device bestimmen, bytelander - 04.05.2020
string device_str;
object device_obj;
object interface_obj;
string channel_str;
object channel_obj;
integer timeLastAction;
string channel_txt;
string timestamp_txt;
integer now = system.Date("%F %X").ToTime().ToInteger();
foreach(device_str, dom.GetObject(ID_DEVICES).EnumUsedIDs()){ !- durch alle Device
device_obj = dom.GetObject(device_str); !- Device-Object
interface_obj = dom.GetObject(device_obj.Interface());
if ((interface_obj.Name()=="HmIP-RF") && (device_obj.Name()!="HmIP-RCV-50")){ !- alle Device am Interface HmIP außer Virtuelle Fernbedienung der CCU3
timeLastAction = -1; !- Vergleichswert setzen
foreach(channel_str, device_obj.Channels().EnumUsedIDs()){ !- durch alle Cannel
channel_obj = dom.GetObject(channel_str); !- Channel-Object
if (channel_obj.LastDPActionTimeSeconds()>timeLastAction){
timeLastAction = channel_obj.LastDPActionTimeSeconds();
channel_txt = device_obj.Name() + ":" + channel_obj.ChnNumber().ToString() + "#" + timeLastAction.ToString();
}
}
timestamp_txt = timestamp_txt + channel_txt + "\t";
} !- ENDE IF Interface-Type
} !- ENDE FOREACH alle Device
timestamp_txt = timestamp_txt.Trim(); !- letztes TAB abschneiden
!- WriteLine(timestamp_txt.Replace("\t","\n"));
!- Sammmlung beendet, jetzt sortieren
string list = timestamp_txt;
string index;
integer comp;
integer count;
integer greatest_value;
string new_list;
string sort_list;
while (list.Length()!=0){
comp = -1;
count = 0;
new_list="";
foreach (index, list){
if(index.StrValueByIndex("#",1).ToInteger()>comp){
comp=index.StrValueByIndex("#",1).ToInteger();
greatest_value = count;
}
count = count + 1;
}
count = 0;
foreach (index, list){
if(count!=greatest_value){
new_list = new_list # index # "\t";
}
else{
sort_list = sort_list # index # "\t";
}
count = count + 1;
}
list = new_list.Trim();
}
sort_list = sort_list.Trim(); !- letztes TAB abschneiden
!- WriteLine(sort_list.Replace("\t","\n"));
!- Output zusammensetzen
string output_txt;
string output_time;
var hour_txt;
var minute_txt;
var second_txt;
foreach (index, sort_list){
second_txt = now-index.StrValueByIndex("#",1).ToInteger();
hour_txt = (second_txt/3600).Floor().ToInteger();
minute_txt = (second_txt.Mod(3600)/60).Floor().ToInteger();
second_txt = second_txt.Mod(60).Floor().ToInteger();
hour_txt = "0" + hour_txt.ToString();
hour_txt = hour_txt.Substr(hour_txt.Length()-2,2);
minute_txt = "0" + minute_txt.ToString();
minute_txt = minute_txt.Substr(minute_txt.Length()-2,2);
second_txt = "0" + second_txt.ToString();
second_txt = second_txt.Substr(second_txt.Length()-2,2);
if (index.StrValueByIndex("#",1).ToInteger()==0){ !- Sonderfall kein gültiger Status
output_txt = index.StrValueByIndex("#",0) + ": " + "Status fehlt\n" + output_txt;
}
else {
output_txt = index.StrValueByIndex("#",0) + ": " + hour_txt + ":" + minute_txt + ":" + second_txt + "\n" + output_txt;
}
}
output_txt = output_txt.Trim();
output_txt = output_txt + "\n\n" + "letzte Aktualisierung: " +now.ToTime().Format("%d.%m.%Y %H:%M:%S Uhr");
!- WriteLine(output_txt);
dom.GetObject("letzter.Kontakt").State(output_txt);