Merge branch 'master' of https://git.steelants.cz/JonatanRek/PHP_SMART_HOME_V3
This commit is contained in:
@@ -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'] == 1) {
|
||||
$restart = true;
|
||||
} else if ($membersHome > 0 && $automation['executed'] == 0){
|
||||
$run = true;
|
||||
}
|
||||
/*echo "Someone Home". '<br>';
|
||||
echo "at home" . $membersHome. '<br>';
|
||||
echo "run" . $run. '<br>';
|
||||
echo "restart" . $restart. '<br>';*/
|
||||
|
||||
}
|
||||
|
||||
@@ -89,8 +116,10 @@ class AutomationManager{
|
||||
foreach ($sceneDoArray as $deviceId => $deviceState) {
|
||||
RecordManager::create($deviceId, 'on/off', $deviceState);
|
||||
}
|
||||
$logManager->write("[AUTOMATIONS] automation id ". $automation['automation_id'] . " was executed");
|
||||
Db::edit('automation', array('executed' => 1), 'WHERE automation_id = ?', array($automation['automation_id']));
|
||||
} else if ($restart) {
|
||||
$logManager->write("[AUTOMATIONS] automation id ". $automation['automation_id'] . " was restarted");
|
||||
Db::edit('automation', array('executed' => 0), 'WHERE automation_id = ?', array($automation['automation_id']));
|
||||
}
|
||||
}
|
||||
|
@@ -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);
|
||||
|
38
class/LogManager.php
Normal file
38
class/LogManager.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
||||
class LogRecordType{
|
||||
const WARNING = 'warning';
|
||||
const ERROR = 'error';
|
||||
const INFO = 'info';
|
||||
}
|
||||
|
||||
class LogManager
|
||||
{
|
||||
|
||||
private $logFile;
|
||||
function __construct($fileName = "")
|
||||
{
|
||||
if ($fileName == ""){
|
||||
$fileName = './logs/'. date("Y-m-d").'.log';
|
||||
}
|
||||
if(!is_dir("./logs/"))
|
||||
{
|
||||
mkdir("./logs/");
|
||||
}
|
||||
$this->logFile = fopen($fileName, "a") or die("Unable to open file!");
|
||||
}
|
||||
|
||||
function write($value, $type = LogRecordType::ERROR){
|
||||
$record = "[".date("H:m:s")."][".$type."]" .$value . "\n";
|
||||
fwrite($this->logFile, $record);
|
||||
}
|
||||
|
||||
function __destruct(){
|
||||
if (isset($this->logFile)) {
|
||||
fclose($this->logFile);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user