Some minor changes of Automation system
This commit is contained in:
parent
aa8235c1bf
commit
b1e19dd64d
35
api.php
35
api.php
@ -14,20 +14,6 @@ foreach (["class", "views"] as $dir) {
|
||||
//DB Conector
|
||||
Db::connect (DBHOST, DBUSER, DBPASS, DBNAME);
|
||||
|
||||
//Filtrování IP adress
|
||||
/*if (DEBUGMOD != 1) {
|
||||
if (!in_array($_SERVER['REMOTE_ADDR'], HOMEIP)) {
|
||||
echo json_encode(array(
|
||||
'state' => 'unsuccess',
|
||||
'errorMSG' => "Using API from your IP insn´t alowed!",
|
||||
));
|
||||
header("HTTP/1.1 401 Unauthorized");
|
||||
exit();
|
||||
}
|
||||
}*/
|
||||
|
||||
|
||||
|
||||
//Read API data
|
||||
$json = file_get_contents('php://input');
|
||||
$obj = json_decode($json, true);
|
||||
@ -36,10 +22,24 @@ if (isset($obj['user']) && $obj['user'] != ''){
|
||||
//user at home
|
||||
$user = UserManager::getUser($obj['user']);
|
||||
$userId = $user['user_id'];
|
||||
UserManager::atHome($userId, $obj['location']);
|
||||
$keyWords = ['entered', 'connected', 'connected to'];
|
||||
UserManager::atHome($userId, $obj['atHome']);
|
||||
echo 'ssaved';
|
||||
die();
|
||||
}
|
||||
|
||||
//Filtrování IP adress
|
||||
/*if (DEBUGMOD != 1) {
|
||||
if (!in_array($_SERVER['REMOTE_ADDR'], HOMEIP)) {
|
||||
echo json_encode(array(
|
||||
'state' => 'unsuccess',
|
||||
'errorMSG' => "Using API from your IP insn´t alowed!",
|
||||
));
|
||||
header("HTTP/1.1 401 Unauthorized");
|
||||
exit();
|
||||
}
|
||||
}*/
|
||||
|
||||
//automationExecution
|
||||
AutomationManager::executeAll();
|
||||
|
||||
@ -117,7 +117,6 @@ if ($values != null || $values != "") {
|
||||
'state' => 'succes',
|
||||
));
|
||||
header("HTTP/1.1 200 OK");
|
||||
die();
|
||||
} else {
|
||||
//Vypis
|
||||
//TODO: doděla uložení výpisu jinými slovy zda li byl comman vykonán
|
||||
@ -145,5 +144,7 @@ if ($values != null || $values != "") {
|
||||
'value' => $subDeviceLastReordValue
|
||||
));
|
||||
header("HTTP/1.1 200 OK");
|
||||
die();
|
||||
}
|
||||
|
||||
Db::disconect();
|
||||
die();
|
||||
|
@ -73,13 +73,40 @@ class AutomationManager{
|
||||
$restart = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if ($onValue['type'] == 'outHome') {
|
||||
|
||||
if ($onValue == 'outHome') {
|
||||
} else if ($onValue['type'] == 'inHome') {
|
||||
|
||||
}
|
||||
|
||||
if ($onValue == 'inHome') {
|
||||
} else if ($onValue['type'] == 'noOneHome') {
|
||||
$users = UserManager::getUsers();
|
||||
$membersHome = 0;
|
||||
foreach ($users as $key => $user) {
|
||||
if ($user['at_home'] == 'true'){
|
||||
$membersHome++;
|
||||
}
|
||||
}
|
||||
if ($membersHome == 0 && $automation['executed'] == 0) {
|
||||
$run = true;
|
||||
} else if ($membersHome > 0 && $automation['executed'] == 1){
|
||||
$restart = true;
|
||||
}
|
||||
} else if ($onValue['type'] == 'someOneHome') {
|
||||
$users = UserManager::getUsers();
|
||||
$membersHome = 0;
|
||||
foreach ($users as $key => $user) {
|
||||
if ($user['at_home'] == 'true'){
|
||||
$membersHome++;
|
||||
}
|
||||
}
|
||||
if ($membersHome == 0 && $automation['executed'] == 0) {
|
||||
$restart = true;
|
||||
} else if ($membersHome > 0 && $automation['executed'] == 1){
|
||||
$run = true;
|
||||
}
|
||||
/*echo "Someone Home". '<br>';
|
||||
echo "at home" . $membersHome. '<br>';
|
||||
echo "run" . $run. '<br>';
|
||||
echo "restart" . $restart. '<br>';*/
|
||||
|
||||
}
|
||||
|
||||
|
@ -19,6 +19,10 @@ class Db{
|
||||
}
|
||||
}
|
||||
|
||||
public static function disconect(){
|
||||
self::$join = null;
|
||||
}
|
||||
|
||||
public static function loadOne ($sql, $values = array (), $numberKey = false) {
|
||||
$answer = self::$join->prepare ($sql);
|
||||
$answer->execute ($values);
|
||||
|
@ -63,8 +63,12 @@ $lang = [
|
||||
'w_icon' => 'Ikona',
|
||||
'w_no' => 'žádná',
|
||||
'w_noOne' => 'Nikdo',
|
||||
'w_someOne' => 'Někdo',
|
||||
'w_room' => 'Místnost',
|
||||
'w_moduls' => 'Moduly',
|
||||
'w_home' => 'Doma',
|
||||
'w_neni' => 'Není',
|
||||
'w_is' => 'je',
|
||||
|
||||
//example
|
||||
'' => '',
|
||||
|
@ -63,8 +63,12 @@ $lang = [
|
||||
'w_icon' => 'Icon',
|
||||
'w_no' => 'no',
|
||||
'w_noOne' => 'noone',
|
||||
'w_someOne' => 'Some',
|
||||
'w_room' => 'Room',
|
||||
'w_moduls' => 'Moduls',
|
||||
'w_home' => 'Home',
|
||||
'w_neni' => 'At',
|
||||
'w_is' => 'is',
|
||||
|
||||
//example
|
||||
'' => '',
|
||||
|
@ -48,7 +48,7 @@
|
||||
<i class="fa fa-times"></i>
|
||||
</div>
|
||||
<h4 class="mb-4">Modal bitch</h4>
|
||||
<form method="post" action="controls/dashboard.php">
|
||||
<form method="post">
|
||||
<div class="field px-2">
|
||||
<div class="label">Zvolte zařízení:</div>
|
||||
<select class="input" name="devices[]" multiple>
|
||||
|
@ -35,10 +35,8 @@
|
||||
<div class="col-md-9 main-body">
|
||||
<div class="label m-1">
|
||||
doma jsou:
|
||||
<?php
|
||||
$keyWords = ['entered', 'connected', 'connected to'];
|
||||
foreach ($USERS as $user) {
|
||||
if (in_array(trim($user['at_home']), $keyWords)) {
|
||||
<?php foreach ($USERS as $user) {
|
||||
if ($user['at_home'] == 'true') {
|
||||
echo $user['username'] . ' ';
|
||||
}
|
||||
} ?>
|
||||
|
@ -33,7 +33,7 @@ function ajaxPost(path, params, self, reload = false) {
|
||||
}
|
||||
console.log(msg);
|
||||
if (reload){
|
||||
//location.reload();
|
||||
location.reload();
|
||||
}
|
||||
},
|
||||
error: function (request, status, error) {
|
||||
|
@ -182,36 +182,36 @@ $( '[name="room"]' ).change(function (e) {
|
||||
});
|
||||
|
||||
|
||||
var windowLoc = $(location).attr('pathname');
|
||||
windowLoc = windowLoc.substring(windowLoc.lastIndexOf("/"));
|
||||
console.log();
|
||||
if (windowLoc == "/") {
|
||||
var autoUpdate = setInterval(function(){
|
||||
$.ajax({
|
||||
url: 'ajax',
|
||||
type: 'POST',
|
||||
dataType: 'json',
|
||||
data: {
|
||||
"action": 'getState'
|
||||
},
|
||||
success: function(data){
|
||||
// console.log('DATA: ', data);
|
||||
for (const key in data) {
|
||||
if (data.hasOwnProperty(key)) {
|
||||
const device = data[key];
|
||||
$('[data-sub-device-id="'+key+'"]')
|
||||
.find('.device-button-value')
|
||||
.text(device['value'])
|
||||
.attr('title',device['time'])
|
||||
}
|
||||
}
|
||||
},
|
||||
error: function (request, status, error) {
|
||||
console.log("ERROR ajaxChart():", request, error);
|
||||
}
|
||||
});
|
||||
},2000);
|
||||
}
|
||||
// var windowLoc = $(location).attr('pathname');
|
||||
// windowLoc = windowLoc.substring(windowLoc.lastIndexOf("/"));
|
||||
// console.log();
|
||||
// if (windowLoc == "/") {
|
||||
// var autoUpdate = setInterval(function(){
|
||||
// $.ajax({
|
||||
// url: 'ajax',
|
||||
// type: 'POST',
|
||||
// dataType: 'json',
|
||||
// data: {
|
||||
// "action": 'getState'
|
||||
// },
|
||||
// success: function(data){
|
||||
// // console.log('DATA: ', data);
|
||||
// for (const key in data) {
|
||||
// if (data.hasOwnProperty(key)) {
|
||||
// const device = data[key];
|
||||
// $('[data-sub-device-id="'+key+'"]')
|
||||
// .find('.device-button-value')
|
||||
// .text(device['value'])
|
||||
// .attr('title',device['time'])
|
||||
// }
|
||||
// }
|
||||
// },
|
||||
// error: function (request, status, error) {
|
||||
// console.log("ERROR ajaxChart():", request, error);
|
||||
// }
|
||||
// });
|
||||
// },2000);
|
||||
// }
|
||||
|
||||
|
||||
|
||||
|
@ -12,7 +12,10 @@
|
||||
<option value="inHome"><?php echo $LANG['l_inHome']?></option>
|
||||
<option value="outHome"><?php echo $LANG['l_outHome']?></option>
|
||||
<option value="time"><?php echo $LANG['l_time']?></option>
|
||||
<option value="atDeviceValue"><?php echo $LANG['l_deviceValue']?></option>
|
||||
<option value="noOneHome"><?php echo $LANG['l_time']?></option>
|
||||
<option value="atDeviceValue"><?php echo $LANG['l_deviceValue'];?></option>
|
||||
<option value="noOneHome"><?php echo $LANG['w_noOne'] . $LANG['w_neni'] . $LANG['w_home'];?></option>
|
||||
<option value="someoOneHome"><?php echo $LANG['w_someOne'] . $LANG['w_is'] . $LANG['w_home'];?></option>
|
||||
</select>
|
||||
<input class="input" type="time" name="atTime" id="atTime" disabled/>
|
||||
<select class="input" name="atDeviceValue" id="atDeviceValue" disabled>
|
||||
|
@ -30,6 +30,7 @@ class Ajax extends Template
|
||||
$subDeviceData = SubDeviceManager::getSubDevice($subDeviceId);
|
||||
$deviceId = SubDeviceManager::getSubDeviceMaster($subDeviceId)['device_id'];
|
||||
if ($subDeviceData['type'] == 'on/off'){
|
||||
//TODO: Pridelat kontrolu změnit stav pouze pokud se poslední [executed] stav != novému
|
||||
if (RecordManager::getLastRecord($subDeviceData['subdevice_id'])['value'] == 0){
|
||||
RecordManager::create($deviceId, 'on/off', 1);
|
||||
echo 'ON';
|
||||
|
@ -20,10 +20,10 @@ class Automation extends Template
|
||||
$automationsData = AutomationManager::getAll();
|
||||
foreach ($automationsData as $automationKey => $automationData) {
|
||||
$doSomething = [];
|
||||
foreach (json_decode($automationData['do_something']) as $subdeviceId => $subDeviceState) {
|
||||
$subDeviceMasterDeviceData = SubDeviceManager::getSubDeviceMaster($subdeviceId);
|
||||
$doSomething[$subdeviceId] = [
|
||||
'name' => $subDeviceMasterDeviceData['name'],
|
||||
foreach (json_decode($automationData['do_something']) as $deviceId => $subDeviceState) {
|
||||
$subDeviceMasterDeviceData = DeviceManager::getDeviceById($deviceId);
|
||||
$doSomething[$deviceId] = [
|
||||
'name' => $subDeviceMasterDeviceData['name'] . $subDeviceMasterDeviceData['device_id'] ,
|
||||
'state' => $subDeviceState,
|
||||
];
|
||||
}
|
||||
@ -43,7 +43,7 @@ class Automation extends Template
|
||||
$allSubDevicesData = SubDeviceManager::getAllSubDevices($deviceValue['device_id']);
|
||||
foreach ($allSubDevicesData as $subDeviceKey => $subDeviceValue) {
|
||||
$approvedSubDevices[$subDeviceValue['subdevice_id']] = [
|
||||
'name' => $allDevicesData[$deviceKey]['name'],
|
||||
'name' => $allDevicesData[$deviceKey]['name'] . $allDevicesData[$deviceKey]['device_id'],
|
||||
'type' => $subDeviceValue['type'],
|
||||
'masterDevice' => $subDeviceValue['device_id'],
|
||||
];
|
||||
|
Loading…
Reference in New Issue
Block a user