2022-01-02 18:14:13 +01:00
|
|
|
<?php
|
|
|
|
|
2022-08-12 10:41:55 +02:00
|
|
|
class availability extends hook
|
2022-01-02 18:14:13 +01:00
|
|
|
{
|
2022-01-17 00:18:50 +01:00
|
|
|
public $hookname = "availability";
|
2022-06-13 19:22:08 +02:00
|
|
|
public $active = true;
|
2022-01-02 18:14:13 +01:00
|
|
|
// by default all devices are listening for availability
|
2022-08-12 10:41:55 +02:00
|
|
|
protected $devicelist = array();
|
2022-01-02 18:14:13 +01:00
|
|
|
|
2022-08-12 10:41:55 +02:00
|
|
|
function init()
|
2022-01-06 13:03:26 +01:00
|
|
|
{
|
2022-08-12 10:41:55 +02:00
|
|
|
global $indexDevices;
|
2022-01-17 00:18:50 +01:00
|
|
|
$this->iterate();
|
2022-01-06 13:03:26 +01:00
|
|
|
}
|
|
|
|
|
2022-08-12 10:41:55 +02:00
|
|
|
protected function iterate()
|
2022-01-06 13:03:26 +01:00
|
|
|
{
|
2022-01-17 00:18:50 +01:00
|
|
|
global $indexDevices;
|
2022-08-12 10:41:55 +02:00
|
|
|
foreach ($indexDevices as $ieeeAddress => $value)
|
2022-01-06 13:03:26 +01:00
|
|
|
{
|
2022-08-12 10:41:55 +02:00
|
|
|
$deviceList[] = array( $ieeeAdress => "availability");
|
2022-01-06 13:03:26 +01:00
|
|
|
}
|
2022-08-12 10:41:55 +02:00
|
|
|
$this->installHooksFunction($indexDevices);
|
2022-01-06 13:03:26 +01:00
|
|
|
}
|
2022-01-17 00:18:50 +01:00
|
|
|
|
2022-06-13 19:22:08 +02:00
|
|
|
function installHooks(&$indexDevices)
|
|
|
|
{
|
2022-08-12 10:41:55 +02:00
|
|
|
static $indexDevicesSize;
|
|
|
|
$tmp = count($indexDevices);
|
|
|
|
if ($tmp != $indexDevicesSize)
|
|
|
|
{
|
|
|
|
$this->iterate();
|
|
|
|
$indexDevicesSize = $tmp;
|
|
|
|
}
|
|
|
|
return false;
|
2022-06-13 19:22:08 +02:00
|
|
|
}
|
2022-08-12 10:41:55 +02:00
|
|
|
|
2022-01-02 18:14:13 +01:00
|
|
|
// callback fonction. Is called with these 3 parameters
|
|
|
|
// $device -> calling device
|
2022-01-06 13:03:26 +01:00
|
|
|
// $property -> parameter passed by mqtt
|
2022-01-02 18:14:13 +01:00
|
|
|
// $value -> value of the parameter
|
2022-01-06 13:03:26 +01:00
|
|
|
public function callBack($device, $property, $value)
|
2022-01-02 18:14:13 +01:00
|
|
|
{
|
2022-01-06 13:03:26 +01:00
|
|
|
switch($property)
|
2022-01-02 18:14:13 +01:00
|
|
|
{
|
|
|
|
case "availability": // theorically can't be other, but ....
|
2022-08-12 10:41:55 +02:00
|
|
|
if ($device->properties["availability"]["value]"] != $value)
|
2022-01-02 18:14:13 +01:00
|
|
|
{
|
|
|
|
//echo "==========>>>>>> Availability $value" . EOL;
|
2022-01-20 00:26:57 +01:00
|
|
|
//if (!empty($device->availability))
|
2022-08-12 10:41:55 +02:00
|
|
|
//{[ Torrent911.com]
|
2022-01-20 00:26:57 +01:00
|
|
|
$log = ALERT;
|
|
|
|
//}else
|
|
|
|
//{
|
|
|
|
// $log = INFO;
|
|
|
|
//}
|
|
|
|
//$device->availability = $value;
|
2022-08-12 10:41:55 +02:00
|
|
|
|
|
|
|
logger($log, sprintf(_("Device: %s/%s is %s"), $device->topic, $device->friendlyName, bool2string($value)), __FILE__ . ":" . __LINE__, $device);
|
2022-01-02 18:14:13 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-06 13:03:26 +01:00
|
|
|
$hooks["availability"] = new availability();
|
2022-01-02 18:14:13 +01:00
|
|
|
?>
|