-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathmodule.php
More file actions
389 lines (363 loc) · 13.2 KB
/
module.php
File metadata and controls
389 lines (363 loc) · 13.2 KB
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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
<?php
declare(strict_types=1);
/**
* @addtogroup homematicextended
* @{
*
* @file module.php
*
* @author Michael Tröger <micha@nall-chan.net>
* @copyright 2020 Michael Tröger
* @license https://creativecommons.org/licenses/by-nc-sa/4.0/ CC BY-NC-SA 4.0
*
* @version 3.12
*/
require_once __DIR__ . '/../libs/HMBase.php'; // HMBase Klasse
/**
* HomeMaticDisEPWM55 ist die Klasse für das IPS-Modul 'HomeMatic Dis-EP-WM55'.
* Erweitert HMBase.
*/
class HomeMaticDisEPWM55 extends HMBase
{
/**
* Interne Funktion des SDK.
*/
public function Create()
{
parent::Create();
$this->RegisterPropertyString('Address', '');
$this->RegisterPropertyInteger('Protocol', 0);
$this->RegisterPropertyBoolean('EmulateStatus', false);
}
/**
* Interne Funktion des SDK.
*/
public function ApplyChanges()
{
parent::ApplyChanges();
$Address = $this->ReadPropertyString('Address');
$this->SetSummary($Address);
$this->SetReceiveDataFilter('.*9999999999.*');
}
//################# public
/**
* IPS-Instanz-Funktion 'HM_WriteValueDisplayNotify'.
* Steuert den Summer und die LED des Display.
*
* @param int $Chime Tonfolge 0-6
* @param int $Repeat Anzahl der Wiederholungen 0-15
* @param int $Wait Wartezeit in 10 Sekunden zwischen den Wiederholungen.
* @param int $Color Farbe der LED 0-3
*
* @return bool True bei Erfolg, sonst false.
*/
public function WriteValueDisplayNotify(int $Chime, int $Repeat, int $Wait, int $Color)
{
$Data = $this->GetSignal($Chime, $Repeat, $Wait, $Color);
if ($Data === false) {
return false;
}
return $this->SendData($Data);
}
/**
* IPS-Instanz-Funktion 'HM_WriteValueDisplayLine'.
* Beschreibt eine Zeile vom Display.
*
* @param int $Line Die zu beschreibende Zeile 1-3
* @param string $Text Der darzustellende Text (bis 12 Zeichen)
* @param int $Icon Das anzuzeigende Icon (0-9)
*
* @return bool True bei Erfolg, sonst false.
*/
public function WriteValueDisplayLine(int $Line, string $Text, int $Icon)
{
$Data[] = '0x0A';
for ($index = 1; $index <= 3; $index++) {
if ($index == $Line) {
$Line = $this->GetLine($Text, $Icon);
if ($Line === false) {
return false;
}
$Data = array_merge($Data, $Line);
} else {
$Data[] = '0x0A';
}
}
return $this->SendData($Data);
}
/**
* IPS-Instanz-Funktion 'HM_WriteValueDisplayLineEx'.
* Beschreibt eine Zeile vom Display und steuert den Summer sowie die LED des Display an.
*
* @param int $Line Die zu beschreibende Zeile 1-3
* @param string $Text Der darzustellende Text (bis 12 Zeichen)
* @param int $Icon Das anzuzeigende Icon (0-9)
* @param int $Chime Tonfolge 0-6
* @param int $Repeat Anzahl der Wiederholungen 0-15
* @param int $Wait Wartezeit in 10 Sekunden zwischen den Wiederholungen.
* @param int $Color Farbe der LED 0-3
*
* @return bool True bei Erfolg, sonst false.
*/
public function WriteValueDisplayLineEx(int $Line, string $Text, int $Icon, int $Chime, int $Repeat, int $Wait, int $Color)
{
$Data[] = '0x0A';
for ($index = 1; $index <= 3; $index++) {
if ($index == $Line) {
$Line = $this->GetLine($Text, $Icon);
if ($Line === false) {
return false;
}
$Data = array_merge($Data, $Line);
} else {
$Data[] = '0x0A';
}
}
$Notify = $this->GetSignal($Chime, $Repeat, $Wait, $Color);
if ($Notify === false) {
return false;
}
$Data = array_merge($Data, $Notify);
return $this->SendData($Data);
}
/**
* IPS-Instanz-Funktion 'HM_WriteValueDisplay'.
* Beschreibt alle Zeilen vom Display.
*
* @param string $Text1 Der darzustellende Text in Zeile 1(bis 12 Zeichen)
* @param int $Icon1 Das anzuzeigende Icon in Zeile 1(0-9)
* @param string $Text2 Der darzustellende Text in Zeile 2(bis 12 Zeichen)
* @param int $Icon2 Das anzuzeigende Icon in Zeile 2(0-9)
* @param string $Text3 Der darzustellende Text in Zeile 3(bis 12 Zeichen)
* @param int $Icon3 Das anzuzeigende Icon in Zeile 3(0-9)
*
* @return bool True bei Erfolg, sonst false.
*/
public function WriteValueDisplay(string $Text1, int $Icon1, string $Text2, int $Icon2, string $Text3, int $Icon3)
{
$Data[] = '0x0A';
$Line1 = $this->GetLine($Text1, $Icon1);
if ($Line1 === false) {
return false;
}
$Data = array_merge($Data, $Line1);
$Line2 = $this->GetLine($Text2, $Icon2);
if ($Line2 === false) {
return false;
}
$Data = array_merge($Data, $Line2);
$Line3 = $this->GetLine($Text3, $Icon3);
if ($Line3 === false) {
return false;
}
$Data = array_merge($Data, $Line3);
return $this->SendData($Data);
}
/**
* IPS-Instanz-Funktion 'HM_WriteValueDisplayEx'.
* Beschreibt alle Zeilen vom Display und steuert den Summer sowie die LED des Display an.
*
* @param string $Text1 Der darzustellende Text in Zeile 1(bis 12 Zeichen)
* @param int $Icon1 Das anzuzeigende Icon in Zeile 1(0-9)
* @param string $Text2 Der darzustellende Text in Zeile 2(bis 12 Zeichen)
* @param int $Icon2 Das anzuzeigende Icon in Zeile 2(0-9)
* @param string $Text3 Der darzustellende Text in Zeile 3(bis 12 Zeichen)
* @param int $Icon3 Das anzuzeigende Icon in Zeile 3(0-9)
* @param int $Chime Tonfolge 0-6
* @param int $Repeat Anzahl der Wiederholungen 0-15
* @param int $Wait Wartezeit in 10 Sekunden zwischen den Wiederholungen.
* @param int $Color Farbe der LED 0-3
*
* @return bool True bei Erfolg, sonst false.
*/
public function WriteValueDisplayEx(string $Text1, int $Icon1, string $Text2, int $Icon2, string $Text3, int $Icon3, int $Chime, int $Repeat, int $Wait, int $Color)
{
$Data[] = '0x0A';
$Line1 = $this->GetLine($Text1, $Icon1);
if ($Line1 === false) {
return false;
}
$Data = array_merge($Data, $Line1);
$Line2 = $this->GetLine($Text2, $Icon2);
if ($Line2 === false) {
return false;
}
$Data = array_merge($Data, $Line2);
$Line3 = $this->GetLine($Text3, $Icon3);
if ($Line3 === false) {
return false;
}
$Data = array_merge($Data, $Line3);
$Notify = $this->GetSignal($Chime, $Repeat, $Wait, $Color);
if ($Notify === false) {
return false;
}
$Data = array_merge($Data, $Notify);
return $this->SendData($Data);
}
//################# protected
/**
* Wird ausgeführt wenn der Kernel hochgefahren wurde.
*/
protected function KernelReady()
{
$this->ApplyChanges();
}
/**
* Wird ausgeführt wenn sich der Status vom Parent ändert.
*/
protected function IOChangeState($State)
{
$this->ApplyChanges();
}
//################# PRIVATE
/**
* Sendet die Daten an den HM-Socket.
*
* @param array $Submit Das Array mit allen Werten, welche an das Display gesendet werden sollen.
*
* @return bool True bei Erfolg, sonst false.
*
* @todo Rückgabewerte fehlen!
*/
private function SendData($Submit)
{
if (!$this->HasActiveParent()) {
trigger_error($this->Translate('Instance has no active parent instance!'), E_USER_NOTICE);
return false;
}
$ParentData = [
'DataID' => '{75B6B237-A7B0-46B9-BBCE-8DF0CFE6FA52}',
'Protocol' => 0,
'MethodName' => 'setValue',
'WaitTime' => 5000,
'Data' => [$this->ReadPropertyString('Address'), 'SUBMIT', '0x02,' . implode(',', $Submit) . ',0x03']
];
$this->SendDebug('Send', $ParentData, 0);
$JSON = json_encode($ParentData);
$ResultJSON = @$this->SendDataToParent($JSON);
if ($ResultJSON === false) {
trigger_error($this->Translate('Error on send Data.'), E_USER_NOTICE);
$this->SendDebug('Error JSON', $ResultJSON, 0);
return false;
}
$Result = json_decode($ResultJSON);
if ($Result === false) {
trigger_error($this->Translate('Error on send Data.'), E_USER_NOTICE);
$this->SendDebug('Error decode', $Result, 0);
return false;
}
$this->SendDebug('Receive', $Result, 0);
return true;
}
/**
* Erzeugt das Daten-Array aus den übergebenden Parametern.
*
* @param int $Chime Tonfolge 0-6
* @param int $Repeat Anzahl der Wiederholungen 0-15
* @param int $Wait Wartezeit in 10 Sekunden zwischen den Wiederholungen.
* @param int $Color Farbe der LED 0-3
*
* @return bool|array Das Array mit den Daten, oder im Fehlerfall false.
*/
private function GetSignal(int $Chime, int $Repeat, int $Wait, int $Color)
{
try {
if (!is_int($Chime)) {
throw new Exception(sprintf($this->Translate('Parameter %s must be type of integer.'), 'Chime'));
}
if (!is_int($Repeat)) {
throw new Exception(sprintf($this->Translate('Parameter %s must be type of integer.'), 'Repeat'));
}
if (!is_int($Wait)) {
throw new Exception(sprintf($this->Translate('Parameter %s must be type of integer.'), 'Wait'));
}
if (!is_int($Color)) {
throw new Exception(sprintf($this->Translate('Parameter %s must be type of integer.'), 'Color'));
}
if (($Chime < 0) || ($Chime > 6)) {
throw new Exception(sprintf($this->Translate('Parameter %s out of range.'), 'Chime'));
}
if (($Repeat < 0) || ($Repeat > 15)) {
throw new Exception(sprintf($this->Translate('Parameter %s out of range.'), 'Repeat'));
}
if (($Wait < 0) || ($Wait > 15)) {
throw new Exception(sprintf($this->Translate('Parameter %s out of range.'), 'Wait'));
}
if (($Color < 0) || ($Color > 3)) {
throw new Exception(sprintf($this->Translate('Parameter %s out of range.'), 'Color'));
}
} catch (Exception $exc) {
trigger_error($exc->getMessage(), E_USER_NOTICE);
return false;
}
$Data[] = '0x14';
$Data[] = '0xC' . dechex($Chime);
$Data[] = '0x1C';
$Data[] = '0xD' . dechex($Repeat);
$Data[] = '0x1D';
$Data[] = '0xE' . dechex($Wait);
$Data[] = '0x16';
$Data[] = '0xF' . dechex($Color);
return $Data;
}
/**
* Erzeugt aus dem übergebenen Parametern eine Daten-Array für den Text und das Icon.
*
* @param string $Text Der darzustellenden Text (0-12 Zeichen)
* @param int $Icon Das anzuzeigende Icon (0-9)
*
* @return array Das Daten-Array für eine Zeile.
*/
private function GetLine(string $Text, int $Icon)
{
try {
if (!is_string($Text)) {
throw new Exception(sprintf($this->Translate('Parameter %s must be type of string.'), 'Text'));
}
if (!is_int($Icon)) {
throw new Exception(sprintf($this->Translate('Parameter %s must be type of integer.'), 'Icon'));
}
if (($Icon < 0) || ($Icon > 9)) {
throw new Exception(sprintf($this->Translate('Parameter %s out of range.'), 'Icon'));
}
} catch (Exception $exc) {
trigger_error($exc->getMessage(), E_USER_NOTICE);
return false;
}
$Data[] = '0x12';
if ($Text === '') {
$Data[] = '0x20';
} else {
if (strpos($Text, '0x8') === 0) {
$Data[] = substr($Text, 0, 4);
} else {
$Text = $this->hex_encode($Text);
for ($i = 0; $i < ((strlen($Text) < 12) ? strlen($Text) : 12); $i++) {
$Data[] = '0x' . dechex(ord($Text[$i]));
}
}
}
if ($Icon != 0) {
$Data[] = '0x13';
$Data[] = '0x8' . dechex($Icon - 1);
}
$Data[] = '0x0A';
return $Data;
}
/**
* Konvertiert die deutschen Sonderzeichen.
*
* @param string $string Der Original-String.
*
* @return string Der veränderte String.
*/
private function hex_encode(string $string)
{
$umlaut = ['Ä', 'Ö', 'Ü', 'ä', 'ö', 'ü', 'ß', ':'];
$hex_neu = [chr(0x5b), chr(0x23), chr(0x24), chr(0x7b), chr(0x7c), chr(0x7d), chr(0x5f), chr(0x3a)];
$return = str_replace($umlaut, $hex_neu, $string);
return $return;
}
}
/* @} */