1
0

added template and delete some debugging message

This commit is contained in:
daniel Tartavel 2022-01-06 13:11:18 +01:00
parent 004c6aa572
commit e702d333c8
3 changed files with 38 additions and 2 deletions

37
docs/template.php Normal file
View File

@ -0,0 +1,37 @@
<?php
class <name_of_class>
{
public $hookName = <public name of the hook>;
public $active = true; enable/disable hook (true => enabled)
private $devicelist = array(<ieee address or constant defined in config/devices_constants.php>) => <property of the device to watch>);
// assigne the function to the sensors devices
function __construct()
{
global $indexDevices;
if ($this->active === true)
{
foreach ($this->devicelist as $ieeeAddress => $property)
{
$indexDevices[$ieeeAddress]->$property["functions"][] = array($this,"callback");
}
}
// put here your code to init the class
}
// callback fonction. Is called with these 3 parameters
// $device -> calling device
// $property -> property of the device (given by mqtt)
// $value -> value of the property
public function callBack(&$device, $property, $value)
{
// here your code
logger (INFO, _("%s: notification received from MQTT from %s => parameter: %s value: %s"), $this->hookName, $device->friendlyName, $property, $value);
}
}
$hooks[<public name of the hook>] = new <name_of_class>();
?>

View File

@ -31,7 +31,6 @@ class rdc_sdb_eclairage
foreach ($this->devicelist as $ieeeAddress => $property) foreach ($this->devicelist as $ieeeAddress => $property)
{ {
$indexDevices[$ieeeAddress]->$property["functions"][] = array($this,"callback"); $indexDevices[$ieeeAddress]->$property["functions"][] = array($this,"callback");
print_r($indexDevices[$ieeeAddress]);
} }
} }
} }

View File

@ -118,7 +118,7 @@ function connectResponse($r, $message)
function subscribeResponse($mid, $qosCount) function subscribeResponse($mid, $qosCount)
{ {
global $topics, $mids, $nSubscribed; global $topics, $mids, $nSubscribed;
print_r($mids); //print_r($mids);
$key = $mids[$mid]; $key = $mids[$mid];
echo _("Subscribed to ") . $key . EOL; echo _("Subscribed to ") . $key . EOL;
$topics[$key]->status = true; $topics[$key]->status = true;