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