65 lines
1.6 KiB
PHP
65 lines
1.6 KiB
PHP
<?php
|
|
|
|
class availability extends hook
|
|
{
|
|
public $hookname = "availability";
|
|
public $active = true;
|
|
// by default all devices are listening for availability
|
|
protected $devicelist = array();
|
|
|
|
protected function iterate()
|
|
{
|
|
global $indexDevices;
|
|
foreach ($indexDevices as $ieeeAddress => $value)
|
|
{
|
|
if (!key_exists("availability", $value->properties))
|
|
{
|
|
$value->properties["availability"] = "";
|
|
}
|
|
}
|
|
$this->installHooksFunction($indexDevices);
|
|
}
|
|
|
|
function installHooks(&$indexDevices)
|
|
{
|
|
$this->installHooksFunction($indexDevices);
|
|
return false;
|
|
}
|
|
|
|
function installHook(&$device)
|
|
{
|
|
global $indexDevices;
|
|
$this->devicelist = array($device["device"]->ieeeAddress => "availability");
|
|
$this->installHooksFunction($indexDevices);
|
|
}
|
|
// callback fonction. Is called with these 3 parameters
|
|
// $device -> calling device
|
|
// $property -> parameter passed by mqtt
|
|
// $value -> value of the parameter
|
|
public function callBack($device, $property, $value)
|
|
{
|
|
switch($property)
|
|
{
|
|
case "availability": // theorically can't be other, but ....
|
|
if ($device->properties["availability"]["value]"] != $value)
|
|
{
|
|
//echo "==========>>>>>> Availability $value" . EOL;
|
|
//if (!empty($device->availability))
|
|
//{
|
|
$log = ALERT;
|
|
//}else
|
|
//{
|
|
// $log = INFO;
|
|
//}
|
|
//$device->availability = $value;
|
|
|
|
logger($log, sprintf(_("Device: %s/%s is %s"), $device->topic, $device->friendlyName, bool2string($value)), __FILE__ . ":" . __LINE__, $device);
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
$hooks["availability"] = new availability();
|
|
?>
|