[CODE] return a shorter waitTime when it’s night time

This commit is contained in:
Jannik Beyerstedt 2017-07-24 12:24:19 +02:00
parent 0e18048954
commit 85f3ee44ca
1 changed files with 6 additions and 1 deletions

View File

@ -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 {