1
0
moha/docs/template.php

38 lines
1.1 KiB
PHP
Raw Normal View History

<?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>();
?>