-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathInventory.hms
105 lines (85 loc) · 4.33 KB
/
Inventory.hms
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
! https://github.com/jollyjinx/homematic/blob/master/Inventory.hms
!
! Run the script to get a nice inventory
!
!----- User setable variables
string language = "de"; ! either "en" for english or "de" for german;
boolean debug = false;
!------ Execution
!
! generate the device list
!
integer devicecounter = 0;
integer channelcount = 0;
integer devicetypecount = 0;
string devicetypes = ",";
string devicesconcat;
string deviceid;
foreach(deviceid, dom.GetObject(ID_DEVICES).EnumUsedIDs())
{
var device = dom.GetObject(deviceid); if(debug){WriteLine("Device:"#device#" (id:"#deviceid#")");}
string devicetype = device.HssType(); if(debug){WriteLine("Devicetype:"#devicetype);}
devicecounter = devicecounter + 1;
devicesconcat = devicesconcat # "\t" # devicetype;
if( -1 == devicetypes.Find(","# devicetype # ",") )
{
devicetypes = devicetypes # devicetype # ",";
devicetypecount = devicetypecount + 1;
}
string channelid;
foreach(channelid,device.Channels().EnumUsedIDs())
{ if(debug){var channel = dom.GetObject(channelid);WriteLine("\t Channel:"#channel#" (id:"#channelid#")");}
channelcount = channelcount + 1;
}
} if(debug){WriteLine(channelcount # " channels " # devicecounter # " devices " # devicetypecount # " devicetypes");}
if( "de" == language )
{
WriteLine(channelcount # " Kanaele in " # devicecounter # " Geraeten, " # devicetypecount # " Geraetetypen:");
}
else
{
WriteLine(channelcount # " channels in " # devicecounter # " devices, " # devicetypecount # " devicetypes:");
}
string typenames;
!. string input = "/bin/sh -c 'cat /www/webui/js/lang/"#language#"/translate.lang.deviceDescription.js|sed -r \"s/%DF/ss/g;s/%FC/ue/g;s/%E4/ae/g;s/%F6/oe/g;s/(^\s+|,\s*\$)//g;s/\\"\\s*:\\s*\\"/\\":\\"/g;s/\\"//g;s/^(HM\-RCV\-50:).*\$/\1CCU2 System/;\"|awk -F : -v ORS=, \"{if(length(\$1)>3 && length(\$2)>3) print \$1\\",\\"\$2;}\"|sed \"s/,\$//;\" ";
!. string stderr;
!. system.Exec(input, &typenames,&stderr); if(debug){WriteLine("Type to Name array:" #typenames)};
string outputstring;
string devicetype;
foreach(devicetype,devicetypes.Split(","))
{
if( devicetype.Length() )
{ if(debug){WriteLine("Device:"#devicetype);}
devicecounter = 0;
string counttype;
foreach(counttype,devicesconcat)
{
if( counttype.Length() && (counttype == devicetype) )
{
devicecounter = devicecounter + 1;
}
}
string originaldevicetype = devicetype;
boolean foundnicename=false;
while( !foundnicename && devicetype.Length()>6 )
{
string nicename;
integer devicenameposition = typenames.Find(devicetype#","); if(debug){WriteLine("Searching nicename for:"#devicetype);}
if( -1 != devicenameposition )
{
integer length = devicetype.Length();
string remainingstring = typenames.Substr(devicenameposition,length-devicenameposition);
nicename = "(" # remainingstring.StrValueByIndex(",",1) # ")";
foundnicename = true;
}
else
{
devicetype = devicetype.Substr(0,devicetype.Length()-1);
}
}
outputstring = outputstring # devicecounter # "x " # originaldevicetype # nicename # ", ";
}
}
WriteLine(outputstring.Substr(0, outputstring.Length() - 2));
WriteLine("--------------------------------------------");
WriteLine("https://github.com/jollyjinx/homematic/blob/master/Inventory.hms");