Automation Rewrite 1%
This commit is contained in:
parent
b4e854d8dd
commit
11eae4932c
@ -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':
|
||||
$value = date_sunset($value, SUNFUNCS_RET_TIMESTAMP, 50.0755381 , 14.4378005, 90, $dateTimeOffset);
|
||||
break;
|
||||
case 'sunRise':
|
||||
$value = date_sunrise($value, SUNFUNCS_RET_TIMESTAMP, 50.0755381 , 14.4378005, 90, $dateTimeOffset);
|
||||
break;
|
||||
case 'time':
|
||||
$onValue = explode(':',$onValue);
|
||||
$today = date_create('now');
|
||||
$onValue = $today->setTime($onValue[0], $onValue[1]);
|
||||
$value = $today->getTimestamp();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
if (in_array($onValue, ['sunSet','time','now'])) {
|
||||
if ($onValue == 'sunSet') {
|
||||
$value = date_sunset($value, SUNFUNCS_RET_TIMESTAMP, 50.0755381 , 14.4378005, 90, $dateTimeOffset);
|
||||
} else if ($onValue == 'sunRise') {
|
||||
$value = date_sunrise($value, SUNFUNCS_RET_TIMESTAMP, 50.0755381 , 14.4378005, 90, $dateTimeOffset);
|
||||
} else if ($onValue == 'time') {
|
||||
$onValue = explode(':',$onValue);
|
||||
$today = date_create('now');
|
||||
$onValue = $today->setTime($onValue[0], $onValue[1]);
|
||||
$value = $today->getTimestamp();
|
||||
}
|
||||
|
||||
if (time() > $value){
|
||||
if ($automation['executed'] == 0){
|
||||
$run = true;
|
||||
} else if (time() < $value && $automation['executed'] = 1) { //recovery realowing of automation
|
||||
$restart = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (time() > $value){
|
||||
if ($automation['executed'] == 0){
|
||||
$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']));
|
||||
if ($onValue == 'outHome') {
|
||||
|
||||
}
|
||||
|
||||
if ($onValue == 'inHome') {
|
||||
|
||||
}
|
||||
|
||||
//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']));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user