Skip to content

Commit

Permalink
Update Style
Browse files Browse the repository at this point in the history
  • Loading branch information
Sunnyka98 committed Nov 16, 2023
1 parent 6ede72a commit 9e1b5e5
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 98 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 2 files
+34 −30 .php-cs-fixer.php
+71 −71 json-check.php
190 changes: 95 additions & 95 deletions Schleppzeiger/module.php
Original file line number Diff line number Diff line change
@@ -1,119 +1,119 @@
<?php

declare(strict_types=1);
class Schleppzeiger extends IPSModule
class Schleppzeiger extends IPSModule
{
public function Create()
{
public function Create()
{
//Never delete this line!
parent::Create();

$this->RegisterPropertyInteger('Target', 0);
$this->RegisterPropertyInteger('Interval', 0);
$this->RegisterPropertyString('Option', 'Maximum');

if (!IPS_VariableProfileExists('SZ.Reset')) {
IPS_CreateVariableProfile('SZ.Reset', VARIABLETYPE_BOOLEAN);
IPS_SetVariableProfileAssociation('SZ.Reset', true, $this->Translate('Reset'), '', 0x00FF00);
}

$this->RegisterVariableFloat('TrailingPointer', $this->Translate('Trailing Pointer'), '', 0);
$this->RegisterVariableBoolean('Reset', $this->Translate('Reset'), 'SZ.Reset', 1);
$this->EnableAction('Reset');
//Never delete this line!
parent::Create();

$this->RegisterTimer('ResetTimer', 0, 'SZ_Reset($_IPS[\'TARGET\']);');
}
$this->RegisterPropertyInteger('Target', 0);
$this->RegisterPropertyInteger('Interval', 0);
$this->RegisterPropertyString('Option', 'Maximum');

public function Destroy()
{
//Never delete this line!
parent::Destroy();
if (!IPS_VariableProfileExists('SZ.Reset')) {
IPS_CreateVariableProfile('SZ.Reset', VARIABLETYPE_BOOLEAN);
IPS_SetVariableProfileAssociation('SZ.Reset', true, $this->Translate('Reset'), '', 0x00FF00);
}

public function ApplyChanges()
{
//Never delete this line!
parent::ApplyChanges();
$this->RegisterVariableFloat('TrailingPointer', $this->Translate('Trailing Pointer'), '', 0);
$this->RegisterVariableBoolean('Reset', $this->Translate('Reset'), 'SZ.Reset', 1);
$this->EnableAction('Reset');

$targetID = $this->ReadPropertyInteger('Target');
if (!IPS_VariableExists($targetID)) {
$this->SetStatus(200); //Target Variable is not valid
return;
}
$this->SetStatus(102);

//Reference
//Unregister
foreach ($this->GetReferenceList() as $id) {
$this->UnregisterReference($id);
}
$this->RegisterTimer('ResetTimer', 0, 'SZ_Reset($_IPS[\'TARGET\']);');
}

//Register
$this->RegisterReference($targetID);
public function Destroy()
{
//Never delete this line!
parent::Destroy();
}

//Messages
//Unregister all messages
foreach ($this->GetMessageList() as $senderID => $messages) {
foreach ($messages as $message) {
$this->UnregisterMessage($senderID, $message);
}
}
public function ApplyChanges()
{
//Never delete this line!
parent::ApplyChanges();

//Register necessary messages
$this->RegisterMessage($this->GetIDForIdent('Reset'), VM_UPDATE);
$this->RegisterMessage($targetID, VM_UPDATE);
$targetID = $this->ReadPropertyInteger('Target');
if (!IPS_VariableExists($targetID)) {
$this->SetStatus(200); //Target Variable is not valid
return;
}
$this->SetStatus(102);

//Set TimerInterval
$this->SetTimerInterval('ResetTimer', $this->ReadPropertyInteger('Interval') * 1000);
//Reference
//Unregister
foreach ($this->GetReferenceList() as $id) {
$this->UnregisterReference($id);
}

public function RequestAction($Ident, $Value)
{
switch ($Ident) {
case 'Reset':
$this->Reset();
break;
default:
$this->SetValue($Ident, $Value);
break;
//Register
$this->RegisterReference($targetID);

//Messages
//Unregister all messages
foreach ($this->GetMessageList() as $senderID => $messages) {
foreach ($messages as $message) {
$this->UnregisterMessage($senderID, $message);
}
}

public function Reset()
{
$this->SetValue('TrailingPointer', GetValue($this->ReadPropertyInteger('Target')));
$this->SetTimerInterval('ResetTimer', $this->ReadPropertyInteger('Interval') * 1000);
//Register necessary messages
$this->RegisterMessage($this->GetIDForIdent('Reset'), VM_UPDATE);
$this->RegisterMessage($targetID, VM_UPDATE);

//Set TimerInterval
$this->SetTimerInterval('ResetTimer', $this->ReadPropertyInteger('Interval') * 1000);
}

public function RequestAction($Ident, $Value)
{
switch ($Ident) {
case 'Reset':
$this->Reset();
break;
default:
$this->SetValue($Ident, $Value);
break;
}
}

public function MessageSink($timestamp, $sendId, $messageID, $data)
{
if ($messageID == VM_UPDATE) {
if ($sendId == $this->GetIDForIdent('Reset')) {
$this->Reset();
} elseif ($sendId == $this->ReadPropertyInteger('Target')) {
$this->trailingTarget($data[0]);
}
public function Reset()
{
$this->SetValue('TrailingPointer', GetValue($this->ReadPropertyInteger('Target')));
$this->SetTimerInterval('ResetTimer', $this->ReadPropertyInteger('Interval') * 1000);
}

public function MessageSink($timestamp, $sendId, $messageID, $data)
{
if ($messageID == VM_UPDATE) {
if ($sendId == $this->GetIDForIdent('Reset')) {
$this->Reset();
} elseif ($sendId == $this->ReadPropertyInteger('Target')) {
$this->trailingTarget($data[0]);
}
}
}

private function trailingTarget($value)
{
$currentValue = $this->GetValue('TrailingPointer');

switch ($this->ReadPropertyString('Option')) {
case 'Maximum':
if ($value > $currentValue) {
$this->SetValue('TrailingPointer', $value);
}
break;
case 'Minimum':
if ($value < $currentValue) {
$this->SetValue('TrailingPointer', $value);
}
break;
default:
$this->SendDebug('Not Supported', 'Current Option is not supported', 0);
break;
}
private function trailingTarget($value)
{
$currentValue = $this->GetValue('TrailingPointer');

switch ($this->ReadPropertyString('Option')) {
case 'Maximum':
if ($value > $currentValue) {
$this->SetValue('TrailingPointer', $value);
}
break;
case 'Minimum':
if ($value < $currentValue) {
$this->SetValue('TrailingPointer', $value);
}
break;
default:
$this->SendDebug('Not Supported', 'Current Option is not supported', 0);
break;
}
}
}
}

0 comments on commit 9e1b5e5

Please sign in to comment.