58 lines
1.4 KiB
PHP
58 lines
1.4 KiB
PHP
|
<?php
|
||
|
class hook
|
||
|
{
|
||
|
public $hookName = "";
|
||
|
public $active = true;
|
||
|
public $initialized = false;
|
||
|
protected $devicelist;
|
||
|
|
||
|
// list of devices we are listening to
|
||
|
function __construct()
|
||
|
{
|
||
|
logger(DEBUG, _("Initializing hook: ") . $this->hookName);
|
||
|
$this->installHooks();
|
||
|
}
|
||
|
|
||
|
function installHooks()
|
||
|
{
|
||
|
global $indexDevices;
|
||
|
$result = true;
|
||
|
// assigne the function to the sensors devices
|
||
|
if ($this->active === true)
|
||
|
{
|
||
|
foreach ($this->devicelist as $ieeeAddress => $property2change)
|
||
|
{
|
||
|
logger(DEBUG, _("Device: ") . $ieeeAddress);
|
||
|
if ($property2change[1] === false)
|
||
|
{
|
||
|
logger(DEBUG, _("Trying to store callback"));
|
||
|
if (isset($indexDevices[$ieeeAddress]))
|
||
|
{
|
||
|
$property = $property2change[0];
|
||
|
$indexDevices[$ieeeAddress]->$property["functions"][] = array($this,"callback");
|
||
|
$property2change[1] = true;
|
||
|
logger(DEBUG, sprintf(_("Property '%s' is initialized with callback"), $property2change[0]));
|
||
|
}else
|
||
|
{
|
||
|
logger(WARNING, sprintf(_("Hook %s can not initialize Property '%s' of device %s"), $this->hookName, $property2change[0], $ieeeAddress));
|
||
|
$result = false;
|
||
|
}
|
||
|
}else
|
||
|
{
|
||
|
logger(DEBUG, _("Callback already installed"));
|
||
|
}
|
||
|
}
|
||
|
echo "result => "; var_dump($result);
|
||
|
if ($result === true)
|
||
|
{
|
||
|
$this->initialized = true;
|
||
|
logger(DEBUG, $this->hookName . (" initialized"));
|
||
|
//var_dump($this);
|
||
|
}
|
||
|
}
|
||
|
return $result;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
?>
|