-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathimport.php
193 lines (152 loc) · 5.79 KB
/
import.php
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
<?php
$exportFile = 'config/export.json';
ini_set('display_errors', 'on');
$beginn = microtime(true);
require_once(__DIR__.'/interface.php');
// Lösche vorhandene export.json
if(file_exists($exportFile))
{
unlink($exportFile);
}
touch($exportFile);
$export = array();
// Devices und Channels von der CCU laden
$devicesXml = simplexml_load_string(api_devicelist($ccu));
$statesXml = simplexml_load_string(api_statelist($ccu));
// Devices
foreach ($devicesXml->device as $device) {
$dummy = array();
foreach($device->attributes() as $attribute => $value) {
$dummy[strval($attribute)] = strval($value);
}
$statesXmlDevice = $statesXml->xpath('//device[@ise_id="' . strval($device['ise_id']) . '"]');
if(isset($statesXmlDevice[0])) {
foreach($statesXmlDevice[0]->attributes() as $attribute => $value) {
$dummy[strval($attribute)] = strval($value);
}
}
$export['devices'][] = $dummy;
}
// Virtuelle Fernbedienung
$device = $statesXml->xpath('//device[contains(@name, "HM-RCV-50")]');
if(count((array)$device) > 0) {
$device = $device[0];
$dummy = array(
'name' => strval($device['name']),
'address' => 'BidCos-RF',
'ise_id' => strval($device['ise_id']),
'interface' => 'BidCos-RF',
'device_type' => 'HM-RCV-50'
);
$export['devices'][] = $dummy;
}
// Channels
$channelDevicesXml = $devicesXml->xpath('//channel');
foreach ($channelDevicesXml as $channel) {
$device = $devicesXml->xpath('//device[@ise_id="' . strval($channel['parent_device']) . '"]');
$device = $device[0];
$dummy = array();
if(strval($device['interface']) <> 'CUxD') {
$dummy['component'] = strval($device['device_type']);
} else {
$dummy['component'] = substr(strval($device['address']), 0, 7);
}
$dummy['parent_device_type'] = strval($device['device_type']);
$dummy['parent_device_interface'] = strval($device['interface']);
foreach($channel->attributes() as $attribute => $value) {
$dummy[strval($attribute)] = strval($value);
}
$channelStatesXml = $statesXml->xpath('//channel[@ise_id="' . strval($channel['ise_id']) . '"]');
if(isset($channelStatesXml[0])) {
foreach($channelStatesXml[0]->attributes() as $attribute => $value) {
$dummy[strval($attribute)] = strval($value);
}
foreach($channelStatesXml[0]->datapoint as $datapoint) {
$dummy2 = array();
foreach($datapoint->attributes() as $attribute => $value) {
$dummy2[strval($attribute)] = strval($value);
}
$dummy['datapoints'][] = $dummy2;
}
}
$export['channels'][] = $dummy;
}
// Channels Virtuelle Fernbedienung
$device = $statesXml->xpath('//device[contains(@name, "HM-RCV-50")]');
if(count((array)$device) > 0) {
$device = $device[0];
$channelXml = $statesXml->xpath('//device[@ise_id="' . strval($device['ise_id']) . '"]/channel');
foreach ($channelXml as $channel) {
$dummy = array();
$dummy['component'] = 'HM-RCV-50';
$dummy['parent_device_type'] = 'HM-RCV-50';
$dummy['parent_device_interface'] = 'BidCos-RF';
foreach($channel->attributes() as $attribute => $value) {
$dummy[strval($attribute)] = strval($value);
}
foreach ($channel->datapoint as $datapoint) {
$dummy2 = array();
foreach($datapoint->attributes() as $attribute => $value) {
$dummy2[strval($attribute)] = strval($value);
}
$dummy['datapoints'][] = $dummy2;
}
$export['channels'][] = $dummy;
}
}
// Aufräumen
unset($devicelistCgi);
unset($devicesXml);
unset($statelistCgi);
unset($statesXml);
// Systemvariablen von der CCU laden
$sysvarsXml = simplexml_load_string(api_sysvarlist($ccu));
// Systemvariablen
foreach ($sysvarsXml->systemVariable as $sysvar) {
$dummy = array();
$dummy['component'] = 'SysVar';
foreach($sysvar->attributes() as $attribute => $value) {
$dummy[strval($attribute)] = strval($value);
}
$export['systemvariables'][] = $dummy;
}
// Aufräumen
unset($sysvarlistCgi);
unset($sysvarsXml);
// Programme von der CCU laden
$programsXml = simplexml_load_string(api_programlist($ccu));
// Programme
foreach ($programsXml->program as $program) {
$dummy = array();
$dummy['component'] = 'Program';
foreach($program->attributes() as $attribute => $value) {
// Unstimmigkeit in der XML-API korrigieren
if(strval($attribute) == 'id') {
$dummy['ise_id'] = strval($value);
} else {
$dummy[strval($attribute)] = strval($value);
}
}
$export['programs'][] = $dummy;
}
// Aufräumen
unset($programlistCgi);
unset($programsXml);
// Umlaute ersetzen
$json = str_replace(
array('\u00c4', '\u00e4', '\u00d6', '\u00f6', '\u00dc', '\u00fc', '\u00df'),
array('Ä', 'ä', 'Ö', 'ö', 'Ü', 'ü', 'ß'),
json_encode($export)
);
file_put_contents($exportFile, $json);
if(isset($_GET['debug']))
{
$dauer = microtime(true) - $beginn;
echo "Verarbeitung des Skripts: ".$dauer." Sek.";
exit();
}
else
{
header('Location: ./index.php');
}
?>