From 85f3ee44cabe1d59c4ddaf837957858622d406d5 Mon Sep 17 00:00:00 2001 From: Jannik Beyerstedt Date: Mon, 24 Jul 2017 12:24:19 +0200 Subject: [PATCH] =?UTF-8?q?[CODE]=20return=20a=20shorter=20waitTime=20when?= =?UTF-8?q?=20it=E2=80=99s=20night=20time?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- functions.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/functions.php b/functions.php index 071b9a1..6369ca7 100644 --- a/functions.php +++ b/functions.php @@ -14,6 +14,7 @@ $timezone = "Europe/Berlin"; class LightStatus { public $state = true; public $changeTime = 1; + public $waitTime = 0; public $times = null; @@ -24,7 +25,7 @@ class LightStatus { } function __toString() { - return 's='.(int)$this->state.' t='.$this->changeTime; + return 's='.(int)$this->state.' t='.$this->waitTime; } public function update() { @@ -46,6 +47,7 @@ class LightStatus { if ($this->times['instant-on'] > time()) { $this->state = true; $this->changeTime = (int)(($this->times['instant-on']-time())/60); + $this->waitTime = $this->changeTime; return true; @@ -78,18 +80,21 @@ class LightStatus { if ($currentTime > $startTime && $currentTime < $stopTime) { $this->state = true; $this->changeTime = (int)(($stopTime - $currentTime) / 60); + $this->waitTime = 1; return true; } } $this->state = false; $this->changeTime = (int)(($stopTime - $currentTime) / 60); + $this->waitTime = 1; return true; } else if ($currentTime > $sunrise && $currentTime < $sunset) { // it's day: nothing else check $this->state = false; $this->changeTime = (int)(($sunset - $currentTime) / 60); + $this->waitTime = $this->changeTime; return true; } else {