[CODE] comments, add public variable for day/night status
This commit is contained in:
parent
596b256e64
commit
d29232cb3c
|
@ -8,26 +8,29 @@
|
|||
$config_filename = 'config_times.json';
|
||||
$timeRegex = '/^((2[0-3]|1[0-9]|0[0-9]|[^0-9][0-9]):([0-5][0-9]|[0-9]))/';
|
||||
$sun_zenith = 96; /* Civilian Twilight */
|
||||
//$sun_zenith = 90+50/60; /* sunrise/ sunset */
|
||||
//$sun_zenith = 90+50/60; /* "true" sunrise/ sunset */
|
||||
$timezone = "Europe/Berlin";
|
||||
|
||||
class LightStatus {
|
||||
public $state = true;
|
||||
public $changeTime = 1;
|
||||
public $waitTime = 0;
|
||||
public $state = true; /* current state: lights on/off */
|
||||
public $changeTime = 1; /* minutes until next state change */
|
||||
public $waitTime = 0; /* minutes the client should wait until next request */
|
||||
|
||||
public $times = null;
|
||||
public $times = null; /* config array */
|
||||
|
||||
public $sunrise, $sunset;
|
||||
public $sunrise, $sunset; /* time string hh:mm */
|
||||
public $isNight; /* bool, true if it's at night */
|
||||
|
||||
function __construct() {
|
||||
return $this->readTimes();
|
||||
}
|
||||
|
||||
/* return string for the service API */
|
||||
function __toString() {
|
||||
return 's='.(int)$this->state.' t='.$this->waitTime;
|
||||
}
|
||||
|
||||
/* re-calculate values */
|
||||
public function update() {
|
||||
global $sun_zenith;
|
||||
global $timezone;
|
||||
|
@ -63,6 +66,8 @@ class LightStatus {
|
|||
// first check, if it's at daylight
|
||||
$currentTime = time();
|
||||
if ($currentTime < $sunrise || $currentTime > $sunset) {
|
||||
$this->isNight = true;
|
||||
|
||||
// it's night: check, if we are in one of the time intervals
|
||||
for ($i = 1; $i <= 3; $i++) {
|
||||
$timeKey = 'time'.$i;
|
||||
|
@ -101,6 +106,8 @@ class LightStatus {
|
|||
return true;
|
||||
|
||||
} else if ($currentTime > $sunrise && $currentTime < $sunset) {
|
||||
$this->isNight = false;
|
||||
|
||||
// it's day: nothing else check
|
||||
$this->state = false;
|
||||
$this->changeTime = (int)(($sunset - $currentTime) / 60);
|
||||
|
@ -113,6 +120,7 @@ class LightStatus {
|
|||
}
|
||||
}
|
||||
|
||||
/* save modified $times array to config file */
|
||||
public function saveTimes() {
|
||||
global $config_filename;
|
||||
|
||||
|
|
Reference in a new issue