Automation Rewrite 1%

This commit is contained in:
JonatanRek 2019-08-23 14:20:58 +02:00
parent b4e854d8dd
commit 11eae4932c

View File

@ -41,39 +41,51 @@ class AutomationManager{
$sceneDoJson = $automation['do_something'];
$actionDays = json_decode($automation['on_days'], true);
$value = time();
$run = false;
$restart = false;
if ($automation['active'] != 0){
if (in_array($dayNameNow, $actionDays)){
switch ($onValue) {
case 'sunSet':
if (in_array($onValue, ['sunSet','time','now'])) {
if ($onValue == 'sunSet') {
$value = date_sunset($value, SUNFUNCS_RET_TIMESTAMP, 50.0755381 , 14.4378005, 90, $dateTimeOffset);
break;
case 'sunRise':
} else if ($onValue == 'sunRise') {
$value = date_sunrise($value, SUNFUNCS_RET_TIMESTAMP, 50.0755381 , 14.4378005, 90, $dateTimeOffset);
break;
case 'time':
} else if ($onValue == 'time') {
$onValue = explode(':',$onValue);
$today = date_create('now');
$onValue = $today->setTime($onValue[0], $onValue[1]);
$value = $today->getTimestamp();
break;
default:
break;
}
if (time() > $value){
if ($automation['executed'] == 0){
$run = true;
} else if (time() < $value && $automation['executed'] = 1) { //recovery realowing of automation
$restart = true;
}
}
}
if ($onValue == 'outHome') {
}
if ($onValue == 'inHome') {
}
//finalization
if ($run) {
$sceneDoArray = json_decode($sceneDoJson);
foreach ($sceneDoArray as $deviceId => $deviceState) {
RecordManager::create($deviceId, 'on/off', $deviceState);
}
Db::edit('automation', array('executed' => 1), 'WHERE automation_id = ?', array($automation['automation_id']));
}
} elseif (time() < $value && $automation['executed'] = 1) { //recovery realowing of automation
} else if ($restart) {
Db::edit('automation', array('executed' => 0), 'WHERE automation_id = ?', array($automation['automation_id']));
}
}
}
}
}
}