Skip to content

Commit

Permalink
Update style
Browse files Browse the repository at this point in the history
  • Loading branch information
Sunnyka98 committed Nov 15, 2023
1 parent 4d6a726 commit 5d2c123
Show file tree
Hide file tree
Showing 4 changed files with 157 additions and 156 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/style.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ jobs:
- name: Checkout module
uses: actions/checkout@master
- name: Check style
uses: symcon/action-style@master
uses: symcon/action-style@v3
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.DS_Store
.idea/
.phpunit.*
.php_cs.cache
.php_cs.cache
.php-cs-fixer.cache
2 changes: 1 addition & 1 deletion .style
Submodule .style updated 3 files
+36 −32 .php-cs-fixer.php
+22 −0 README.md
+85 −0 json-check.php
306 changes: 153 additions & 153 deletions Gruppensteuerung/module.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,193 +2,193 @@

declare(strict_types=1);

class Gruppensteuerung extends IPSModule
class Gruppensteuerung extends IPSModule
{
public function Create()
{
public function Create()
{
//Never delete this line!
parent::Create();
//Never delete this line!
parent::Create();

//Properties
$this->RegisterPropertyBoolean('Active', false);
$this->RegisterPropertyString('Variables', '[]');
}
//Properties
$this->RegisterPropertyBoolean('Active', false);
$this->RegisterPropertyString('Variables', '[]');
}

public function Destroy()
{
//Never delete this line!
parent::Destroy();
}
public function Destroy()
{
//Never delete this line!
parent::Destroy();
}

public function ApplyChanges()
{
//Never delete this line!
parent::ApplyChanges();
public function ApplyChanges()
{
//Never delete this line!
parent::ApplyChanges();

$variables = json_decode($this->ReadPropertyString('Variables'), true);
$variables = json_decode($this->ReadPropertyString('Variables'), true);

//Register references
foreach ($this->GetReferenceList() as $referenceID) {
$this->UnregisterReference($referenceID);
}
//Register references
foreach ($this->GetReferenceList() as $referenceID) {
$this->UnregisterReference($referenceID);
}

foreach ($variables as $variable) {
$this->RegisterReference($variable['VariableID']);
}
foreach ($variables as $variable) {
$this->RegisterReference($variable['VariableID']);
}

$this->setUpModule();
$this->setUpModule();

if ($this->GetStatus() != 102) {
return;
}
if ($this->GetStatus() != 102) {
return;
}

//Register messages
$messageList = array_keys($this->GetMessageList());
foreach ($messageList as $message) {
$this->UnregisterMessage($message, VM_UPDATE);
}
foreach ($variables as $variable) {
$this->RegisterMessage($variable['VariableID'], VM_UPDATE);
}
//Register messages
$messageList = array_keys($this->GetMessageList());
foreach ($messageList as $message) {
$this->UnregisterMessage($message, VM_UPDATE);
}
foreach ($variables as $variable) {
$this->RegisterMessage($variable['VariableID'], VM_UPDATE);
}
}

public function MessageSink($Timestamp, $SenderID, $MessageID, $Data)
{
$this->SendDebug('MessageSink', IPS_GetName($SenderID), 0);
$this->RequestAction('Status', $Data[0]);
public function MessageSink($Timestamp, $SenderID, $MessageID, $Data)
{
$this->SendDebug('MessageSink', IPS_GetName($SenderID), 0);
$this->RequestAction('Status', $Data[0]);
}

public function RequestAction($Ident, $Value)
{
switch ($Ident) {
case 'Status':
$this->SwitchGroup($Value);
break;
default:
throw new Exception('InvalidIdent');
}
}

public function RequestAction($Ident, $Value)
{
switch ($Ident) {
case 'Status':
$this->SwitchGroup($Value);
break;
default:
throw new Exception('InvalidIdent');
}
private function getProfile($variableID)
{
$variableData = IPS_GetVariable($variableID);
if ($variableData['VariableCustomProfile'] == '') {
return $variableData['VariableProfile'];
} else {
return $variableData['VariableCustomProfile'];
}
}

private function getProfile($variableID)
{
$variableData = IPS_GetVariable($variableID);
if ($variableData['VariableCustomProfile'] == '') {
return $variableData['VariableProfile'];
} else {
return $variableData['VariableCustomProfile'];
}
private function getType($variableID)
{
return IPS_GetVariable($variableID)['VariableType'];
}

private function setUpModule()
{
//Active
if (!$this->ReadPropertyBoolean('Active')) {
$this->SetStatus(104);
return;
}

private function getType($variableID)
{
return IPS_GetVariable($variableID)['VariableType'];
$variables = json_decode($this->ReadPropertyString('Variables'), true);

//List empty
if (count($variables) <= 0) {
$this->SetStatus(204);
return;
}

private function setUpModule()
{
//Active
if (!$this->ReadPropertyBoolean('Active')) {
$this->SetStatus(104);
//Exist
foreach ($variables as $variable) {
if (!IPS_VariableExists($variable['VariableID'])) {
$this->SetStatus(203);
return;
}

$variables = json_decode($this->ReadPropertyString('Variables'), true);

//List empty
if (count($variables) <= 0) {
$this->SetStatus(204);
}
//ReferenceVariable
$referenceVariableID = $variables[0]['VariableID'];
$referenceType = $this->getType($referenceVariableID);
$referenceProfile = $this->getProfile($referenceVariableID);

//Same type
foreach ($variables as $variable) {
if ($this->getType($variable['VariableID']) != $referenceType) {
$this->SetStatus(200);
return;
}
}

//Exist
foreach ($variables as $variable) {
if (!IPS_VariableExists($variable['VariableID'])) {
$this->SetStatus(203);
return;
}
//Same profile
foreach ($variables as $variable) {
if ($this->getProfile($variable['VariableID']) != $referenceProfile) {
$this->SetStatus(201);
return;
}
//ReferenceVariable
$referenceVariableID = $variables[0]['VariableID'];
$referenceType = $this->getType($referenceVariableID);
$referenceProfile = $this->getProfile($referenceVariableID);
}

//Same type
foreach ($variables as $variable) {
if ($this->getType($variable['VariableID']) != $referenceType) {
$this->SetStatus(200);
return;
}
}
//Register variable of needed type with correct profile
$statusVariableID = @$this->GetIDForIdent('Status');
//StatusVariableID could be false. In order to prevent false beeing used in VariableExist we use intval() and convert it to 0
if (IPS_VariableExists(intval($statusVariableID)) && ($referenceType != $this->getType($statusVariableID))) {
$this->UnregisterVariable('Status');
}
//Update profile of status if necessary
switch ($referenceType) {
case 0:
$this->RegisterVariableBoolean('Status', $this->Translate('Status'), $referenceProfile, 0);
break;

case 1:
$this->RegisterVariableInteger('Status', $this->Translate('Status'), $referenceProfile, 0);
break;

case 2:
$this->RegisterVariableFloat('Status', $this->Translate('Status'), $referenceProfile, 0);
break;

case 3:
$this->RegisterVariableString('Status', $this->Translate('Status'), $referenceProfile, 0);
break;
}
$this->EnableAction('Status');

//Same profile
foreach ($variables as $variable) {
if ($this->getProfile($variable['VariableID']) != $referenceProfile) {
$this->SetStatus(201);
return;
}
//Have action
foreach ($variables as $variable) {
if (!HasAction($variable['VariableID'])) {
$this->SetStatus(202);
return;
}
}

//Register variable of needed type with correct profile
$statusVariableID = @$this->GetIDForIdent('Status');
//StatusVariableID could be false. In order to prevent false beeing used in VariableExist we use intval() and convert it to 0
if (IPS_VariableExists(intval($statusVariableID)) && ($referenceType != $this->getType($statusVariableID))) {
$this->UnregisterVariable('Status');
}
//Update profile of status if necessary
switch ($referenceType) {
case 0:
$this->RegisterVariableBoolean('Status', $this->Translate('Status'), $referenceProfile, 0);
break;

case 1:
$this->RegisterVariableInteger('Status', $this->Translate('Status'), $referenceProfile, 0);
break;

case 2:
$this->RegisterVariableFloat('Status', $this->Translate('Status'), $referenceProfile, 0);
break;

case 3:
$this->RegisterVariableString('Status', $this->Translate('Status'), $referenceProfile, 0);
break;
}
$this->EnableAction('Status');
//Everything ok
$this->SetStatus(102);
return;
}

private function SwitchGroup($value)
{
$this->setUpModule();
$instanceStatus = $this->GetStatus();
if (($instanceStatus == 102) && ($value != $this->GetValue('Status'))) {
$this->SetValue('Status', $value);
$variables = json_decode($this->ReadPropertyString('Variables'), true);

//Have action
foreach ($variables as $variable) {
if (!HasAction($variable['VariableID'])) {
$this->SetStatus(202);
return;
if (GetValue($variable['VariableID']) != $value && HasAction($variable['VariableID'])) {
RequestAction($variable['VariableID'], $value);
} elseif (!HasAction($variable['VariableID'])) {
throw new Exception('One variable has no action.');
}
}

//Everything ok
$this->SetStatus(102);
return;
}

private function SwitchGroup($value)
{
$this->setUpModule();
$instanceStatus = $this->GetStatus();
if (($instanceStatus == 102) && ($value != $this->GetValue('Status'))) {
$this->SetValue('Status', $value);
$variables = json_decode($this->ReadPropertyString('Variables'), true);

foreach ($variables as $variable) {
if (GetValue($variable['VariableID']) != $value && HasAction($variable['VariableID'])) {
RequestAction($variable['VariableID'], $value);
} elseif (!HasAction($variable['VariableID'])) {
throw new Exception('One variable has no action.');
}
}
} elseif ($instanceStatus != 102) {
$statuscodes = [];
$statusForm = json_decode(IPS_GetConfigurationForm($this->InstanceID), true)['status'];
foreach ($statusForm as $status) {
$statuscodes[$status['code']] = $status['caption'];
}
$this->LogMessage($this->Translate($statuscodes[$instanceStatus]), KL_ERROR);
} elseif ($instanceStatus != 102) {
$statuscodes = [];
$statusForm = json_decode(IPS_GetConfigurationForm($this->InstanceID), true)['status'];
foreach ($statusForm as $status) {
$statuscodes[$status['code']] = $status['caption'];
}
$this->LogMessage($this->Translate($statuscodes[$instanceStatus]), KL_ERROR);
}
}
}

0 comments on commit 5d2c123

Please sign in to comment.