Skip to content

Commit

Permalink
Merge pull request #15 from symcon/fixes/upgrade-style-to-v3
Browse files Browse the repository at this point in the history
Update Style
  • Loading branch information
Sunnyka98 authored Nov 16, 2023
2 parents d785a3f + 95c7649 commit fdcb7e1
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 86 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
+42 −33 .php-cs-fixer.php
+22 −0 README.md
+85 −0 json-check.php
17 changes: 12 additions & 5 deletions ZaehlerUeberlauf/form.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
{
"elements":
[
{ "name": "SourceVariable", "type": "SelectVariable", "caption": "Source" },
{ "name": "MaximumValue", "type": "NumberSpinner", "caption": "Maximum value" }
]
"elements": [
{
"name": "SourceVariable",
"type": "SelectVariable",
"caption": "Source"
},
{
"name": "MaximumValue",
"type": "NumberSpinner",
"caption": "Maximum value"
}
]
}
14 changes: 7 additions & 7 deletions ZaehlerUeberlauf/locale.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"translations": {
"de": {
"Source": "Quelle",
"Maximum value": "Maximalwert",
"Counter": "Zähler"
}
}
"translations": {
"de": {
"Source": "Quelle",
"Maximum value": "Maximalwert",
"Counter": "Zähler"
}
}
}
25 changes: 12 additions & 13 deletions ZaehlerUeberlauf/module.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
{
"id": "{57A84449-AA15-4423-80B0-3F98C54EAC03}",
"name": "ZaehlerUeberlauf",
"type": 3,
"vendor": "",
"aliases":
[
"Zählerüberlauf"
],
"parentRequirements": [],
"childRequirements": [],
"implemented": [],
"prefix": "ZUL",
"url": "https://github.com/symcon/ZaehlerUeberlauf/tree/master/ZaehlerUeberlauf"
"id": "{57A84449-AA15-4423-80B0-3F98C54EAC03}",
"name": "ZaehlerUeberlauf",
"type": 3,
"vendor": "",
"aliases": [
"Zählerüberlauf"
],
"parentRequirements": [],
"childRequirements": [],
"implemented": [],
"prefix": "ZUL",
"url": "https://github.com/symcon/ZaehlerUeberlauf/tree/master/ZaehlerUeberlauf"
}
94 changes: 47 additions & 47 deletions ZaehlerUeberlauf/module.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,64 +2,64 @@

declare(strict_types=1);

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

$this->RegisterPropertyInteger('SourceVariable', 0);
$this->RegisterPropertyInteger('MaximumValue', 999999);
$this->RegisterPropertyInteger('SourceVariable', 0);
$this->RegisterPropertyInteger('MaximumValue', 999999);

$this->RegisterVariableFloat('Counter', $this->Translate('Counter'), '', 1);
}
$this->RegisterVariableFloat('Counter', $this->Translate('Counter'), '', 1);
}

public function ApplyChanges()
{
public function ApplyChanges()
{

//Never delete this line!
parent::ApplyChanges();
//Deleting references in order to re-add them
foreach ($this->GetReferenceList() as $referenceID) {
$this->UnregisterReference($referenceID);
}
//Never delete this line!
parent::ApplyChanges();
//Deleting references in order to re-add them
foreach ($this->GetReferenceList() as $referenceID) {
$this->UnregisterReference($referenceID);
}

//Unregister all messages in order to readd them
foreach ($this->GetMessageList() as $senderID => $messages) {
foreach ($messages as $message) {
$this->UnregisterMessage($senderID, $message);
}
//Unregister all messages in order to readd them
foreach ($this->GetMessageList() as $senderID => $messages) {
foreach ($messages as $message) {
$this->UnregisterMessage($senderID, $message);
}
}

//Create our trigger
$sourceVariable = $this->ReadPropertyInteger('SourceVariable');
if (IPS_VariableExists($sourceVariable)) {
$this->RegisterMessage($sourceVariable, VM_UPDATE);
$this->RegisterReference($sourceVariable);
//Deleting events used in legacy
$eid = @IPS_GetObjectIDByIdent('SourceTrigger', $this->InstanceID);
if ($eid) {
IPS_DeleteEvent($this->GetIDForIdent('SourceTrigger'));
}
//Create our trigger
$sourceVariable = $this->ReadPropertyInteger('SourceVariable');
if (IPS_VariableExists($sourceVariable)) {
$this->RegisterMessage($sourceVariable, VM_UPDATE);
$this->RegisterReference($sourceVariable);
//Deleting events used in legacy
$eid = @IPS_GetObjectIDByIdent('SourceTrigger', $this->InstanceID);
if ($eid) {
IPS_DeleteEvent($this->GetIDForIdent('SourceTrigger'));
}
}
}

private function Update(float $OldValue, float $Value)
{
if (($Value - $OldValue) < 0) {
$diff = $this->ReadPropertyInteger('MaximumValue') + 1 - $OldValue + $Value;
} else {
$diff = $Value - $OldValue;
}
public function MessageSink($TimeStamp, $SenderID, $Message, $Data)
{
//VM_UPDATE
$this->Update($Data[2], $Data[0]);
}

//update value
SetValue($this->GetIDForIdent('Counter'), GetValue($this->GetIDForIdent('Counter')) + $diff);
private function Update(float $OldValue, float $Value)
{
if (($Value - $OldValue) < 0) {
$diff = $this->ReadPropertyInteger('MaximumValue') + 1 - $OldValue + $Value;
} else {
$diff = $Value - $OldValue;
}

public function MessageSink($TimeStamp, $SenderID, $Message, $Data)
{
//VM_UPDATE
$this->Update($Data[2], $Data[0]);
}
}
//update value
SetValue($this->GetIDForIdent('Counter'), GetValue($this->GetIDForIdent('Counter')) + $diff);
}
}
22 changes: 11 additions & 11 deletions library.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"id": "{173B5799-B5BF-4AB1-BD2D-19C1DD309B9C}",
"author": "Symcon GmbH",
"name": "ZaehlerUeberlauf",
"url": "https://www.symcon.de/",
"compatibility": {
"version": "4.2"
},
"version": "1.0",
"build": 0,
"date": 0
}
"id": "{173B5799-B5BF-4AB1-BD2D-19C1DD309B9C}",
"author": "Symcon GmbH",
"name": "ZaehlerUeberlauf",
"url": "https://www.symcon.de/",
"compatibility": {
"version": "4.2"
},
"version": "1.0",
"build": 0,
"date": 0
}

0 comments on commit fdcb7e1

Please sign in to comment.