forked from Wolbolar/IPSymconDenon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DenonClass.php
4667 lines (4225 loc) · 242 KB
/
DenonClass.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
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
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
declare(strict_types=1);
/** @noinspection SpellCheckingInspection */
require_once __DIR__ . '/AVRModels.php'; // diverse Klassen
class AVRModule extends IPSModule
{
private const PROPERTY_WRITE_DEBUG_INFORMATION_TO_LOGFILE = 'WriteDebugInformationToLogfile';
protected $testAllProperties = false;
private const STATUS_INST_IP_IS_INVALID = 204; //IP Adresse ist ungültig
private const STATUS_INST_NO_MANUFACTURER_SELECTED = 210;
private const STATUS_INST_NO_NEO_CATEGORY_SELECTED = 211;
private const STATUS_INST_NO_ZONE_SELECTED = 212;
private const STATUS_INST_NO_DENON_AVR_TYPE_SELECTED = 213;
private const STATUS_INST_NO_MARANTZ_AVR_TYPE_SELECTED = 214;
protected function SetInstanceStatus(): bool
{
if (IPS_GetKernelRunlevel() !== KR_READY) {
return false;
}
//Zone prüfen
$Zone = $this->ReadPropertyInteger('Zone');
$manufacturer = $this->ReadPropertyInteger('manufacturer');
if ($manufacturer === 0) {
// Error Manufacturer auswählen
$Status = self::STATUS_INST_NO_MANUFACTURER_SELECTED;
} elseif ($manufacturer === 1 && $this->ReadPropertyInteger('AVRTypeDenon') === 50) {
// Error Denon AVR Type auswählen
$Status = self::STATUS_INST_NO_DENON_AVR_TYPE_SELECTED;
} elseif ($manufacturer === 2 && $this->ReadPropertyInteger('AVRTypeMarantz') === 50) {
// Error Marantz AVR Type auswählen
$Status = self::STATUS_INST_NO_MARANTZ_AVR_TYPE_SELECTED;
} elseif ($Zone === 6) {
// Error Zone auswählen
$Status = self::STATUS_INST_NO_ZONE_SELECTED;
} elseif (!$this->isNeoCategoryValid()) {
// Error keine gültige Category ausgewählt
$Status = self::STATUS_INST_NO_NEO_CATEGORY_SELECTED;
} elseif ($this->GetIPParent() === false) {
// Status keine gültige IP
$Status = self::STATUS_INST_IP_IS_INVALID;
} else {
$Status = IS_ACTIVE;
}
$this->SetStatus($Status);
return $Status === IS_ACTIVE;
}
private function isNeoCategoryValid(): bool
{
if ($this->ReadPropertyBoolean('NEOToggle')) {
$CatId = $this->ReadPropertyInteger('NEOToggleCategoryID');
if (!IPS_ObjectExists($CatId) || (!IPS_GetObject($CatId)['ObjectType'] === 0 /*Category*/)) {
return false;
}
}
return true;
}
// Daten vom Splitter Instanz
public function ReceiveData($JSONString)
{
// Empfangene Daten vom Splitter
$data = json_decode($JSONString, false);
$this->Logger_Dbg(__FUNCTION__, json_encode($data->Buffer->Data));
$this->UpdateVariable($data->Buffer);
}
// Wertet Response aus und setzt Variable
protected function UpdateVariable($data): bool
{
//$data = json_decode('{"ResponseType":"TELNET","Data":[],"SurroundDisplay":"","Display":{"1":"\u0001GAMPER & DADONI - BITTERSWEET SYMPHONY (feat. Emily Roberts)","2":"\u0001Radio 7"}}');
$this->Logger_Dbg(__FUNCTION__, 'data: ' . json_encode($data));
$ResponseType = $data->ResponseType;
$Zone = $this->ReadPropertyInteger('Zone');
$this->Logger_Dbg(__FUNCTION__, sprintf('ResponseType: %s, Zone: %s', $ResponseType, $Zone));
$datavalues = null;
switch ($ResponseType) {
case 'HTTP':
if ($Zone === 0) {
$datavalues = $data->Data->Mainzone;
} elseif ($Zone === 1) {
$datavalues = $data->Data->Zone2;
} elseif ($Zone === 2) {
$datavalues = $data->Data->Zone3;
}
break;
case 'TELNET':
$datavalues = $data->Data;
$this->Logger_Dbg(__FUNCTION__, 'Data Telnet: ' . json_encode($datavalues));
if ($Zone === 0) {
//SurroundDisplay
if ($this->ReadPropertyBoolean('SurroundDisplay')) {
$SurroundDisplay = $data->SurroundDisplay;
if ($SurroundDisplay !== '') {
$this->Logger_Dbg(__FUNCTION__, 'Surround Display: ' . $SurroundDisplay);
SetValueString($this->GetIDForIdent('SurroundDisplay'), $SurroundDisplay);
}
}
// OnScreenDisplay
if ($this->ReadPropertyBoolean('Display')) {
$OnScreenDisplay = $data->Display;
$this->Logger_Dbg(__FUNCTION__, 'Display: ' . json_encode($OnScreenDisplay));
$idDisplay = $this->GetIDForIdent(DENON_API_Commands::DISPLAY);
$DisplayHTML = GetValue($idDisplay);
$doc = new DOMDocument();
$doc->loadHTML($DisplayHTML);
foreach ($OnScreenDisplay as $row => $content) {
$node = $doc->getElementById('NSARow' . $row);
if (!isset($node)){
continue;
}
if (($row > 0) && ($row < 8)) {
if ((ord(substr($content, 0, 1)) & 8) === 8) { //Cursor Select (8) ist gesetzt
$this->Logger_Dbg(__FUNCTION__, 'row: ' . $row . ', content[0]: ' . decbin(ord(substr($content, 0, 1))));
$node->setAttribute('style', 'color:#FF0000');
} elseif ($node->hasAttribute('style')) {
$node->removeAttribute('style');
}
if ($content !== ''){
$content = substr($content, 1);
}
}
$node->textContent = $content;
}
SetValueString($idDisplay, $doc->saveHTML());
}
}
break;
default:
trigger_error(__CLASS__ . '::' . __FUNCTION__ . ': Unknown response type: ' . $ResponseType);
return false;
}
if ($datavalues === null) {
$this->Logger_Err(__FUNCTION__ . ': ' . json_encode(debug_backtrace()));
return false;
}
foreach ($datavalues as $Ident => $Values) {
$Ident = str_replace(' ', '_', $Ident); //Ident Leerzeichen von Command mit _ ersetzten
$VarID = @$this->GetIDForIdent($Ident);
if ($VarID > 0) {
$VarType = $Values->VarType;
$Subcommand = $Values->Subcommand;
$Subcommandvalue = $Values->Value;
switch ($VarType) {
case 0: //Boolean
SetValueBoolean($VarID, $Subcommandvalue);
$this->Logger_Dbg(__FUNCTION__, 'Update ObjektID ' . $VarID . ' (' . IPS_GetName($VarID) . '): ' . $Subcommand . '(' . (int) $Subcommandvalue . ')');
break;
case 1: //Integer
SetValueInteger($VarID, $Subcommandvalue);
$this->Logger_Dbg(__FUNCTION__, 'Update ObjektID ' . $VarID . ' (' . IPS_GetName($VarID) . '): ' . $Subcommand . '(' . $Subcommandvalue . ')');
break;
case 2: //Float
SetValueFloat($this->GetIDForIdent($Ident), $Subcommandvalue);
$this->Logger_Dbg(__FUNCTION__, 'Update ObjektID ' . $VarID . ' (' . IPS_GetName($VarID) . '): ' . $Subcommand . '(' . $Subcommandvalue . ')');
break;
case 3: //String
SetValueString($this->GetIDForIdent($Ident), $Subcommandvalue);
$this->Logger_Dbg(__FUNCTION__, 'Update ObjektID ' . $VarID . ' (' . IPS_GetName($VarID) . '): ' . $Subcommandvalue);
break;
default:
trigger_error(__CLASS__ . '::' . __FUNCTION__ . ': invalid VarType: ' . $VarType);
}
} else {
$this->Logger_Dbg(__FUNCTION__, $this->InstanceID . ': Info: Keine Variable mit dem Ident "' . $Ident . '" gefunden.');
}
}
return true;
}
protected function RegisterProperties(): void
{
//Expert Parameters, must set first, because Logging functions are using it
$this->RegisterPropertyBoolean(self::PROPERTY_WRITE_DEBUG_INFORMATION_TO_LOGFILE, false);
$this->RegisterPropertyInteger('manufacturer', 0);
$this->RegisterPropertyInteger('AVRTypeDenon', 50);
$this->RegisterPropertyInteger('AVRTypeMarantz', 50);
$this->RegisterPropertyInteger('Zone', 6);
// all Checkboxes for the selection of the variables have to be registered
$DenonAVRVar = new DENONIPSProfiles(null, null, function (string $message, string $data) {
$this->Logger_Dbg($message, $data);
});
$profiles = $DenonAVRVar->GetAllProfiles();
foreach ($profiles as $profile) {
//some variables were registered with 'true' in the former version. So due to compatibility reasons they where registered with 'true' again
$DefaultValue = in_array(
$profile['PropertyName'],
[
DENONIPSProfiles::ptPower,
DENONIPSProfiles::ptMainZonePower,
DENONIPSProfiles::ptMainMute,
'InputSource',
DENONIPSProfiles::ptSurroundMode,
DENONIPSProfiles::ptMasterVolume,
DENONIPSProfiles::ptZone2Name,
DENONIPSProfiles::ptZone3Name,
DENONIPSProfiles::ptZone2Power,
DENONIPSProfiles::ptZone3Power,
DENONIPSProfiles::ptZone2Mute,
DENONIPSProfiles::ptZone3Mute,
DENONIPSProfiles::ptZone2Volume,
DENONIPSProfiles::ptZone3Volume,
DENONIPSProfiles::ptZone2InputSource,
DENONIPSProfiles::ptZone3InputSource, ],
true
);
$this->Logger_Dbg(__FUNCTION__, 'Property registered: ' . $profile['PropertyName'] . '(' . (int) $DefaultValue . ')');
$this->RegisterPropertyBoolean($profile['PropertyName'], $DefaultValue);
}
//Zusätzliche Inputs
$this->RegisterPropertyBoolean('FAVORITES', false);
$this->RegisterPropertyBoolean('IRADIO', false);
$this->RegisterPropertyBoolean('SERVER', false);
$this->RegisterPropertyBoolean('NAPSTER', false);
$this->RegisterPropertyBoolean('LASTFM', false);
$this->RegisterPropertyBoolean('FLICKR', false);
//Neo
$this->RegisterPropertyBoolean('NEOToggle', false);
$this->RegisterPropertyInteger('NEOToggleCategoryID', 0);
}
protected function RegisterReferences(): void
{
$objectIDs = [
$this->ReadPropertyInteger('NEOToggleCategoryID')
];
foreach ($this->GetReferenceList() as $ref) {
$this->UnregisterReference($ref);
}
foreach ($objectIDs as $id) {
if ($id !== 0) {
$this->RegisterReference($id);
}
}
}
protected function RegisterVariables(DENONIPSProfiles $DenonAVRVar, $idents, $AVRType, $manufacturername): bool
{
$this->Logger_Dbg(__FUNCTION__, 'variables: ' . json_encode($idents));
if (!in_array($manufacturername, [DENONIPSProfiles::ManufacturerDenon, DENONIPSProfiles::ManufacturerMarantz], true)) {
trigger_error('ManufacturerName not set');
return false;
}
// Add/Remove according to feature activation
//Selektierte Variablen anlegen
foreach ($idents as $ident => $selected) {
$statusvariable = $DenonAVRVar->SetupVariable($ident);
//Auswahl Prüfen
if ($selected) {
switch ($statusvariable['Type']) {
case DENONIPSVarType::vtString:
if ($statusvariable['ProfilName'] === '~HTMLBox') {
$profilname = '~HTMLBox';
} else {
$profilname = $manufacturername . '.' . $AVRType . '.' . $statusvariable['ProfilName'];
$this->CreateProfileString($profilname, $statusvariable['Icon']);
}
$this->RegisterVariableString($statusvariable['Ident'], $statusvariable['Name'], $profilname, $statusvariable['Position']);
if ($ident === DENON_API_Commands::DISPLAY) {
$DisplayHTML = '<!--suppress HtmlRequiredLangAttribute -->
<html><body><div id="NSARow0"></div><div id="NSARow1"></div><div id="NSARow2"></div><div id="NSARow3"></div><div id="NSARow4"></div><div id="NSARow5"></div><div id="NSARow6"></div><div id="NSARow7"></div><div id="NSARow8"></div></body></html>';
SetValueString($this->GetIDForIdent(DENON_API_Commands::DISPLAY), $DisplayHTML);
}
break;
case DENONIPSVarType::vtBoolean:
$this->RegisterVariableBoolean($statusvariable['Ident'], $statusvariable['Name'], '~Switch', $statusvariable['Position']);
$this->EnableAction($statusvariable['Ident']);
break;
case DENONIPSVarType::vtInteger:
$profilname = $manufacturername . '.' . $AVRType . '.' . $statusvariable['ProfilName'];
$this->CreateProfileIntegerAss(
$profilname,
$statusvariable['Icon'],
$statusvariable['Prefix'],
$statusvariable['Suffix'],
$statusvariable['Stepsize'],
$statusvariable['Digits'],
$statusvariable['Associations']
);
$this->RegisterVariableInteger($statusvariable['Ident'], $statusvariable['Name'], $profilname, $statusvariable['Position']);
$this->EnableAction($statusvariable['Ident']);
break;
case DENONIPSVarType::vtFloat:
$profilname = $manufacturername . '.' . $AVRType . '.' . $statusvariable['ProfilName'];
$this->CreateProfileFloat($profilname, $statusvariable['Icon'], $statusvariable['Prefix'], $statusvariable['Suffix'], $statusvariable['MinValue'], $statusvariable['MaxValue'], $statusvariable['Stepsize'], $statusvariable['Digits']);
$this->Logger_Dbg(__FUNCTION__, 'Variablenprofil angelegt: ' . $profilname);
$this->RegisterVariableFloat($statusvariable['Ident'], $statusvariable['Name'], $profilname, $statusvariable['Position']);
$this->EnableAction($statusvariable['Ident']);
break;
default:
trigger_error(__CLASS__ . '::' . __FUNCTION__ . ': invalid Type: ' . $statusvariable['Type']);
return false;
}
}
// wenn nicht selektiert löschen
else {
$this->removeVariableAction($statusvariable['Ident'], $ident);
}
}
return true;
}
protected function CreateNEOScripts($NEO_Parameter): void
{
// alle Instancevariablen vom Typ boolean suchen
$ObjectIds = IPS_GetChildrenIDs($this->InstanceID);
foreach ($ObjectIds as $ObjectId) {
// wenn es sich um eine Variable handelt und die vom Typ Boolean ist
$obj = IPS_GetObject($ObjectId);
if (($obj['ObjectType'] === 2 /*Variable*/) && IPS_GetVariable($ObjectId)['VariableType'] === DENONIPSVarType::vtBoolean) {
$Ident = $obj['ObjectIdent'];
if (array_key_exists($Ident, $NEO_Parameter)) {
$this->WriteNEOScript($ObjectId, $NEO_Parameter[$Ident][0], $NEO_Parameter[$Ident][1]);
}
}
}
}
protected function GetParent()
{
$instance = IPS_GetInstance($this->InstanceID); //array
return ($instance['ConnectionID'] > 0) ? $instance['ConnectionID'] : 0; //ConnectionID
}
private function checkProfileType($ProfileName, $VarType): void
{
$profile = IPS_GetVariableProfile($ProfileName);
if ($profile['ProfileType'] !== $VarType) {
trigger_error('Variable profile type does not match for already existing profile "' . $ProfileName . '". The existing profile has to be deleted manually.');
}
}
private function CreateProfileInteger($ProfileName, $Icon, $Prefix, $Suffix, $MinValue, $MaxValue, $StepSize, $Digits): void
{
if (!IPS_VariableProfileExists($ProfileName)) {
IPS_CreateVariableProfile($ProfileName, 1);
$this->Logger_Inf('Variablenprofil angelegt: ' . $ProfileName);
} else {
$this->checkProfileType($ProfileName, 1); //integer
}
IPS_SetVariableProfileIcon($ProfileName, $Icon);
IPS_SetVariableProfileText($ProfileName, $Prefix, $Suffix);
IPS_SetVariableProfileDigits($ProfileName, $Digits); // Nachkommastellen
IPS_SetVariableProfileValues($ProfileName, $MinValue, $MaxValue, $StepSize);
}
private function CreateProfileIntegerAss($ProfileName, $Icon, $Prefix, $Suffix, $StepSize, $Digits, $Associations): void
{
if (count($Associations) === 0) {
trigger_error(__FUNCTION__ . ': Associations of profil "' . $ProfileName . '" is empty');
IPS_LogMessage(__FUNCTION__, json_encode(debug_backtrace()));
return;
}
$MinValue = 0;
$MaxValue = 0;
$this->CreateProfileInteger($ProfileName, $Icon, $Prefix, $Suffix, $MinValue, $MaxValue, $StepSize, $Digits);
//zunächst werden alte Assoziationen gelöscht
//bool IPS_SetVariableProfileAssociation ( string $ProfilName, float $Wert, string $Name, string $Icon, integer $Farbe )
foreach (IPS_GetVariableProfile($ProfileName)['Associations'] as $Association) {
IPS_SetVariableProfileAssociation($ProfileName, $Association['Value'], '', '', -1);
}
//dann werden die aktuellen eingetragen
foreach ($Associations as $Association) {
IPS_SetVariableProfileAssociation($ProfileName, $Association[0], $Association[1], '', -1);
}
}
private function CreateProfileString($ProfileName, $Icon): void
{
if (!IPS_VariableProfileExists($ProfileName)) {
IPS_CreateVariableProfile($ProfileName, DENONIPSVarType::vtString);
$this->Logger_Inf('Variablenprofil angelegt: ' . $ProfileName);
} else {
$this->checkProfileType($ProfileName, DENONIPSVarType::vtString);
}
IPS_SetVariableProfileIcon($ProfileName, $Icon);
}
private function CreateProfileFloat($ProfileName, $Icon, $Prefix, $Suffix, $MinValue, $MaxValue, $StepSize, $Digits): void
{
if (!IPS_VariableProfileExists($ProfileName)) {
IPS_CreateVariableProfile($ProfileName, DENONIPSVarType::vtFloat);
$this->Logger_Inf('Variablenprofil angelegt: ' . $ProfileName);
} else {
$this->checkProfileType($ProfileName, DENONIPSVarType::vtFloat);
}
IPS_SetVariableProfileIcon($ProfileName, $Icon);
IPS_SetVariableProfileText($ProfileName, $Prefix, $Suffix);
IPS_SetVariableProfileDigits($ProfileName, $Digits); // Nachkommastellen
IPS_SetVariableProfileValues($ProfileName, $MinValue, $MaxValue, $StepSize);
}
protected function GetAPICommandFromIdent($Ident): string
{
if (in_array($Ident, [DENON_API_Commands::Z2POWER, DENON_API_Commands::Z2INPUT, DENON_API_Commands::Z2VOL], true)) {
$APICommand = DENON_API_Commands::Z2;
} elseif (in_array($Ident, [DENON_API_Commands::Z3POWER, DENON_API_Commands::Z3INPUT, DENON_API_Commands::Z3VOL], true)) {
$APICommand = DENON_API_Commands::Z3;
} elseif ($Ident === 'PVPICT') {
$APICommand = 'PV';
} else {
$APICommand = str_replace('_', ' ', $Ident); //Ident _ von Ident mit Leerzeichen ersetzten
}
return $APICommand;
}
protected function GetManufacturerName()
{
$manufacturer = $this->ReadPropertyInteger('manufacturer');
switch ($manufacturer) {
case 0:
$manufacturername = DENONIPSProfiles::ManufacturerNone;
break;
case 1:
$manufacturername = DENONIPSProfiles::ManufacturerDenon;
break;
case 2:
$manufacturername = DENONIPSProfiles::ManufacturerMarantz;
break;
default:
trigger_error('Unnown manufacturer: ' . $manufacturer);
$manufacturername = false;
}
return $manufacturername;
}
protected function GetAVRType($manufacturername)
{
switch ($manufacturername) {
case DENONIPSProfiles::ManufacturerDenon:
$TypeInt = $this->ReadPropertyInteger('AVRTypeDenon');
break;
case DENONIPSProfiles::ManufacturerMarantz:
$TypeInt = $this->ReadPropertyInteger('AVRTypeMarantz');
break;
default:
return false;
}
if ($TypeInt === 50) { //none
return false;
}
foreach (AVRs::getAllAVRs() as $AVRType => $Caps) {
if ($Caps['internalID'] === $TypeInt) {
return $Caps['Name'];
}
}
return false;
}
protected function removeVariableAction($Ident, $Profile): void
{
$vid = @$this->GetIDForIdent($Ident);
if ($vid !== false) {
$Name = IPS_GetName($vid);
$this->DisableAction($Ident);
$this->UnregisterVariable($Ident);
$this->Logger_Inf('Variable gelöscht - Name: ' . $Name . ', Ident: ' . $Ident . ', ObjektID: ' . $vid);
//delete Profile
if (IPS_VariableProfileExists($Profile)) {
IPS_DeleteVariableProfile($Profile);
$this->Logger_Inf('Variablenprofil gelöscht:' . $Profile);
}
}
}
protected function GetInputsAVR(DENONIPSProfiles $DenonAVRVar)
{
$Zone = $this->ReadPropertyInteger('Zone');
$DenonAVRVar->SetInputSources(
$this->GetIPParent(),
$Zone,
$this->ReadPropertyBoolean('FAVORITES'),
$this->ReadPropertyBoolean('IRADIO'),
$this->ReadPropertyBoolean('SERVER'),
$this->ReadPropertyBoolean('NAPSTER'),
$this->ReadPropertyBoolean('LASTFM'),
$this->ReadPropertyBoolean('FLICKR')
);
return $DenonAVRVar->GetInputVarMapping($Zone);
}
//IP des AVR aus der IO Instanz
protected function GetIPParent()
{
$io_instance = IPS_GetInstance($this->GetParent())['ConnectionID'];
$IP = IPS_GetProperty($io_instance, 'Host');
if (!filter_var($IP, FILTER_VALIDATE_IP) === false) {
return $IP;
}
return false;
}
protected function FormSelectionZone(): array
{
$form = [
[
'type' => 'Label',
'caption' => 'Please select an AVR zone and push the "Apply Changes" button'
],
[
'type' => 'Select',
'name' => 'Zone',
'caption' => 'AVR Zone',
'options' => [
[
'label' => 'Main Zone',
'value' => 0
],
[
'label' => 'Zone 2',
'value' => 1
],
[
'label' => 'Zone 3',
'value' => 2
],
[
'label' => 'select zone',
'value' => 6
]
]
]
];
return $form;
}
protected function FormSelectionAVR($manufacturer): array
{
$form = [
[
'type' => 'Label',
'caption' => 'Please select an AVR zone and push the "Apply Changes" button'
],
[
'type' => 'Select',
'name' => 'AVRType' . $manufacturer,
'caption' => 'Type AVR' . $manufacturer,
'options' => $this->FormSelectionAVROptions($manufacturer)
]
];
return $form;
}
protected function FormSelectionAVROptions(string $manufacturer): array
{
$form = [
[
'value' => 50,
'caption' => 'select AVR Type'
]
];
foreach (AVRs::getAllAVRs() as $AVRName => $Caps) {
if ($Caps['Manufacturer'] === $manufacturer) {
$form[] = [
'value' => $Caps['internalID'],
'caption' => $AVRName
];
}
}
return $form;
}
protected function FormSelectionNEO(): array
{
$form = [
[
'type' => 'ExpansionPanel',
'caption' => 'create helper scripts for toggling with NEO (Mediola)',
'items' => [
[
'type' => 'CheckBox',
'name' => 'NEOToggle',
'caption' => 'create separate NEO toggle scripts'
],
[
'type' => 'Label',
'caption' => 'category for creating NEO scripts:'
],
[
'type' => 'SelectCategory',
'name' => 'NEOToggleCategoryID',
'caption' => 'script category'
]
]
]
];
return $form;
}
protected function FormMoreInputs(): array
{
$form = [
[
'type' => 'ExpansionPanel',
'caption' => 'more inputs',
'items' => [
[
'type' => 'CheckBox',
'name' => 'FAVORITES',
'caption' => 'favorites'
],
[
'type' => 'CheckBox',
'name' => 'IRADIO',
'caption' => 'internet radio'
],
[
'type' => 'CheckBox',
'name' => 'SERVER',
'caption' => 'Server'
],
[
'type' => 'CheckBox',
'name' => 'NAPSTER',
'caption' => 'Napster'
],
[
'type' => 'CheckBox',
'name' => 'LASTFM',
'caption' => 'LastFM'
],
[
'type' => 'CheckBox',
'name' => 'FLICKR',
'caption' => 'Flickr'
],
]
]
];
return $form;
}
protected function FormExpertParameters(): array
{
return [
[
'type' => 'ExpansionPanel',
'caption' => 'Expert Parameters',
'items' => [
[
'type' => 'CheckBox',
'name' => 'WriteDebugInformationToLogfile',
'caption' => 'Debug information are written additionally to standard logfile'],
]]];
}
protected function FormStatus(): array
{
$form = [
[
'code' => 204,
'icon' => 'error',
'caption' => 'IP address is not valid.'
],
[
'code' => 210,
'icon' => 'error',
'caption' => 'select a manufacturer.'
],
[
'code' => 211,
'icon' => 'error',
'caption' => 'select category for import.'
],
[
'code' => 212,
'icon' => 'error',
'caption' => 'please select an AVR Zone.'
],
[
'code' => 213,
'icon' => 'error',
'caption' => 'please select a Denon AVR type.'
],
[
'code' => 214,
'icon' => 'error',
'caption' => 'please select a Marantz AVR type.'
]
];
return $form;
}
protected function getTypeItem($type, $command, $propertyname, $caption, $CapsItems = null): ?array
{
if ($propertyname === '') {
trigger_error(__CLASS__ . '::' . __FUNCTION__ . ': ' . $command . ': PropertyName nicht gesetzt.');
return null;
}
// is the command supported?
if ($CapsItems === null || in_array($command, $CapsItems, true)) {
$item = [
'type' => $type,
'name' => $propertyname,
'caption' => $caption . ' (' . $command . ')'
];
return $item;
}
return null;
}
private function WriteNEOScript($ObjectID, $FunctionName, $LogLabel)
{
$InstanzID = IPS_GetParent($ObjectID);
$InstanzName = IPS_GetName($InstanzID);
$Name = IPS_GetName($ObjectID);
$KatID = $this->ReadPropertyInteger('NEOToggleCategoryID');
$ScriptName = $InstanzName . ' ' . $Name . '_toggle';
$SkriptID = @IPS_GetScriptIDByName($ScriptName, $KatID);
if ($SkriptID === false) {
$Content
= '
<?
$status = GetValueBoolean(' . $ObjectID . '); // Status des Geräts auslesen
if ($status == false)// Einschalten
{
' . $FunctionName . '(' . $InstanzID . ', true);
IPS_LogMessage( "Denon Telnet AVR" , "' . $LogLabel . ' einschalten" );
}
elseif ($status == true)// Ausschalten
{
' . $FunctionName . '(' . $InstanzID . ', false);
IPS_LogMessage( "Denon Telnet AVR" , "' . $LogLabel . ' ausschalten" );
}
?>';
// write Script
$ScriptID = IPS_CreateScript(0);
IPS_SetName($ScriptID, $ScriptName);
IPS_SetParent($ScriptID, $KatID);
IPS_SetScriptContent($ScriptID, $Content);
return $ScriptID;
}
return false;
}
protected function Logger_Err(string $message): void
{
$this->SendDebug('LOG_ERR', $message, 0);
/*
if (function_exists('IPSLogger_Err') && $this->ReadPropertyBoolean('WriteLogInformationToIPSLogger')) {
IPSLogger_Err(__CLASS__, $message);
}
*/
$this->LogMessage($message, KL_ERROR);
}
protected function Logger_Inf(string $message): void
{
$this->SendDebug('LOG_INFO', $message, 0);
$this->LogMessage($message, KL_NOTIFY);
}
protected function Logger_Dbg(string $message, string $data): void
{
$this->SendDebug($message, $data, 0);
/*
if (function_exists('IPSLogger_Dbg') && $this->ReadPropertyBoolean('WriteDebugInformationToIPSLogger')) {
IPSLogger_Dbg(__CLASS__ . '.' . IPS_GetObject($this->InstanceID)['ObjectName'] . '.' . $message, $data);
}
*/
if ($this->ReadPropertyBoolean(self::PROPERTY_WRITE_DEBUG_INFORMATION_TO_LOGFILE)) {
$this->LogMessage(sprintf('%s: %s', $message, $data), KL_DEBUG);
}
}
}
class DENONIPSVarType extends stdClass
{
// API Datentypen
public const vtNone = -1;
public const vtBoolean = 0;
public const vtInteger = 1;
public const vtFloat = 2;
public const vtString = 3;
}
class DENONIPSProfiles extends stdClass
{
private $debug = false; //wird im Constructor gesetzt
private $AVRType;
private $profiles;
public const ManufacturerDenon = 'Denon';
public const ManufacturerMarantz = 'Marantz';
public const ManufacturerNone = 'none';
//Profiltype
public const ptPower = 'Power';
public const ptMasterVolume = 'MasterVolume';
public const ptChannelVolumeFL = 'ChannelVolumeFL';
public const ptChannelVolumeFR = 'ChannelVolumeFR';
public const ptChannelVolumeC = 'ChannelVolumeC';
public const ptChannelVolumeSW = 'ChannelVolumeSW';
public const ptChannelVolumeSW2 = 'ChannelVolumeSW2';
public const ptChannelVolumeSL = 'ChannelVolumeSL';
public const ptChannelVolumeSR = 'ChannelVolumeSR';
public const ptChannelVolumeSBL = 'ChannelVolumeSBL';
public const ptChannelVolumeSBR = 'ChannelVolumeSBR';
public const ptChannelVolumeSB = 'ChannelVolumeSB';
public const ptChannelVolumeFHL = 'ChannelVolumeFHL';
public const ptChannelVolumeFHR = 'ChannelVolumeFHR';
public const ptChannelVolumeFWL = 'ChannelVolumeFWL';
public const ptChannelVolumeFWR = 'ChannelVolumeFWR';
public const ptMainMute = 'MainMute';
public const ptInputSource = 'Inputsource';
public const ptMainZonePower = 'MainZonePower';
public const ptInputMode = 'InputMode';
public const ptDigitalInputMode = 'DigitalInputMode';
public const ptVideoSelect = 'VideoSelect';
public const ptSleep = 'Sleep';
public const ptSurroundMode = 'SurroundMode';
public const ptQuickSelect = 'QuickSelect';
public const ptSmartSelect = 'SmartSelect';
public const ptHDMIMonitor = 'HDMIMonitor';
public const ptASP = 'ASP';
public const ptResolution = 'Resolution';
public const ptResolutionHDMI = 'ResolutionHDMI';
public const ptHDMIAudioOutput = 'HDMIAudioOutput';
public const ptVideoProcessingMode = 'VideoProcessingMode';
public const ptToneCTRL = 'ToneCTRL';
public const ptSurroundBackMode = 'SurroundBackMode';
public const ptSurroundPlayMode = 'SurroundPlayMode';
public const ptFrontHeight = 'FrontHeight';
public const ptPLIIZHeightGain = 'PLIIZHeightGain';
public const ptSpeakerOutput = 'SpeakerOutputFront';
public const ptMultiEQMode = 'MultiEQMode';
public const ptDynamicEQ = 'DynamicEQ';
public const ptAudysseyLFC = 'AudysseyLFC';
public const ptAudysseyContainmentAmount = 'AudysseyContainmantAmount';
public const ptReferenceLevel = 'ReferenceLevel';
public const ptDynamicVolume = 'DynamicVolume';
public const ptAudysseyDSX = 'AudysseyDSX';
public const ptStageWidth = 'StageWidth';
public const ptStageHeight = 'StageHeight';
public const ptBassLevel = 'BassLevel';
public const ptTrebleLevel = 'TrebleLevel';
public const ptLoudnessManagement = 'LoudnessManagement';
public const ptDynamicRangeCompression = 'DynamicRangeCompression';
public const ptMDAX = 'MDAX';
public const ptDynamicCompressor = 'DynamicCompressor';
public const ptCenterLevelAdjust = 'CenterLevelAdjust';
public const ptLFELevel = 'LFELevel';
public const ptLFE71Level = 'LFE71Level';
public const ptEffectLevel = 'EffectLevel';
public const ptDelay = 'Delay';
public const ptAFDM = 'AFDM';
public const ptPanorama = 'Panorama';
public const ptDimension = 'Dimension';
public const ptDialogControl = 'DialogControl';
public const ptCenterWidth = 'CenterWidth';
public const ptCenterImage = 'CenterImage';
public const ptCenterGain = 'CenterGain';
public const ptSubwoofer = 'Subwoofer';
public const ptRoomSize = 'RoomSize';
public const ptAudioDelay = 'AudioDelay';
public const ptAudioRestorer = 'AudioRestorer';
public const ptFrontSpeaker = 'FrontSpeaker';
public const ptContrast = 'Contrast';
public const ptBrightness = 'Brightness';
public const ptSaturation = 'Saturation';
public const ptChromalevel = 'Chromalevel';
public const ptHue = 'Hue';
public const ptDigitalNoiseReduction = 'DNRDirectChange';
public const ptPictureMode = 'PictureMode';
public const ptEnhancer = 'Enhancer';
public const ptZone2Power = 'Zone2Power';
public const ptZone2InputSource = 'Zone2InputSource';
public const ptZone2Volume = 'Zone2Volume';
public const ptZone2Mute = 'Zone2Mute';
public const ptZone2ChannelSetting = 'Zone2ChannelSetting';
public const ptZone2ChannelVolumeFL = 'Zone2ChannelVolumeFL';
public const ptZone2ChannelVolumeFR = 'Zone2ChannelVolumeFR';
public const ptZone2HPF = 'Zone2HPF';
public const ptZone2Bass = 'Zone2Bass';
public const ptZone2Treble = 'Zone2Treble';
public const ptZone2QuickSelect = 'Zone2QuickSelect';
public const ptZone2SmartSelect = 'Zone2SmartSelect';
public const ptZone2Sleep = 'Zone2Sleep';
public const ptZone3InputSource = 'Zone3InputSource';
public const ptZone3Volume = 'Zone3Volume';
public const ptZone3Mute = 'Zone3Mute';
public const ptZone3ChannelSetting = 'Zone3ChannelSetting';
public const ptZone3ChannelVolumeFL = 'Zone3ChannelVolumeFL';
public const ptZone3ChannelVolumeFR = 'Zone3ChannelVolumeFR';
public const ptZone3HPF = 'Zone3HPF';
public const ptZone3Bass = 'Zone3Bass';
public const ptZone3Treble = 'Zone3Treble';
public const ptZone3QuickSelect = 'Zone3QuickSelect';
public const ptZone3SmartSelect = 'Zone3SmartSelect';
public const ptZone3Sleep = 'Zone3Sleep';
public const ptCinemaEQ = 'CinemaEQ';
public const ptHTEQ = 'HTEQ';
public const ptDynamicRange = 'DynamicRange';
public const ptPreset = 'Preset';
public const ptZone2Name = 'Zone2Name';
public const ptZone3Power = 'Zone3Power';
public const ptZone3Name = 'Zone3Name';
public const ptNavigation = 'Navigation';
public const ptNavigationNetwork = 'NavigationNetwork';
public const ptSubwooferATT = 'SubwooferATT';
//public const ptDCOMPDirectChange = 'DCOMPDirectChange';
public const ptDolbyVolumeLeveler = 'DolbyVolumeLeveler';
public const ptDolbyVolumeModeler = 'DolbyVolumeModeler';
public const ptVerticalStretch = 'VerticalStretch';
public const ptDolbyVolume = 'DolbyVolume';
public const ptFriendlyName = 'FriendlyName';
public const ptMainZoneName = 'MainZoneName';
public const ptTopMenuLink = 'TopMenuLink';
public const ptModel = 'Model';
public const ptGUIMenuSourceSelect = 'GUIMenuSourceSelect';
public const ptGUIMenuSetup = 'GUIMenuSetup';
public const ptSurroundDisplay = 'SurroundDisplay';
public const ptDisplay = 'Display';
public const ptGraphicEQ = 'GraphicEQ';
public const ptHeadphoneEQ = 'HeadphoneEQ';
public const ptDimmer = 'Dimmer';
public const ptDialogLevelAdjust = 'DialogLevelAdjust';
public const ptMAINZONEAutoStandbySetting = 'MAINZONEAutoStandbySetting';
public const ptMAINZONEECOModeSetting = 'MAINZONEECOModeSetting';
public const ptCenterSpread = 'Centerspread';
public const ptSpeakerVirtualizer = 'SpeakerVirtualizer';