Skip to content

Commit

Permalink
Merge pull request #29 from symcon/fixes/upgrade-style
Browse files Browse the repository at this point in the history
Update style
  • Loading branch information
Sunnyka98 committed Nov 16, 2023
2 parents 5599478 + 096a460 commit 584c68c
Show file tree
Hide file tree
Showing 8 changed files with 110 additions and 110 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,3 +1,4 @@
.DS_Store
.idea/
tests/.phpunit.*
tests/.phpunit.*
.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
2 changes: 1 addition & 1 deletion AnwesenheitsSimulation/locale.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"translations": {
"de": {
"de": {
"Minimum needed daily changes": "Minimale Anzahl an täglichen Schaltvorgängen",
"Count": "Anzahl",
"Simulation preview": "Simulationsvorschau",
Expand Down
3 changes: 1 addition & 2 deletions AnwesenheitsSimulation/module.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
"name": "AnwesenheitsSimulation",
"type": 3,
"vendor": "",
"aliases":
[
"aliases": [
"AnwesenheitsSimulation"
],
"parentRequirements": [],
Expand Down
176 changes: 88 additions & 88 deletions AnwesenheitsSimulation/module.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,20 +154,6 @@ public function SetSimulation(bool $SwitchOn)

$this->SetValue('Active', $SwitchOn);
}
//If the the variable has a name we use it
private function GetName($VariableID)
{
$targets = json_decode($this->ReadPropertyString('Targets'), true);
foreach ($targets as $target) {
if (($target['VariableID'] == $VariableID) && IPS_VariableExists($target['VariableID'])) {
if (!isset($target['Name']) || $target['Name'] == '') {
return IPS_GetName($VariableID);
} else {
return $target['Name'];
}
}
}
}

public function RequestAction($Ident, $Value)
{
Expand All @@ -180,80 +166,6 @@ public function RequestAction($Ident, $Value)
}
}

//Returns all variableIDs in list
private function GetTargets()
{
$targets = json_decode($this->ReadPropertyString('Targets'), true);

$result = [];
foreach ($targets as $target) {
if (IPS_VariableExists($target['VariableID'])) {
$result[] = $target['VariableID'];
}
}
return $result;
}

//returns a array of the dayData of 1 Variable
private function GetDayData($day, $targetIDs)
{
$dayStart = mktime(0, 0, 0, intval(date('m', $this->getTime())), intval(date('d', $this->getTime())), intval(date('Y', $this->getTime())));
$dayDiff = $day * 24 * 3600;
$dayData = [];
$archiveControlID = IPS_GetInstanceListByModuleID('{43192F0B-135B-4CE7-A0A7-1475603F3060}')[0];

//Going through all variables
foreach ($targetIDs as $targetID) {
if (AC_GetLoggingStatus($archiveControlID, $targetID)) {
//Fetch Data for all variables but only one day
$values = AC_GetLoggedValues($archiveControlID, $targetID, $dayStart - $dayDiff, $dayStart + (24 * 3600) - $dayDiff - 1, 0);
if (count($values) > 0) {

//Transform UnixTimeStamp into human readable value
foreach ($values as $key => $value) {
$values[$key]['TimeStamp'] = date('H:i:s', $value['TimeStamp']);
}

//Reverse array to have the Timestamps ascending
$dayData[$targetID] = array_reverse($values);
}
}
}

// return all values for listed variables for one day in a array
return ['Date' => date('d.m.Y', $dayStart - $dayDiff), 'Data' => $dayData];
}

//returns a array of all listed variables for 1 day and checks if this meets the needed switchcount
private function GetDataArray($days, $targetIDs)
{

//Get the dayData for all variables
foreach ($days as $day) {
$data = $this->GetDayData($day, $targetIDs);

$this->SendDebug('Fetch', 'Fetched day -' . $day . ' with ' . count($data['Data']) . ' valid device(s)', 0);

if (count($data['Data']) > 0) {

//Sum up the switchCount
$switchCounts = 0;
foreach ($data['Data'] as $value) {
$switchCounts += count($value);
}

$this->SendDebug('Fetch', '> Required entropy of ' . ($this->ReadPropertyInteger('RequiredSwitchCount') * count($targetIDs)) . '. Have ' . $switchCounts, 0);

//Check if the needed switchCount requierement is meet
if ($switchCounts >= ($this->ReadPropertyInteger('RequiredSwitchCount') * count($targetIDs))) {
return $data;
}
}
}

return [];
}

//Fetches the needed SimulationData for a whole day
public function UpdateData()
{
Expand Down Expand Up @@ -378,6 +290,94 @@ public function UpdateTargets()
}
$this->SetTimerInterval('MidnightTimer', 1000 * (strtotime('tomorrow', $this->getTime()) - $this->getTime()));
}
//If the the variable has a name we use it
private function GetName($VariableID)
{
$targets = json_decode($this->ReadPropertyString('Targets'), true);
foreach ($targets as $target) {
if (($target['VariableID'] == $VariableID) && IPS_VariableExists($target['VariableID'])) {
if (!isset($target['Name']) || $target['Name'] == '') {
return IPS_GetName($VariableID);
} else {
return $target['Name'];
}
}
}
}

//Returns all variableIDs in list
private function GetTargets()
{
$targets = json_decode($this->ReadPropertyString('Targets'), true);

$result = [];
foreach ($targets as $target) {
if (IPS_VariableExists($target['VariableID'])) {
$result[] = $target['VariableID'];
}
}
return $result;
}

//returns a array of the dayData of 1 Variable
private function GetDayData($day, $targetIDs)
{
$dayStart = mktime(0, 0, 0, intval(date('m', $this->getTime())), intval(date('d', $this->getTime())), intval(date('Y', $this->getTime())));
$dayDiff = $day * 24 * 3600;
$dayData = [];
$archiveControlID = IPS_GetInstanceListByModuleID('{43192F0B-135B-4CE7-A0A7-1475603F3060}')[0];

//Going through all variables
foreach ($targetIDs as $targetID) {
if (AC_GetLoggingStatus($archiveControlID, $targetID)) {
//Fetch Data for all variables but only one day
$values = AC_GetLoggedValues($archiveControlID, $targetID, $dayStart - $dayDiff, $dayStart + (24 * 3600) - $dayDiff - 1, 0);
if (count($values) > 0) {

//Transform UnixTimeStamp into human readable value
foreach ($values as $key => $value) {
$values[$key]['TimeStamp'] = date('H:i:s', $value['TimeStamp']);
}

//Reverse array to have the Timestamps ascending
$dayData[$targetID] = array_reverse($values);
}
}
}

// return all values for listed variables for one day in a array
return ['Date' => date('d.m.Y', $dayStart - $dayDiff), 'Data' => $dayData];
}

//returns a array of all listed variables for 1 day and checks if this meets the needed switchcount
private function GetDataArray($days, $targetIDs)
{

//Get the dayData for all variables
foreach ($days as $day) {
$data = $this->GetDayData($day, $targetIDs);

$this->SendDebug('Fetch', 'Fetched day -' . $day . ' with ' . count($data['Data']) . ' valid device(s)', 0);

if (count($data['Data']) > 0) {

//Sum up the switchCount
$switchCounts = 0;
foreach ($data['Data'] as $value) {
$switchCounts += count($value);
}

$this->SendDebug('Fetch', '> Required entropy of ' . ($this->ReadPropertyInteger('RequiredSwitchCount') * count($targetIDs)) . '. Have ' . $switchCounts, 0);

//Check if the needed switchCount requierement is meet
if ($switchCounts >= ($this->ReadPropertyInteger('RequiredSwitchCount') * count($targetIDs))) {
return $data;
}
}
}

return [];
}

private function UpdateView($targetIDs, $nextSimulationData)
{
Expand Down
10 changes: 5 additions & 5 deletions AnwesenheitsSimulation/timetest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@ trait TestTime
{
private $currentTime = 989884800;

protected function getTime()
{
return $this->currentTime;
}

public function setTime(int $Time)
{
$this->currentTime = $Time;
Expand All @@ -21,6 +16,11 @@ public function GetTimerInterval(string $Ident)
{
return parent::GetTimerInterval($Ident);
}

protected function getTime()
{
return $this->currentTime;
}
}
} else {
trait TestTime
Expand Down
22 changes: 11 additions & 11 deletions library.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"id": "{0F05F2D8-78FB-4A9C-8FAA-DE436ACA7EB0}",
"author": "Symcon GmbH",
"name": "AnwesenheitsSimulation",
"url": "https://www.symcon.de",
"compatibility": {
"version": "6.0"
},
"version": "1.3",
"build": 0,
"date": 0
}
"id": "{0F05F2D8-78FB-4A9C-8FAA-DE436ACA7EB0}",
"author": "Symcon GmbH",
"name": "AnwesenheitsSimulation",
"url": "https://www.symcon.de",
"compatibility": {
"version": "6.0"
},
"version": "1.3",
"build": 0,
"date": 0
}

0 comments on commit 584c68c

Please sign in to comment.