Skip to content

Commit 3a6c38f

Browse files
committed
no message
1 parent 7cd5375 commit 3a6c38f

File tree

9 files changed

+808
-112
lines changed

9 files changed

+808
-112
lines changed

KLF200Configurator/module.php

+87-43
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
* @property int $ParentID
2323
* @property array $Nodes
2424
* @property array $TempNodes
25+
* @property array $Scenes
26+
* @property array $TempScenes
2527
*/
2628
class KLF200Configurator extends IPSModule
2729
{
@@ -44,6 +46,8 @@ public function Create()
4446
//$this->GetNodeInfoIsRunning = false;
4547
$this->Nodes = [];
4648
$this->TempNodes = [];
49+
$this->Scenes = [];
50+
$this->TempScenes = [];
4751
$this->ParentID = 0;
4852
}
4953

@@ -61,7 +65,8 @@ public function ApplyChanges()
6165
$APICommands = [
6266
\KLF200\APICommand::GET_ALL_NODES_INFORMATION_NTF,
6367
\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
6570
];
6671

6772
if (count($APICommands) > 0) {
@@ -95,19 +100,6 @@ public function RequestAction($Ident, $Value)
95100
if ($this->IORequestAction($Ident, $Value)) {
96101
return true;
97102
}
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-
}*/
111103
return false;
112104
}
113105

@@ -155,6 +147,7 @@ public function RemoveNode(int $Node)
155147
return true;
156148
}
157149

150+
//todo scenes
158151
public function GetConfigurationForm()
159152
{
160153
$Form = json_decode(file_get_contents(__DIR__ . '/form.json'), true);
@@ -220,7 +213,6 @@ protected function IOChangeState($State)
220213
{
221214
if ($State == IS_ACTIVE) {
222215
$this->UpdateFormField('GatewayCommands', 'visible', true);
223-
//$this->GetAllNodesInformation();
224216
} else {
225217
$this->Nodes = [];
226218
$this->TempNodes = [];
@@ -232,24 +224,14 @@ protected function IOChangeState($State)
232224
$this->UpdateFormField('Config', 'values', json_encode($NodeValues));
233225
$this->UpdateFormField('RemoveNode', 'values', json_encode([]));
234226
$this->UpdateFormField('GatewayCommands', 'visible', false);
235-
//$this->ReloadForm();
236227
}
237228
}
238229
239-
protected function UpdateFormField($Name, $Field, $Value)
240-
{
241-
$this->SendDebug('Form: ' . $Name . '.' . $Field, $Value, 0);
242-
parent::UpdateFormField($Name, $Field, $Value);
243-
}
244-
245230
protected function SendDebug($Message, $Data, $Format)
246231
{
247232
if (is_a($Data, '\\KLF200\\APIData')) {
248233
/** @var \KLF200\APIData $Data */
249234
$this->SendDebugTrait($Message . ':Command', \KLF200\APICommand::ToString($Data->Command), 0);
250-
if ($Data->NodeID != -1) {
251-
$this->SendDebugTrait($Message . ':NodeID', $Data->NodeID, 0);
252-
}
253235
if ($Data->isError()) {
254236
$this->SendDebugTrait('Error', $Data->ErrorToString(), 0);
255237
} elseif ($Data->Data != '') {
@@ -272,7 +254,7 @@ private function ReceiveEvent(\KLF200\APIData $APIData)
272254
$this->SendDebug('NodeTypeSubType', $NodeTypeSubType, 0);
273255
$this->SendDebug('SerialNumber', substr($APIData->Data, 76, 8), 1);
274256
$this->SendDebug('BuildNumber', ord($APIData->Data[75]), 0);
275-
$Nodes = $this->TempNodes; //$this->Nodes;
257+
$Nodes = $this->TempNodes;
276258
$Nodes[$APIData->NodeID] = [
277259
'Name' => $Name,
278260
'NodeTypeSubType' => $NodeTypeSubType
@@ -282,17 +264,18 @@ private function ReceiveEvent(\KLF200\APIData $APIData)
282264
case \KLF200\APICommand::GET_ALL_NODES_INFORMATION_FINISHED_NTF:
283265
$this->Nodes = $this->TempNodes;
284266
$this->TempNodes = [];
267+
$this->SendDebug('END Nodes', '', 0);
285268
$Splitter = IPS_GetInstance($this->InstanceID)['ConnectionID'];
286269
$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)));
288272
$this->UpdateFormField('Config', 'visible', true);
289273
$this->UpdateFormField('GatewayCommands', 'visible', true);
290274
$this->UpdateFormField('ProgressLearn', 'visible', false);
291275
$DeleteNodeValues = $this->GetDeleteNodeConfigFormValues();
292276
$this->UpdateFormField('RemoveNode', 'values', json_encode($DeleteNodeValues));
293277
$this->UpdateFormField('RemoveNode', 'visible', true);
294278
$this->UpdateFormField('ProgressRemove', 'visible', false);
295-
//$this->GetNodeInfoIsRunning = false;
296279
break;
297280
case \KLF200\APICommand::NODE_INFORMATION_CHANGED_NTF:
298281
$Name = trim(substr($APIData->Data, 4, 64));
@@ -301,6 +284,29 @@ private function ReceiveEvent(\KLF200\APIData $APIData)
301284
$Nodes[$APIData->NodeID]['Name'] = $Name;
302285
$this->Nodes = $Nodes;
303286
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;
304310
}
305311
}
306312
@@ -325,19 +331,6 @@ private function GetConfigParam(&$item1, $InstanceID, $ConfigParam)
325331
$item1 = IPS_GetProperty($InstanceID, $ConfigParam);
326332
}
327333
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-
341334
/**
342335
* Interne Funktion des SDK.
343336
*/
@@ -377,10 +370,10 @@ private function GetNodeConfigFormValues(int $Splitter)
377370
$NodeValues[] = $AddValue;
378371
}
379372
380-
foreach ($InstanceIDListNodes as $InstanceIDNode => $Node) {
373+
foreach ($InstanceIDListNodes as $InstanceIDNode => $NodeID) {
381374
$NodeValues[] = [
382375
'instanceID' => $InstanceIDNode,
383-
'nodeid' => $Node,
376+
'nodeid' => $NodeID,
384377
'name' => IPS_GetName($InstanceIDNode),
385378
'type' => 'unknown',
386379
'location' => stristr(IPS_GetLocation($InstanceIDNode), IPS_GetName($InstanceIDNode), true)
@@ -389,6 +382,57 @@ private function GetNodeConfigFormValues(int $Splitter)
389382
return $NodeValues;
390383
}
391384
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+
392436
private function GetDeleteNodeConfigFormValues()
393437
{
394438
$NodeValues = [];

0 commit comments

Comments
 (0)