1
0

hooks are now classes and devices scan exposes to add properties

This commit is contained in:
2021-12-31 23:09:58 +01:00
parent 57390d099b
commit f2f8e27c89
5 changed files with 111 additions and 28 deletions

View File

@ -14,7 +14,8 @@ $logLevel = LOG_DEBUG;
declare(ticks = 1);
$listProperties = array( "powerSource" => "batterie" );
$listProperties = array("powerSource" => "batterie");
$listPropertiesKeys = array("property");
class Message
{
@ -64,6 +65,7 @@ class event
public $topic;
public $param;
public $value;
public $device;
public $published;
public $dateTimeEvent;
public $recurrenceDay;
@ -178,17 +180,20 @@ foreach($topics as $name => $topic)
while (true)
{
$client->loop();
if ($dbInit and ! $included)
if ($dbInit == 2 and ! $included)
{
$hooks = loadHooks("./scripts");
if (!empty($hooks))
$hooksList = array();
loadHooks("./hooks", $hooksList);
//print_r($hooksList);
if (!empty($hooksList))
{
foreach ($hooks as $hook)
foreach ($hooksList as $hook)
{
echo "Including $hook" . EOL;
include $hook;
}
}
}elseif($dbInit and $included)
}elseif($dbInit == 2 and $included)
{
checkEvents();
if (empty($flag))
@ -213,32 +218,31 @@ function init()
return true;
}
function loadHooks($dir)
function loadHooks($dir, &$hookList)
{
global $included;
$hookList = array();
$files = scandir($dir);
//print_r($files);
foreach ($files as $file)
{
//echo " $file" . EOL;
if ($file != "." and $file != ".." and strpos($file, "~", -2) === false)
//echo "=====> $file" . EOL;
if ($file != "." and $file != "..")
{
//echo "not . or .." . EOL;
if (is_dir($file))
//echo "not . or .." . EOL;echo strpos($file, ".php", -4) . EOL;
if (is_dir($dir . "/" . $file))
{
//echo "directory" . EOL;
loadHooks($dir . '/' . $file);
}else
//echo "directory : " . $dir . '/' . $file . EOL;
loadHooks($dir . '/' . $file, $hookList);
}elseif (strpos($file, ".php", -4) !== false)
{
//echo "file" . EOL;
//echo "file : " . $dir . "/" . $file . EOL;
$hookList[] = $dir . "/" . $file;
}
}
}
//print_r($hookList);
$included = true;
return $hookList;
}