Automations
This commit is contained in:
		@@ -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
 | 
			
		||||
 
 | 
			
		||||
@@ -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']) : '');
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -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
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -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
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user