Skip to content

Commit

Permalink
Version 1.00
Browse files Browse the repository at this point in the history
  • Loading branch information
Nall-chan committed Jan 5, 2024
1 parent 9cc76ea commit 04f974c
Show file tree
Hide file tree
Showing 14 changed files with 601 additions and 160 deletions.
2 changes: 1 addition & 1 deletion KLF200Configurator/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[![SDK](https://img.shields.io/badge/Symcon-PHPModul-red.svg?style=flat-square)](https://www.symcon.de/service/dokumentation/entwicklerbereich/sdk-tools/sdk-php/)
[![Version](https://img.shields.io/badge/Modul%20Version-0.80-blue.svg?style=flat-square)](https://community.symcon.de/t/modul-velux-klf200/50429)
[![Version](https://img.shields.io/badge/Modul%20Version-1.00-blue.svg?style=flat-square)](https://community.symcon.de/t/modul-velux-klf200/50429)
[![Version](https://img.shields.io/badge/Symcon%20Version-6.0%20%3E-green.svg?style=flat-square)](https://www.symcon.de/de/service/dokumentation/installation/migrationen/v55-v60-q3-2021/)
[![License](https://img.shields.io/badge/License-CC%20BY--NC--SA%204.0-green.svg?style=flat-square)](https://creativecommons.org/licenses/by-nc-sa/4.0/)
[![Check Style](https://github.com/Nall-chan/VeluxKLF200/workflows/Check%20Style/badge.svg)](https://github.com/Nall-chan/VeluxKLF200/actions) [![Run Tests](https://github.com/Nall-chan/VeluxKLF200/workflows/Run%20Tests/badge.svg)](https://github.com/Nall-chan/VeluxKLF200/actions)
Expand Down
59 changes: 30 additions & 29 deletions KLF200Configurator/module.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
* @copyright 2024 Michael Tröger
* @license https://creativecommons.org/licenses/by-nc-sa/4.0/ CC BY-NC-SA 4.0
*
* @version 0.80
* @version 1.00
*
* @method void RegisterParent()
*
* @property int $ParentID
* @property array $Nodes
* @property bool $GetNodeInfoIsRunning
* @property array $TempNodes
*/
class KLF200Configurator extends IPSModule
{
Expand All @@ -41,8 +41,9 @@ public function Create()
{
parent::Create();
$this->RequireParent(\KLF200\GUID::Gateway);
$this->GetNodeInfoIsRunning = false;
//$this->GetNodeInfoIsRunning = false;
$this->Nodes = [];
$this->TempNodes = [];
$this->ParentID = 0;
}

Expand All @@ -56,15 +57,11 @@ public function ApplyChanges()
$this->RegisterMessage($this->InstanceID, FM_DISCONNECT);

parent::ApplyChanges();

$APICommands = [
\KLF200\APICommand::GET_ALL_GROUPS_INFORMATION_NTF,
\KLF200\APICommand::GET_ALL_GROUPS_INFORMATION_FINISHED_NTF,
\KLF200\APICommand::GET_ALL_NODES_INFORMATION_NTF,
\KLF200\APICommand::GET_ALL_NODES_INFORMATION_FINISHED_NTF,
\KLF200\APICommand::GET_SCENE_INFORMATION_NTF,
\KLF200\APICommand::GET_SCENE_LIST_NTF,
\KLF200\APICommand::CS_DISCOVER_NODES_NTF,
\KLF200\APICommand::CS_SYSTEM_TABLE_UPDATE_NTF
\KLF200\APICommand::NODE_INFORMATION_CHANGED_NTF
];

if (count($APICommands) > 0) {
Expand Down Expand Up @@ -98,6 +95,7 @@ public function RequestAction($Ident, $Value)
if ($this->IORequestAction($Ident, $Value)) {
return true;
}
/*
if ($Ident == 'GetAllNodesInformation') {
if ($Value) {
if ($this->GetAllNodesInformation()) {
Expand All @@ -109,7 +107,7 @@ public function RequestAction($Ident, $Value)
} else {
return $this->GetAllNodesInformation();
}
}
}*/
return false;
}

Expand Down Expand Up @@ -222,9 +220,10 @@ protected function IOChangeState($State)
{
if ($State == IS_ACTIVE) {
$this->UpdateFormField('GatewayCommands', 'visible', true);
$this->GetAllNodesInformation();
//$this->GetAllNodesInformation();
} else {
$this->Nodes = [];
$this->TempNodes = [];
$NodeValues = [];
$Splitter = IPS_GetInstance($this->InstanceID)['ConnectionID'];
if ($Splitter > 0) {
Expand All @@ -233,6 +232,7 @@ protected function IOChangeState($State)
$this->UpdateFormField('Config', 'values', json_encode($NodeValues));
$this->UpdateFormField('RemoveNode', 'values', json_encode([]));
$this->UpdateFormField('GatewayCommands', 'visible', false);
//$this->ReloadForm();
}
}
Expand All @@ -247,6 +247,9 @@ protected function SendDebug($Message, $Data, $Format)
if (is_a($Data, '\\KLF200\\APIData')) {
/** @var \KLF200\APIData $Data */
$this->SendDebugTrait($Message . ':Command', \KLF200\APICommand::ToString($Data->Command), 0);
if ($Data->NodeID != -1) {
$this->SendDebugTrait($Message . ':NodeID', $Data->NodeID, 0);
}
if ($Data->isError()) {
$this->SendDebugTrait('Error', $Data->ErrorToString(), 0);
} elseif ($Data->Data != '') {
Expand All @@ -260,34 +263,25 @@ protected function SendDebug($Message, $Data, $Format)
private function ReceiveEvent(\KLF200\APIData $APIData)
{
switch ($APIData->Command) {
case \KLF200\APICommand::CS_DISCOVER_NODES_NTF:
if (!$this->GetNodeInfoIsRunning) {
IPS_RunScriptText('IPS_RequestAction(' . $this->InstanceID . ',"GetAllNodesInformation",false);');
}
break;
case \KLF200\APICommand::CS_SYSTEM_TABLE_UPDATE_NTF:
sleep(3);
if (!$this->GetNodeInfoIsRunning) {
IPS_RunScriptText('IPS_RequestAction(' . $this->InstanceID . ',"GetAllNodesInformation",false);');
}
break;
case \KLF200\APICommand::GET_ALL_NODES_INFORMATION_NTF:
$NodeID = ord($APIData->Data[0]);
$Name = trim(substr($APIData->Data, 4, 64));
$NodeTypeSubType = unpack('n', substr($APIData->Data, 69, 2))[1];
$this->SendDebug('NodeID', $NodeID, 0);
$this->SendDebug('NodeID (' . $APIData->NodeID . ')', $NodeID, 0);
$this->SendDebug('Name', $Name, 0);
$this->SendDebug('NodeTypeSubType', $NodeTypeSubType, 0);
$this->SendDebug('SerialNumber', substr($APIData->Data, 76, 8), 1);
$this->SendDebug('BuildNumber', ord($APIData->Data[75]), 0);
$Nodes = $this->Nodes;
$Nodes[$NodeID] = [
$Nodes = $this->TempNodes; //$this->Nodes;
$Nodes[$APIData->NodeID] = [
'Name' => $Name,
'NodeTypeSubType' => $NodeTypeSubType
];
$this->Nodes = $Nodes;
$this->TempNodes = $Nodes;
break;
case \KLF200\APICommand::GET_ALL_NODES_INFORMATION_FINISHED_NTF:
$this->Nodes = $this->TempNodes;
$this->TempNodes = [];
$Splitter = IPS_GetInstance($this->InstanceID)['ConnectionID'];
$NodeValues = $this->GetNodeConfigFormValues($Splitter);
$this->UpdateFormField('Config', 'values', json_encode($NodeValues));
Expand All @@ -298,7 +292,14 @@ private function ReceiveEvent(\KLF200\APIData $APIData)
$this->UpdateFormField('RemoveNode', 'values', json_encode($DeleteNodeValues));
$this->UpdateFormField('RemoveNode', 'visible', true);
$this->UpdateFormField('ProgressRemove', 'visible', false);
$this->GetNodeInfoIsRunning = false;
//$this->GetNodeInfoIsRunning = false;
break;
case \KLF200\APICommand::NODE_INFORMATION_CHANGED_NTF:
$Name = trim(substr($APIData->Data, 4, 64));
$this->SendDebug('Name', $Name, 0);
$Nodes = $this->Nodes;
$Nodes[$APIData->NodeID]['Name'] = $Name;
$this->Nodes = $Nodes;
break;
}
}
Expand All @@ -324,7 +325,7 @@ private function GetConfigParam(&$item1, $InstanceID, $ConfigParam)
$item1 = IPS_GetProperty($InstanceID, $ConfigParam);
}
private function GetAllNodesInformation()
/*private function GetAllNodesInformation()
{
$this->Nodes = [];
Expand All @@ -335,7 +336,7 @@ private function GetAllNodesInformation()
}
$this->GetNodeInfoIsRunning = true;
return ord($ResultAPIData->Data[0]) == 1;
}
}*/
/**
* Interne Funktion des SDK.
Expand Down
2 changes: 1 addition & 1 deletion KLF200Discovery/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[![SDK](https://img.shields.io/badge/Symcon-PHPModul-red.svg?style=flat-square)](https://www.symcon.de/service/dokumentation/entwicklerbereich/sdk-tools/sdk-php/)
[![Version](https://img.shields.io/badge/Modul%20Version-0.80-blue.svg?style=flat-square)](https://community.symcon.de/t/modul-velux-klf200/50429)
[![Version](https://img.shields.io/badge/Modul%20Version-1.00-blue.svg?style=flat-square)](https://community.symcon.de/t/modul-velux-klf200/50429)
[![Version](https://img.shields.io/badge/Symcon%20Version-6.0%20%3E-green.svg?style=flat-square)](https://www.symcon.de/de/service/dokumentation/installation/migrationen/v55-v60-q3-2021/)
[![License](https://img.shields.io/badge/License-CC%20BY--NC--SA%204.0-green.svg?style=flat-square)](https://creativecommons.org/licenses/by-nc-sa/4.0/)
[![Check Style](https://github.com/Nall-chan/VeluxKLF200/workflows/Check%20Style/badge.svg)](https://github.com/Nall-chan/VeluxKLF200/actions) [![Run Tests](https://github.com/Nall-chan/VeluxKLF200/workflows/Run%20Tests/badge.svg)](https://github.com/Nall-chan/VeluxKLF200/actions)
Expand Down
2 changes: 1 addition & 1 deletion KLF200Discovery/module.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* @copyright 2024 Michael Tröger
* @license https://creativecommons.org/licenses/by-nc-sa/4.0/ CC BY-NC-SA 4.0
*
* @version 0.80
* @version 1.00
*
* @method bool SendDebug(string $Message, mixed $Data, int $Format)
*/
Expand Down
2 changes: 1 addition & 1 deletion KLF200Gateway/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[![SDK](https://img.shields.io/badge/Symcon-PHPModul-red.svg?style=flat-square)](https://www.symcon.de/service/dokumentation/entwicklerbereich/sdk-tools/sdk-php/)
[![Version](https://img.shields.io/badge/Modul%20Version-0.80-blue.svg?style=flat-square)](https://community.symcon.de/t/modul-velux-klf200/50429)
[![Version](https://img.shields.io/badge/Modul%20Version-1.00-blue.svg?style=flat-square)](https://community.symcon.de/t/modul-velux-klf200/50429)
[![Version](https://img.shields.io/badge/Symcon%20Version-6.0%20%3E-green.svg?style=flat-square)](https://www.symcon.de/de/service/dokumentation/installation/migrationen/v55-v60-q3-2021/)
[![License](https://img.shields.io/badge/License-CC%20BY--NC--SA%204.0-green.svg?style=flat-square)](https://creativecommons.org/licenses/by-nc-sa/4.0/)
[![Check Style](https://github.com/Nall-chan/VeluxKLF200/workflows/Check%20Style/badge.svg)](https://github.com/Nall-chan/VeluxKLF200/actions) [![Run Tests](https://github.com/Nall-chan/VeluxKLF200/workflows/Run%20Tests/badge.svg)](https://github.com/Nall-chan/VeluxKLF200/actions)
Expand Down
51 changes: 50 additions & 1 deletion KLF200Gateway/module.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* @copyright 2024 Michael Tröger
* @license https://creativecommons.org/licenses/by-nc-sa/4.0/ CC BY-NC-SA 4.0
*
* @version 0.80
* @version 1.00
*
* @method bool lock(string $ident)
* @method void unlock(string $ident)
Expand All @@ -32,6 +32,7 @@
* @property array $Nodes
* @property int $WaitForNodes
* @property int $SessionId
* @property bool $GetNodeInfoIsRunning
*/
class KLF200Gateway extends IPSModule
{
Expand Down Expand Up @@ -63,6 +64,7 @@ public function Create()

$this->ReceiveBuffer = '';
$this->ReplyAPIData = null;
$this->GetNodeInfoIsRunning = false;
$this->Nodes = [];

if (IPS_GetKernelRunlevel() != KR_READY) {
Expand Down Expand Up @@ -93,6 +95,18 @@ public function RequestAction($Ident, $Value)
if ($this->IORequestAction($Ident, $Value)) {
return true;
}
if ($Ident == 'GetAllNodesInformation') {
if ($Value) {
if ($this->GetAllNodesInformation()) {
while ($this->GetNodeInfoIsRunning) {
IPS_Sleep(10);
}
return true;
}
} else {
return $this->GetAllNodesInformation();
}
}
return false;
}

Expand Down Expand Up @@ -346,6 +360,7 @@ protected function IOChangeState($State)
$this->ReadGatewayState();
$this->RequestGatewayVersion();
$this->SetHouseStatusMonitor();
$this->GetAllNodesInformation();
} else {
$this->SetTimerInterval(\KLF200\Gateway\Timer::KeepAlive, 0);
}
Expand All @@ -360,6 +375,9 @@ protected function SendDebug($Message, $Data, $Format)
if (is_a($Data, '\\KLF200\\APIData')) {
/** @var \KLF200\APIData $Data */
$this->SendDebugTrait($Message . ':Command', \KLF200\APICommand::ToString($Data->Command), 0);
if ($Data->NodeID != -1) {
$this->SendDebugTrait($Message . ':NodeID', $Data->NodeID, 0);
}
if ($Data->isError()) {
$this->SendDebugTrait('Error', $Data->ErrorToString(), 0);
} elseif ($Data->Data != '') {
Expand All @@ -370,13 +388,27 @@ protected function SendDebug($Message, $Data, $Format)
}
}

private function GetAllNodesInformation()
{
$this->Nodes = [];

$APIData = new \KLF200\APIData(\KLF200\APICommand::GET_ALL_NODES_INFORMATION_REQ);
$ResultAPIData = $this->SendAPIData($APIData);
if ($ResultAPIData->isError()) {
return false;
}
$this->GetNodeInfoIsRunning = true;
return ord($ResultAPIData->Data[0]) == 1;
}

/*
public function GetSceneList()
{
$APIData = new \KLF200\APIData(\KLF200\APICommand::GET_SCENE_LIST_REQ);
$ResultAPIData = $this->SendAPIData($APIData);
}
*/

private function SetHouseStatusMonitor()
{
$APIData = new \KLF200\APIData(\KLF200\APICommand::HOUSE_STATUS_MONITOR_ENABLE_REQ);
Expand All @@ -387,6 +419,23 @@ private function SetHouseStatusMonitor()
//################# PRIVATE
private function ReceiveEvent(\KLF200\APIData $APIData)
{
switch ($APIData->Command) {
case \KLF200\APICommand::CS_DISCOVER_NODES_NTF:
sleep(3);
if (!$this->GetNodeInfoIsRunning) {
IPS_RunScriptText('IPS_RequestAction(' . $this->InstanceID . ',"GetAllNodesInformation",false);');
}
break;
case \KLF200\APICommand::CS_SYSTEM_TABLE_UPDATE_NTF:
sleep(3);
if (!$this->GetNodeInfoIsRunning) {
IPS_RunScriptText('IPS_RequestAction(' . $this->InstanceID . ',"GetAllNodesInformation",false);');
}
break;
case \KLF200\APICommand::GET_ALL_NODES_INFORMATION_FINISHED_NTF:
$this->GetNodeInfoIsRunning = false;
break;
}
$this->SendAPIDataToChildren($APIData);
}

Expand Down
29 changes: 27 additions & 2 deletions KLF200Node/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[![SDK](https://img.shields.io/badge/Symcon-PHPModul-red.svg?style=flat-square)](https://www.symcon.de/service/dokumentation/entwicklerbereich/sdk-tools/sdk-php/)
[![Version](https://img.shields.io/badge/Modul%20Version-0.80-blue.svg?style=flat-square)](https://community.symcon.de/t/modul-velux-klf200/50429)
[![Version](https://img.shields.io/badge/Modul%20Version-1.00-blue.svg?style=flat-square)](https://community.symcon.de/t/modul-velux-klf200/50429)
[![Version](https://img.shields.io/badge/Symcon%20Version-6.0%20%3E-green.svg?style=flat-square)](https://www.symcon.de/de/service/dokumentation/installation/migrationen/v55-v60-q3-2021/)
[![License](https://img.shields.io/badge/License-CC%20BY--NC--SA%204.0-green.svg?style=flat-square)](https://creativecommons.org/licenses/by-nc-sa/4.0/)
[![Check Style](https://github.com/Nall-chan/VeluxKLF200/workflows/Check%20Style/badge.svg)](https://github.com/Nall-chan/VeluxKLF200/actions) [![Run Tests](https://github.com/Nall-chan/VeluxKLF200/workflows/Run%20Tests/badge.svg)](https://github.com/Nall-chan/VeluxKLF200/actions)
Expand Down Expand Up @@ -51,15 +51,39 @@ Bei der manuellen Einrichtung ist das Modul im Dialog `Instanz hinzufügen` unte
![Instanz hinzufügen](../imgs/instanzen.png)

In dem sich öffnenden Konfigurationsformular ist die `Node ID` des Gerätes einzutragen.
![Konfiguration](../imgs/conf_node.png)

## 5. Statusvariablen und Profile
**Konfigurationsseite (Parameter)**

| Name | Text |
| -------------------- | ------------------------------------------------------- |
| NodeId | Node ID |
| WaitForFinishSession | Auf Zustand vom Gerät warten (*) |
| AutoRename | Instanz umbenennen, wenn sich der Name in KLF200 ändert |

**(*) Wichtig:**
Wird diese Option aktiviert, so wartet die Instanz bei einer Ansteuerung eines Gerätes auf die Beendigung der Aktion!
Solange die Aktion noch läuft und das Gerät nicht 'fertig' (oder Fehler) gemeldet hat, wird im WebFront die Aktion auch als laufend Angezeigt bzw. wird ein PHP-Skript welches eine Aktion mit `KLF200_SetMainParameter` gestartet hat, blockiert.
Der Vorteil ist jedoch, sollte ein Gerät seine Aktion nicht abschließen können, so wird die Fehlermeldung unmittelbar im WebFront bzw. PHP-Skript ausgegeben.

Ist diese Option inaktiv, so wird nur das Zustellen des Befehls an das KLF200 und die empfangene Quittung ausgewertet. Sollte dann beim ausführen der Aktion das Gerät einen Fehler melden, so ist dies nur im Logfile bzw. Meldungslog zu finden.


## 5. Statusvariablen und Profile

Die Statusvariablen werden je nach Geräte-Typ des Nodes angelegt oder auch wieder entfernt.
Es werden folgende Statusvariablen verwendet: 'MAIN', 'FP1', 'FP2' und 'FP3'.
Dabei entsprechen die Werte und Aktionen dem jeweiligen Funktions-Parameter, welche bei jedem Geräte-Typ (NodeSubType) unterschiedlich sind.
Entsprechend sind auch der Name und das Profil beim anlegen der Instanz je nach Geräte-Typ unterschiedlich.

**Statusvariablen allgemein:**

| Name | Typ | Ident | Beschreibung |
| :----------------- | :------ | :------------- | :---------------------------------------- |
| letzte Aktivierung | integer | LastActivation | Quelle der letzte Ansteuerung des Gerätes |
| zuletzt gesehen | integer | LastSeen | UnixTimestamp der letzten Meldung |
| letzter Fehler | string | ErrorState | Letzter Fehlerstatus |

**Statusvariable MAIN:**

| Name | Typ | Ident | Beschreibung |
Expand Down Expand Up @@ -95,6 +119,7 @@ Entsprechend sind auch der Name und das Profil beim anlegen der Instanz je nach

| Name | Typ | verwendet von Statusvariablen (Ident) |
| :-------------------------- | :------ | :------------------------------------- |
| KLF200.StatusOwner | integer | STATUS |
| KLF200.Light.Reversed | boolean | MAIN |
| KLF200.Lock | boolean | MAIN |
| KLF200.Blind | integer | MAIN |
Expand Down
10 changes: 10 additions & 0 deletions KLF200Node/form.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@
"name": "NodeId",
"type": "NumberSpinner",
"caption": "Node ID"
},
{
"name": "WaitForFinishSession",
"type": "CheckBox",
"caption": "Wait for the status of the device"
},
{
"name": "AutoRename",
"type": "CheckBox",
"caption": "Rename the instance if the name changes in the KLF200"
}
],
"actions": [
Expand Down
Loading

0 comments on commit 04f974c

Please sign in to comment.