1
0
moha/hooks/scripts/availability.php

53 lines
1.2 KiB
PHP

<?php
class availability
{
public $hookname = "availability";
public $initialized = true;
// by default all devices are listening for availability
function __construct()
{
global $devices;
$this->iterate();
}
private function iterate()
{
global $indexDevices;
foreach ($indexDevices as &$value)
{
$value->properties["availability"]["functions"][] = array($this,"callback");
}
}
// 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->availability != $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__);
}
break;
}
}
}
$hooks["availability"] = new availability();
?>