debugged notification of availability of devices
This commit is contained in:
@ -1,31 +1,40 @@
|
||||
<?php
|
||||
|
||||
class availability
|
||||
class availability extends hook
|
||||
{
|
||||
public $hookname = "availability";
|
||||
public $initialized = true;
|
||||
public $active = true;
|
||||
// by default all devices are listening for availability
|
||||
protected $devicelist = array();
|
||||
|
||||
function __construct()
|
||||
function init()
|
||||
{
|
||||
global $devices;
|
||||
global $indexDevices;
|
||||
$this->iterate();
|
||||
}
|
||||
|
||||
private function iterate()
|
||||
protected function iterate()
|
||||
{
|
||||
global $indexDevices;
|
||||
foreach ($indexDevices as &$value)
|
||||
foreach ($indexDevices as $ieeeAddress => $value)
|
||||
{
|
||||
$value->properties["availability"]["functions"][] = array($this,"callback");
|
||||
$deviceList[] = array( $ieeeAdress => "availability");
|
||||
}
|
||||
$this->installHooksFunction($indexDevices);
|
||||
}
|
||||
|
||||
function installHooks(&$indexDevices)
|
||||
{
|
||||
return true;
|
||||
static $indexDevicesSize;
|
||||
$tmp = count($indexDevices);
|
||||
if ($tmp != $indexDevicesSize)
|
||||
{
|
||||
$this->iterate();
|
||||
$indexDevicesSize = $tmp;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// callback fonction. Is called with these 3 parameters
|
||||
// $device -> calling device
|
||||
// $property -> parameter passed by mqtt
|
||||
@ -35,18 +44,19 @@ class availability
|
||||
switch($property)
|
||||
{
|
||||
case "availability": // theorically can't be other, but ....
|
||||
if ($device->availability != $value)
|
||||
if ($device->properties["availability"]["value]"] != $value)
|
||||
{
|
||||
//echo "==========>>>>>> Availability $value" . EOL;
|
||||
//if (!empty($device->availability))
|
||||
//{
|
||||
//{[ Torrent911.com]
|
||||
$log = ALERT;
|
||||
//}else
|
||||
//{
|
||||
// $log = INFO;
|
||||
//}
|
||||
//$device->availability = $value;
|
||||
logger($log, sprintf(_("Device: %s/%s is %s"), $device->topic, $device->friendlyName, bool2string($value)), __FILE__ . ":" . __LINE__);
|
||||
|
||||
logger($log, sprintf(_("Device: %s/%s is %s"), $device->topic, $device->friendlyName, bool2string($value)), __FILE__ . ":" . __LINE__, $device);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
Reference in New Issue
Block a user