1
0

some debugging and modifying hooks functions to fetch parameters

This commit is contained in:
2022-01-05 00:01:41 +01:00
parent c97f05d2b6
commit 85a7fd7ed9
7 changed files with 81 additions and 31 deletions

View File

@ -21,6 +21,7 @@ $topics = array(); // list of topics
$mids = array(); // list of message IDs
$devices = array(); // array of device objetcs
$indexDevices = array(); // index devices by ieee_address
$hooksList = array(); // list of hooks to be included
$hooks = array(); // array of hooks
$notificationMethods = array(); // array of notification methods objects
$events = array(); // list of event objects
@ -31,6 +32,7 @@ $included = false; // flag indicate scripts are loaded
$nSubscribed = 0; // Number of topics subsribed
$logFh = null; // filehandle of log file
$curlErr = 0; // Number of errors returned by curl
$configDir = "./config"; // default config dir (production value is /etc/moha/)
// topics definition
$topics["zigbee2mqtt"] = new topic;
@ -55,13 +57,23 @@ define( "ALL", DEBUG | INFO | NOTICE | WARNING | ERROR);
$logLevel = ALL;
$notificationLevel = WARNING | ERROR;
require "utils.php";
require "mqtt_functions.php";
require "events.php";
require "db_functions.php";
require "class/availability.php";
//include predefined file witch define constants for devices
if (is_readable($configDir . "/" . "devices_constants.php"))
{
$hooksList[] = $configDir . "/" . "devices_constants.php";
//echo "hooklist"; print_r($hooksList); echo EOL;
logger(INFO, sprintf(_("%s/devices_constants.define found, so it will be included :-)"), $configDir));
}else
{
logger(WARNING, sprintf(_("%s/devices_constants.define not found, so not included :-)"), $configDir));
}
// defining callback functions
$client->onConnect('connectResponse');
$client->onDisconnect('disconnectResponse');
@ -92,14 +104,12 @@ while (true)
$client->loop();
if ($dbInit == 2 and ! $included)
{
$hooksList = array();
loadHooks("./hooks", $hooksList);
//print_r($hooksList);
if (!empty($hooksList))
{
foreach ($hooksList as $hook)
{
echo "Including $hook" . EOL;
logger(INFO, _("Including ") . $hook . EOL);
include $hook;
}
}
@ -133,6 +143,7 @@ function loadHooks($dir, &$hookList)
global $included;
$files = scandir($dir);
//print_r($files);
foreach ($files as $file)
{
//echo "=====> $file" . EOL;
@ -155,8 +166,6 @@ function loadHooks($dir, &$hookList)
$included = true;
}
function endMoha()
{
global $topics, $nSubscribed ,$client, $logFh, $connected;