22
22
* @property int $ParentID
23
23
* @property array $Nodes
24
24
* @property array $TempNodes
25
+ * @property array $Scenes
26
+ * @property array $TempScenes
25
27
*/
26
28
class KLF200Configurator extends IPSModule
27
29
{
@@ -44,6 +46,8 @@ public function Create()
44
46
//$this->GetNodeInfoIsRunning = false;
45
47
$ this ->Nodes = [];
46
48
$ this ->TempNodes = [];
49
+ $ this ->Scenes = [];
50
+ $ this ->TempScenes = [];
47
51
$ this ->ParentID = 0 ;
48
52
}
49
53
@@ -61,7 +65,8 @@ public function ApplyChanges()
61
65
$ APICommands = [
62
66
\KLF200 \APICommand::GET_ALL_NODES_INFORMATION_NTF ,
63
67
\KLF200 \APICommand::GET_ALL_NODES_INFORMATION_FINISHED_NTF ,
64
- \KLF200 \APICommand::NODE_INFORMATION_CHANGED_NTF
68
+ \KLF200 \APICommand::NODE_INFORMATION_CHANGED_NTF ,
69
+ \KLF200 \APICommand::GET_SCENE_LIST_NTF
65
70
];
66
71
67
72
if (count ($ APICommands ) > 0 ) {
@@ -95,19 +100,6 @@ public function RequestAction($Ident, $Value)
95
100
if ($ this ->IORequestAction ($ Ident , $ Value )) {
96
101
return true ;
97
102
}
98
- /*
99
- if ($Ident == 'GetAllNodesInformation') {
100
- if ($Value) {
101
- if ($this->GetAllNodesInformation()) {
102
- while ($this->GetNodeInfoIsRunning) {
103
- IPS_Sleep(10);
104
- }
105
- return true;
106
- }
107
- } else {
108
- return $this->GetAllNodesInformation();
109
- }
110
- }*/
111
103
return false ;
112
104
}
113
105
@@ -155,6 +147,7 @@ public function RemoveNode(int $Node)
155
147
return true ;
156
148
}
157
149
150
+ //todo scenes
158
151
public function GetConfigurationForm()
159
152
{
160
153
$ Form = json_decode (file_get_contents (__DIR__ . '/form.json ' ), true );
@@ -220,7 +213,6 @@ protected function IOChangeState($State)
220
213
{
221
214
if ($State == IS_ACTIVE) {
222
215
$this->UpdateFormField('GatewayCommands', 'visible', true);
223
- //$this->GetAllNodesInformation();
224
216
} else {
225
217
$this->Nodes = [];
226
218
$this->TempNodes = [];
@@ -232,24 +224,14 @@ protected function IOChangeState($State)
232
224
$this->UpdateFormField('Config', 'values', json_encode($NodeValues));
233
225
$this->UpdateFormField('RemoveNode', 'values', json_encode([]));
234
226
$this->UpdateFormField('GatewayCommands', 'visible', false);
235
- //$this->ReloadForm();
236
227
}
237
228
}
238
229
239
- protected function UpdateFormField($Name, $Field, $Value)
240
- {
241
- $this->SendDebug('Form: ' . $Name . '.' . $Field, $Value, 0);
242
- parent::UpdateFormField($Name, $Field, $Value);
243
- }
244
-
245
230
protected function SendDebug($Message, $Data, $Format)
246
231
{
247
232
if (is_a($Data, '\\KLF200\\APIData')) {
248
233
/** @var \KLF200\APIData $Data */
249
234
$this->SendDebugTrait($Message . ':Command', \KLF200\APICommand::ToString($Data->Command), 0);
250
- if ($Data->NodeID != -1) {
251
- $this->SendDebugTrait($Message . ':NodeID', $Data->NodeID, 0);
252
- }
253
235
if ($Data->isError()) {
254
236
$this->SendDebugTrait('Error', $Data->ErrorToString(), 0);
255
237
} elseif ($Data->Data != '') {
@@ -272,7 +254,7 @@ private function ReceiveEvent(\KLF200\APIData $APIData)
272
254
$this->SendDebug('NodeTypeSubType', $NodeTypeSubType, 0);
273
255
$this->SendDebug('SerialNumber', substr($APIData->Data, 76, 8), 1);
274
256
$this->SendDebug('BuildNumber', ord($APIData->Data[75]), 0);
275
- $Nodes = $this->TempNodes; //$this->Nodes;
257
+ $Nodes = $this->TempNodes;
276
258
$Nodes[$APIData->NodeID] = [
277
259
'Name' => $Name,
278
260
'NodeTypeSubType' => $NodeTypeSubType
@@ -282,17 +264,18 @@ private function ReceiveEvent(\KLF200\APIData $APIData)
282
264
case \KLF200\APICommand::GET_ALL_NODES_INFORMATION_FINISHED_NTF:
283
265
$this->Nodes = $this->TempNodes;
284
266
$this->TempNodes = [];
267
+ $this->SendDebug('END Nodes', '', 0);
285
268
$Splitter = IPS_GetInstance($this->InstanceID)['ConnectionID'];
286
269
$NodeValues = $this->GetNodeConfigFormValues($Splitter);
287
- $this->UpdateFormField('Config', 'values', json_encode($NodeValues));
270
+ $SceneValues = $this->GetSceneConfigFormValues($Splitter);
271
+ $this->UpdateFormField('Config', 'values', json_encode(array_merge($NodeValues, $SceneValues)));
288
272
$this->UpdateFormField('Config', 'visible', true);
289
273
$this->UpdateFormField('GatewayCommands', 'visible', true);
290
274
$this->UpdateFormField('ProgressLearn', 'visible', false);
291
275
$DeleteNodeValues = $this->GetDeleteNodeConfigFormValues();
292
276
$this->UpdateFormField('RemoveNode', 'values', json_encode($DeleteNodeValues));
293
277
$this->UpdateFormField('RemoveNode', 'visible', true);
294
278
$this->UpdateFormField('ProgressRemove', 'visible', false);
295
- //$this->GetNodeInfoIsRunning = false;
296
279
break;
297
280
case \KLF200\APICommand::NODE_INFORMATION_CHANGED_NTF:
298
281
$Name = trim(substr($APIData->Data, 4, 64));
@@ -301,6 +284,29 @@ private function ReceiveEvent(\KLF200\APIData $APIData)
301
284
$Nodes[$APIData->NodeID]['Name'] = $Name;
302
285
$this->Nodes = $Nodes;
303
286
break;
287
+ case \KLF200\APICommand::GET_SCENE_LIST_NTF:
288
+ $NumberOfSceneObject = ord($APIData->Data[0]);
289
+ $this->SendDebug('NumberOfObject', $NumberOfSceneObject, 0);
290
+ $ObjectData = substr($APIData->Data, 1);
291
+ for ($index = 0; $index < $NumberOfSceneObject; $index++) {
292
+ $SceneID = ord($ObjectData[0]);
293
+ $SceneName = trim(substr($ObjectData, 1, 64));
294
+ $TempScenes = $this->TempScenes;
295
+ $TempScenes[$SceneID]['Name'] = $SceneName;
296
+ $this->TempScenes = $TempScenes;
297
+ $ObjectData = substr($ObjectData, 65);
298
+ }
299
+ $RemainingNumberOfObject = $ObjectData[0];
300
+ if ($RemainingNumberOfObject == 0) {
301
+ $this->Scenes = $this->TempScenes;
302
+ $this->TempScenes = [];
303
+ $this->SendDebug('END Scenes', '', 0);
304
+ $Splitter = IPS_GetInstance($this->InstanceID)['ConnectionID'];
305
+ $NodeValues = $this->GetNodeConfigFormValues($Splitter);
306
+ $SceneValues = $this->GetSceneConfigFormValues($Splitter);
307
+ $this->UpdateFormField('Config', 'values', json_encode(array_merge($NodeValues, $SceneValues)));
308
+ }
309
+ break;
304
310
}
305
311
}
306
312
@@ -325,19 +331,6 @@ private function GetConfigParam(&$item1, $InstanceID, $ConfigParam)
325
331
$item1 = IPS_GetProperty($InstanceID, $ConfigParam);
326
332
}
327
333
328
- /*private function GetAllNodesInformation()
329
- {
330
- $this->Nodes = [];
331
-
332
- $APIData = new \KLF200\APIData(\KLF200\APICommand::GET_ALL_NODES_INFORMATION_REQ);
333
- $ResultAPIData = $this->SendAPIData($APIData);
334
- if ($ResultAPIData->isError()) {
335
- return false;
336
- }
337
- $this->GetNodeInfoIsRunning = true;
338
- return ord($ResultAPIData->Data[0]) == 1;
339
- }*/
340
-
341
334
/**
342
335
* Interne Funktion des SDK.
343
336
*/
@@ -377,10 +370,10 @@ private function GetNodeConfigFormValues(int $Splitter)
377
370
$NodeValues[] = $AddValue;
378
371
}
379
372
380
- foreach ($InstanceIDListNodes as $InstanceIDNode => $Node ) {
373
+ foreach ($InstanceIDListNodes as $InstanceIDNode => $NodeID ) {
381
374
$NodeValues[] = [
382
375
'instanceID' => $InstanceIDNode,
383
- 'nodeid' => $Node ,
376
+ 'nodeid' => $NodeID ,
384
377
'name' => IPS_GetName($InstanceIDNode),
385
378
'type' => 'unknown',
386
379
'location' => stristr(IPS_GetLocation($InstanceIDNode), IPS_GetName($InstanceIDNode), true)
@@ -389,6 +382,57 @@ private function GetNodeConfigFormValues(int $Splitter)
389
382
return $NodeValues;
390
383
}
391
384
385
+ /**
386
+ * Interne Funktion des SDK.
387
+ */
388
+ private function GetSceneConfigFormValues(int $Splitter)
389
+ {
390
+ $FoundScenes = $this->Scenes;
391
+ $this->SendDebug('Found Scenes', $FoundScenes, 0);
392
+ $InstanceIDListScenes = $this->GetInstanceList(\KLF200\GUID::Scene, $Splitter, \KLF200\Scene\Property::SceneId);
393
+ $this->SendDebug('IPS Scenes', $InstanceIDListScenes, 0);
394
+ $SceneValues = [];
395
+ foreach ($FoundScenes as $SceneID => $Scene) {
396
+ $InstanceIDScene = array_search($Scene, $InstanceIDListScenes);
397
+ if ($InstanceIDScene !== false) {
398
+ $AddValue = [
399
+ 'instanceID' => $InstanceIDScene,
400
+ 'sceneid' => $SceneID,
401
+ 'name' => IPS_GetName($InstanceIDScene),
402
+ 'type' => $this->Translate('Scene'),
403
+ 'location' => stristr(IPS_GetLocation($InstanceIDScene), IPS_GetName($InstanceIDScene), true)
404
+ ];
405
+ unset($InstanceIDListScenes[$InstanceIDScene]);
406
+ } else {
407
+ $AddValue = [
408
+ 'instanceID' => 0,
409
+ 'sceneid' => $SceneID,
410
+ 'name' => $Scene['Name'],
411
+ 'type' => $this->Translate('Scene'),
412
+ 'location' => ''
413
+ ];
414
+ }
415
+ $AddValue['create'] = [
416
+ 'moduleID' => \KLF200\GUID::Scene,
417
+ 'configuration' => [\KLF200\Scene\Property::SceneId => $Scene],
418
+ 'location' => ['Velux KLF200']
419
+ ];
420
+
421
+ $SceneValues[] = $AddValue;
422
+ }
423
+
424
+ foreach ($InstanceIDListScenes as $InstanceIDScene => $SceneID) {
425
+ $SceneValues[] = [
426
+ 'instanceID' => $InstanceIDScene,
427
+ 'sceneid' => $SceneID,
428
+ 'name' => IPS_GetName($InstanceIDScene),
429
+ 'type' => $this->Translate('Scene'),
430
+ 'location' => stristr(IPS_GetLocation($InstanceIDScene), IPS_GetName($InstanceIDScene), true)
431
+ ];
432
+ }
433
+ return $SceneValues;
434
+ }
435
+
392
436
private function GetDeleteNodeConfigFormValues()
393
437
{
394
438
$NodeValues = [];
0 commit comments