2022-01-02 18:14:13 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class availability
|
|
|
|
{
|
|
|
|
// by default all devices are listening for availability
|
|
|
|
|
|
|
|
// callback fonction. Is called with these 3 parameters
|
|
|
|
// $device -> calling device
|
|
|
|
// $param -> parameter passed by mqtt
|
|
|
|
// $value -> value of the parameter
|
|
|
|
public function callBack($device, $param, $value)
|
|
|
|
{
|
|
|
|
switch($param)
|
|
|
|
{
|
|
|
|
case "availability": // theorically can't be other, but ....
|
|
|
|
if ($device->availability != $value)
|
|
|
|
{
|
|
|
|
//echo "==========>>>>>> Availability $value" . EOL;
|
|
|
|
if (!empty($device->availability))
|
|
|
|
{
|
|
|
|
$log = WARNING;
|
|
|
|
}else
|
|
|
|
{
|
|
|
|
$log = INFO;
|
|
|
|
}
|
2022-01-03 21:11:52 +01:00
|
|
|
$device->availability = $value;
|
2022-01-02 18:14:13 +01:00
|
|
|
logger($log, sprintf(_("Device: %s/%s is %s"), $topic, $fn , $value));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
echo _("notification received from MQTT") . EOL;
|
|
|
|
//echo $param . "=> " . $value . EOL;
|
|
|
|
}
|
|
|
|
public function getHook()
|
|
|
|
{
|
|
|
|
return array($this,"callback");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$hooks["availability"] = new availability;
|
|
|
|
?>
|