1
0
moha/class/hook_class.php

73 lines
2.1 KiB
PHP
Raw Normal View History

2022-01-17 00:18:50 +01:00
<?php
class hook
{
public $hookName = "";
public $active = true;
public $initialized = false;
protected $devicelist;
protected $propertyInitialized;
2022-01-17 00:18:50 +01:00
// list of devices we are listening to
function __construct()
{
2022-03-04 22:30:16 +01:00
logger(INFO, _("Initializing hook: ") . $this->hookName);
//$this->installHooks();
foreach ($this->devicelist as $ieeeAddress => $property)
{
$this->propertyInitialized[$ieeeAddress][$property] = false;
}
2022-01-23 09:46:06 +01:00
if (method_exists($this, "init"))
{
$this->init();
}
2022-01-17 00:18:50 +01:00
}
function installHooks(&$indexDevices)
2022-01-17 00:18:50 +01:00
{
global $devices;
2022-01-17 00:18:50 +01:00
$result = true;
// assigne the function to the sensors devices
if ($this->active === true)
{
foreach ($this->devicelist as $ieeeAddress => $property)
2022-01-17 00:18:50 +01:00
{
2022-01-28 23:05:58 +01:00
logger(DEBUG, _("Device: ") . $ieeeAddress, __FILE__ . ":" . __LINE__);
if ($this->propertyInitialized[$ieeeAddress][$property] === false)
2022-01-17 00:18:50 +01:00
{
2022-01-28 23:05:58 +01:00
logger(DEBUG, _("Trying to store callback"), __FILE__ . ":" . __LINE__);
if (isset($indexDevices[$ieeeAddress]->properties[$property]["functions"]))
2022-01-17 00:18:50 +01:00
{
$indexDevices[$ieeeAddress]->properties[$property]["functions"][$this->hookName] = array($this,"callback");
$this->propertyInitialized[$ieeeAddress][$property] = true;
logger(DEBUG, sprintf(_("Property '%s' of %s is initialized with callback"), $property, $indexDevices[$ieeeAddress]->friendlyName), __FILE__ . ":" . __LINE__);
2022-01-17 00:18:50 +01:00
}else
{
logger(WARNING, sprintf(_("Hook %s can not initialize Property '%s' of device %s"), $this->hookName, $property, $ieeeAddress), __FILE__ . ":" . __LINE__);
2022-01-17 00:18:50 +01:00
$result = false;
}
}else
{
2022-01-28 23:05:58 +01:00
logger(DEBUG, _("Callback already installed"), __FILE__ . ":" . __LINE__);
2022-01-17 00:18:50 +01:00
}
}
2022-01-17 21:01:11 +01:00
//echo "result => "; var_dump($result);
2022-01-17 00:18:50 +01:00
if ($result === true)
{
$this->initialized = true;
2022-03-04 22:30:16 +01:00
logger(INFO, $this->hookName . _(" initialized"), __FILE__ . ":" . __LINE__);
2022-01-17 00:18:50 +01:00
//var_dump($this);
}
}/*else
{
$this->initialized = true;
2022-03-04 22:30:16 +01:00
logger(INFO, $this->hookName . _("hook is disabled"), __FILE__ . ":" . __LINE__);
}*/
//print(var_export($indexDevices[$ieeeAddress],true));
//storeDB($devices,"debug.devices");
2022-01-17 00:18:50 +01:00
return $result;
}
}
?>