Merge branch 'remastering' of https://git.steelants.cz/SImple-Home/PHP_SMART_HOME_V3 into remastering
This commit is contained in:
commit
386e7be130
@ -1,9 +1,4 @@
|
|||||||
<?php
|
<?php
|
||||||
$files = scandir('app/class/');
|
|
||||||
$files = array_diff($files, array('.', '..'));
|
|
||||||
foreach($files as $file) {
|
|
||||||
include_once 'app/class/'. $file;
|
|
||||||
}
|
|
||||||
|
|
||||||
class Ajax extends Template
|
class Ajax extends Template
|
||||||
{
|
{
|
||||||
@ -11,16 +6,16 @@ class Ajax extends Template
|
|||||||
{
|
{
|
||||||
global $userManager;
|
global $userManager;
|
||||||
global $lang;
|
global $lang;
|
||||||
|
|
||||||
if (!$userManager->isLogin()){
|
if (!$userManager->isLogin()){
|
||||||
header('Location: ' . BASEDIR);
|
header('Location: ' . BASEDIR);
|
||||||
}
|
}
|
||||||
|
|
||||||
$is_ajax = 'XMLHttpRequest' == ( $_SERVER['HTTP_X_REQUESTED_WITH'] ?? '' );
|
$is_ajax = 'XMLHttpRequest' == ( $_SERVER['HTTP_X_REQUESTED_WITH'] ?? '' );
|
||||||
if (!$is_ajax){
|
if (!$is_ajax){
|
||||||
header('Location: ' . BASEDIR);
|
header('Location: ' . BASEDIR);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
isset($_POST['automation_id']) &&
|
isset($_POST['automation_id']) &&
|
||||||
$_POST['automation_id'] != '' &&
|
$_POST['automation_id'] != '' &&
|
||||||
@ -34,17 +29,17 @@ class Ajax extends Template
|
|||||||
AutomationManager::remove($automationId);
|
AutomationManager::remove($automationId);
|
||||||
die();
|
die();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'deactive':
|
case 'deactive':
|
||||||
AutomationManager::deactive($automationId);
|
AutomationManager::deactive($automationId);
|
||||||
die();
|
die();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'restart':
|
case 'restart':
|
||||||
AutomationManager::restart($automationId);
|
AutomationManager::restart($automationId);
|
||||||
die();
|
die();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
echo 'no action detected';
|
echo 'no action detected';
|
||||||
break;
|
break;
|
||||||
@ -65,7 +60,7 @@ class Ajax extends Template
|
|||||||
echo Utilities::generateGraphJson($graphData['graphType'], $graphData['graphData'], $graphData['graphRange']);
|
echo Utilities::generateGraphJson($graphData['graphType'], $graphData['graphData'], $graphData['graphRange']);
|
||||||
die();
|
die();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
//Change On/Off Device State of Device Button
|
//Change On/Off Device State of Device Button
|
||||||
case 'change':
|
case 'change':
|
||||||
$subDeviceData = SubDeviceManager::getSubDevice($subDeviceId);
|
$subDeviceData = SubDeviceManager::getSubDevice($subDeviceId);
|
||||||
@ -77,13 +72,13 @@ class Ajax extends Template
|
|||||||
}
|
}
|
||||||
die();
|
die();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
//Waitin for execution of Changet walue for Device Button
|
//Waitin for execution of Changet walue for Device Button
|
||||||
case 'executed':
|
case 'executed':
|
||||||
echo RecordManager::getLastRecord($subDeviceId)['execuded'];
|
echo RecordManager::getLastRecord($subDeviceId)['execuded'];
|
||||||
die();
|
die();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'set':
|
case 'set':
|
||||||
$value = $_POST['value'];
|
$value = $_POST['value'];
|
||||||
$subDevice = SubDeviceManager::getSubDevice($subDeviceId);
|
$subDevice = SubDeviceManager::getSubDevice($subDeviceId);
|
||||||
@ -91,7 +86,7 @@ class Ajax extends Template
|
|||||||
echo 'test id' . $subDevice['device_id'] .$subDevice['type'] . $value ;
|
echo 'test id' . $subDevice['device_id'] .$subDevice['type'] . $value ;
|
||||||
die();
|
die();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
echo 'no action detected';
|
echo 'no action detected';
|
||||||
break;
|
break;
|
||||||
@ -108,12 +103,12 @@ class Ajax extends Template
|
|||||||
SceneManager::delete($sceneId);
|
SceneManager::delete($sceneId);
|
||||||
die();
|
die();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'execute':
|
case 'execute':
|
||||||
echo SceneManager::execScene($sceneId);
|
echo SceneManager::execScene($sceneId);
|
||||||
die();
|
die();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
echo 'no action detected';
|
echo 'no action detected';
|
||||||
break;
|
break;
|
||||||
@ -131,7 +126,7 @@ class Ajax extends Template
|
|||||||
NotificationManager::addSubscriber($_SESSION['user']['id'], $subscriptionToken);
|
NotificationManager::addSubscriber($_SESSION['user']['id'], $subscriptionToken);
|
||||||
die();
|
die();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'sendTest':
|
case 'sendTest':
|
||||||
$notificationData = [
|
$notificationData = [
|
||||||
'title' => 'Alert',
|
'title' => 'Alert',
|
||||||
@ -147,7 +142,7 @@ class Ajax extends Template
|
|||||||
}
|
}
|
||||||
die();
|
die();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
echo 'no action detected';
|
echo 'no action detected';
|
||||||
break;
|
break;
|
||||||
@ -161,10 +156,10 @@ class Ajax extends Template
|
|||||||
foreach ($allDevicesData as $deviceKey => $deviceValue) {
|
foreach ($allDevicesData as $deviceKey => $deviceValue) {
|
||||||
$allSubDevices = SubDeviceManager::getAllSubDevices($deviceValue['device_id']);
|
$allSubDevices = SubDeviceManager::getAllSubDevices($deviceValue['device_id']);
|
||||||
foreach ($allSubDevices as $key => $subDevicesData) {
|
foreach ($allSubDevices as $key => $subDevicesData) {
|
||||||
|
|
||||||
$lastRecord = RecordManager::getLastRecord($subDevicesData['subdevice_id']);
|
$lastRecord = RecordManager::getLastRecord($subDevicesData['subdevice_id']);
|
||||||
$parsedValue = $lastRecord['value'] . $subDevicesData['unit'];
|
$parsedValue = $lastRecord['value'] . $subDevicesData['unit'];
|
||||||
|
|
||||||
//TODO: udělat parser a ten použít jak v houmu tak zde
|
//TODO: udělat parser a ten použít jak v houmu tak zde
|
||||||
switch ($subDevicesData['type']) {
|
switch ($subDevicesData['type']) {
|
||||||
case 'on/off':
|
case 'on/off':
|
||||||
@ -173,14 +168,14 @@ class Ajax extends Template
|
|||||||
$operator = '==';
|
$operator = '==';
|
||||||
$breakValue = 1;
|
$breakValue = 1;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'door':
|
case 'door':
|
||||||
$replacementTrue = 'Closed';
|
$replacementTrue = 'Closed';
|
||||||
$replacementFalse = 'Open';
|
$replacementFalse = 'Open';
|
||||||
$operator = '==';
|
$operator = '==';
|
||||||
$breakValue = 1;
|
$breakValue = 1;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'light':
|
case 'light':
|
||||||
$replacementTrue = 'Light';
|
$replacementTrue = 'Light';
|
||||||
$replacementFalse = 'Dark';
|
$replacementFalse = 'Dark';
|
||||||
@ -191,36 +186,36 @@ class Ajax extends Template
|
|||||||
$breakValue = 810;
|
$breakValue = 810;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'water':
|
case 'water':
|
||||||
$replacementTrue = 'Wet';
|
$replacementTrue = 'Wet';
|
||||||
$replacementFalse = 'Dry';
|
$replacementFalse = 'Dry';
|
||||||
$operator = '==';
|
$operator = '==';
|
||||||
$breakValue = 1;
|
$breakValue = 1;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
$replacementTrue = '';
|
$replacementTrue = '';
|
||||||
$replacementFalse = '';
|
$replacementFalse = '';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($replacementTrue != '' && $replacementFalse != '') {
|
if ($replacementTrue != '' && $replacementFalse != '') {
|
||||||
//parsing last values
|
//parsing last values
|
||||||
$parsedValue = $replacementFalse;
|
$parsedValue = $replacementFalse;
|
||||||
|
|
||||||
if (Utilities::checkOperator($lastRecord['value'], $operator, $breakValue)) {
|
if (Utilities::checkOperator($lastRecord['value'], $operator, $breakValue)) {
|
||||||
$parsedValue = $replacementTrue;
|
$parsedValue = $replacementTrue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$updateData[$subDevicesData['subdevice_id']] = [
|
$updateData[$subDevicesData['subdevice_id']] = [
|
||||||
'time' => $lastRecord['time'],
|
'time' => $lastRecord['time'],
|
||||||
'value' => $parsedValue,
|
'value' => $parsedValue,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: PRO JS VRACET DATA
|
//TODO: PRO JS VRACET DATA
|
||||||
echo json_encode($updateData, JSON_PRETTY_PRINT);
|
echo json_encode($updateData, JSON_PRETTY_PRINT);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user