From d8c7a54446466c9e8716c02cb653d2d4a0a30af6 Mon Sep 17 00:00:00 2001 From: JonatanRek Date: Fri, 21 Feb 2020 14:01:39 +0100 Subject: [PATCH] Automations --- api.php | 4 ---- app/class/AutomationManager.php | 14 +++++++++++++- app/controls/automation.php | 31 ++++++++++++++++++++++++++----- app/templates/js/script.js | 9 --------- app/views/Ajax.php | 5 ----- 5 files changed, 39 insertions(+), 24 deletions(-) diff --git a/api.php b/api.php index bfec2e8..ebc6f6e 100644 --- a/api.php +++ b/api.php @@ -73,11 +73,7 @@ try { AutomationManager::executeAll(); $fallbackManager = new FallbackManager(RANGES); $fallbackManager->check(); -<<<<<<< HEAD //LogKeeper::purge(LOGTIMOUT); -======= - LogKeeper::purge(LOGTIMOUT); ->>>>>>> 15d95dae1d1766044ec10522238bb848dff548c2 } catch (\Exception $e) { $logManager->write("[Automation] Something happen during automation execution", LogRecordType::ERROR); } diff --git a/app/class/AutomationManager.php b/app/class/AutomationManager.php index f962681..95149e7 100644 --- a/app/class/AutomationManager.php +++ b/app/class/AutomationManager.php @@ -55,7 +55,7 @@ class AutomationManager{ $run = false; $restart = false; - if ($automation['active'] == 1 && $automation['locked'] != 1){ + if ($automation['active'] == 1 && $automation['locked'] != 1){ Db::edit('automation', array('locked' => 1), 'WHERE automation_id = ?', array($automation['automation_id'])); if (in_array($dayNameNow, $actionDays)){ if (in_array($onValue['type'], ['sunSet', 'sunRise', 'time','now'])) { @@ -118,6 +118,18 @@ class AutomationManager{ } else if ($membersHome > 0 && $automation['executed'] == 0){ $run = true; } + } else if ($onValue['type'] == 'atDeviceValue') { + + $subDeviceId = SubDeviceManager::getSubDeviceByMaster($onValue['value']['deviceID'], $onValue['value']['type'])["subdevice_id"]; + $lastValue = RecordManager::getLastRecord($subDeviceId); + + if ($lastValue['value'] == $onValue['value']['value'] && $automation['executed'] == 0) { + $run = true; + + } else if ($lastValue['value'] != $onValue['value']['value'] && $automation['executed'] == 1){ + $restart = true; + + } } //finalization diff --git a/app/controls/automation.php b/app/controls/automation.php index 446f9c2..94790c7 100644 --- a/app/controls/automation.php +++ b/app/controls/automation.php @@ -2,9 +2,20 @@ if (isset($_POST) && !empty($_POST)){ if (isset($_POST['modalFinal']) && $_POST['action'] == "add") { $doCode = json_encode($_POST['device'], JSON_PRETTY_PRINT); + + $value = $_POST['atSelector']; + if ($_POST['atSelector'] == 'time'){ + $value = $_POST['atSelectorValue']; + } else if ($_POST['atSelector'] == 'atDeviceValue') { + $value = json_decode($_POST['atSelectorValue']); + } else if ($_POST['atSelector'] == 'inHome' || $_POST['atSelector'] == 'outHome') { + $value = UserManager::getUserData('user_id'); + } + + $ifCode = json_encode([ "type" => $_POST['atSelector'], - "value" => $_POST['atSelectorValue'], + "value" => $value, ], JSON_PRETTY_PRINT); $onDays = $_POST['atDays']; @@ -32,18 +43,28 @@ if (isset($_POST) && !empty($_POST)){ $subDevice = SubDeviceManager::getSubDevice($subDeviceId); $subDeviceMaster = SubDeviceManager::getSubDeviceMaster($subDeviceId,$subDevice['type']); - $json = json_encode([ + $device = [ 'deviceID' => $subDeviceMaster['device_id'], 'type'=> $subDevice['type'], 'value'=> $subDeviceValue, - ]); + ]; } - $_POST['atSelectorValue'] = (isset($_POST['atTime']) ? $_POST['atTime'] : (isset($_POST['atDeviceValue']) ? $json : $_POST['atSelector'])); + $value = $_POST['atSelector']; + if (isset($_POST['atTime'])){ + $value = $_POST['atTime']; + } else if (isset($_POST['atDeviceValue'])) { + $value = $device; + } else if ($_POST['atSelector'] == 'inHome' || $_POST['atSelector'] == 'outHome') { + //TODO: opravit edit aby vkládal id původního uživatele + $value = UserManager::getUserData('user_id'); + } + + $value = (isset($_POST['atTime']) ? $_POST['atTime'] : (isset($_POST['atDeviceValue']) ? $device : $_POST['atSelector'])); $ifCode = json_encode([ "type" => $_POST['atSelector'], - "value" => $_POST['atSelectorValue'], + "value" => $value, ], JSON_PRETTY_PRINT); $onDays = ($_POST['day'] != '' ? json_encode($_POST['day']) : ''); diff --git a/app/templates/js/script.js b/app/templates/js/script.js index b01d0e8..3df7ca2 100644 --- a/app/templates/js/script.js +++ b/app/templates/js/script.js @@ -241,10 +241,7 @@ $( '[name="room"]' ).change(function (e) { }); -<<<<<<< HEAD /* -======= ->>>>>>> 15d95dae1d1766044ec10522238bb848dff548c2 var windowLoc = $(location).attr('pathname'); windowLoc = windowLoc.substring(windowLoc.lastIndexOf("/")); console.log(); @@ -280,13 +277,7 @@ if (windowLoc == "/") { }); } },4000); -<<<<<<< HEAD }*/ -======= -} - - ->>>>>>> 15d95dae1d1766044ec10522238bb848dff548c2 diff --git a/app/views/Ajax.php b/app/views/Ajax.php index 237cd49..7276de2 100644 --- a/app/views/Ajax.php +++ b/app/views/Ajax.php @@ -149,7 +149,6 @@ class Ajax extends Template isset($_POST['action']) && $_POST['action'] != '' ) { -<<<<<<< HEAD $updateData = []; $allDevicesData = DeviceManager::getAllDevices(); foreach ($allDevicesData as $deviceKey => $deviceValue) { @@ -217,10 +216,6 @@ class Ajax extends Template //TODO: PRO JS VRACET DATA echo json_encode($updateData, JSON_PRETTY_PRINT); -======= - //TODO: PRO JS VRACET DATA - ECHO 'test'; ->>>>>>> 15d95dae1d1766044ec10522238bb848dff548c2 } } }