-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathmodule.php
More file actions
224 lines (200 loc) · 6.13 KB
/
Copy pathmodule.php
File metadata and controls
224 lines (200 loc) · 6.13 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
<?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
/**
* HomeMaticWRInterface ist die Klasse für das IPS-Modul 'HomeMatic WR-Interface'.
* Erweitert HMBase.
*/
class HomeMaticWRInterface extends HMBase
{
/**
* Interne Funktion des SDK.
*/
public function Create()
{
parent::Create();
$this->RegisterHMPropertys('XXX9999993');
$this->RegisterPropertyBoolean('EmulateStatus', false);
$this->RegisterPropertyInteger('Interval', 0);
$this->RegisterTimer('ReadWRInterface', 0, 'HM_ReadWRInterface($_IPS[\'TARGET\']);');
}
/**
* Interne Funktion des SDK.
*/
public function ApplyChanges()
{
parent::ApplyChanges();
$this->SetReceiveDataFilter('.*9999999999.*');
if (IPS_GetKernelRunlevel() != KR_READY) {
return;
}
if ($this->CheckConfig()) {
if ($this->ReadPropertyInteger('Interval') >= 5) {
$this->SetTimerInterval('ReadWRInterface', $this->ReadPropertyInteger('Interval') * 1000);
} else {
$this->SetTimerInterval('ReadWRInterface', 0);
}
} else {
$this->SetTimerInterval('ReadWRInterface', 0);
}
if (!$this->HasActiveParent()) {
return;
}
$this->ReadWRInterface();
}
//################# PUBLIC
/**
* IPS-Instanz-Funktion 'HM_ReadWRInterface'.
* Liest die Daten des WR-Interface.
*
* @return bool True bei Erfolg, sonst false.
*/
public function ReadWRInterface()
{
$Result = $this->GetInterface();
if ($Result === false) {
return false;
}
foreach ($Result as $Ident => $Value) {
if ($Value === '') {
continue;
}
switch (gettype($Value)) {
case 'boolean':
$Typ = VARIABLETYPE_BOOLEAN;
break;
case 'integer':
$Typ = VARIABLETYPE_INTEGER;
break;
case 'double':
case 'float':
$Typ = VARIABLETYPE_FLOAT;
break;
case 'string':
$Typ = VARIABLETYPE_STRING;
break;
default:
continue 2;
}
$vid = @$this->GetIDForIdent($Ident);
if ($vid === false) {
$this->MaintainVariable($Ident, $Ident, $Typ, '', 0, true);
$vid = $this->GetIDForIdent($Ident);
}
if ($Ident == 'CONNECTED') {
$this->SetValue($Ident, $Value);
continue;
}
if (GetValue($vid) != $Value) {
$this->SetValue($Ident, $Value);
}
}
return true;
}
//################# 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)
{
if ($State == IS_ACTIVE) {
$this->ApplyChanges();
} else {
$this->SetTimerInterval('ReadWRInterface', 0);
}
}
/**
* Registriert Nachrichten des aktuellen Parent und ließt die Adresse der CCU aus dem Parent.
*
* @return int ID des Parent.
*/
protected function RegisterParent()
{
$ParentId = parent::RegisterParent();
$this->SetSummary($this->HMAddress);
return $ParentId;
}
//################# PRIVATE
/**
* Prüft die Konfiguration und setzt den Status der Instanz.
*
* @return bool True wenn Konfig ok, sonst false.
*/
private function CheckConfig()
{
$Interval = $this->ReadPropertyInteger('Interval');
if ($Interval < 0) {
$this->SetStatus(IS_EBASE + 2);
return false;
}
if ($Interval == 0) {
$this->SetStatus(IS_INACTIVE);
return true;
}
if ($Interval < 5) {
$this->SetStatus(IS_EBASE + 3);
return false;
}
$this->SetStatus(IS_ACTIVE);
return true;
}
/**
* Liest alle Daten des WR-Interfaces aus der CCU aus.
*
* @return array Ein Array mit den Daten des Interface.
*/
private function GetInterface()
{
if (!$this->HasActiveParent()) {
trigger_error($this->Translate('Instance has no active parent instance!'), E_USER_NOTICE);
return false;
}
if (IPS_GetProperty($this->ParentID, 'WROpen') !== true) {
trigger_error($this->Translate('Instance has no active parent instance!'), E_USER_NOTICE);
return false;
}
$ParentData = [
'DataID' => '{75B6B237-A7B0-46B9-BBCE-8DF0CFE6FA52}',
'Protocol' => 1,
'MethodName' => 'getLGWStatus',
'WaitTime' => 5000,
'Data' => []
];
$this->SendDebug('Send', $ParentData, 0);
$JSON = json_encode($ParentData);
$ResultJSON = @$this->SendDataToParent($JSON);
if ($ResultJSON === false) {
trigger_error($this->Translate('Error on read WR-Interface.'), E_USER_NOTICE);
$this->SendDebug('Error JSON', $ResultJSON, 0);
return false;
}
$Result = json_decode($ResultJSON, true);
if (($Result === false) || is_null($Result)) {
trigger_error($this->Translate('Error on read WR-Interface.'), E_USER_NOTICE);
$this->SendDebug('Error decode', $Result, 0);
return false;
}
$this->SendDebug('Receive', $Result, 0);
return $Result;
}
}
/* @} */