1
0

some debbuging

This commit is contained in:
2022-01-02 18:14:13 +01:00
parent 2e6b2fe5cb
commit d79463fbd4
11 changed files with 147 additions and 242 deletions

41
class/availability.php Normal file
View File

@ -0,0 +1,41 @@
<?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;
}
$device->availability = $value
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;
?>

View File

@ -1,31 +0,0 @@
<?php
<?php
class availability
{
// by default all devices are listening for availability
// callback fonction. Is called with these 4 parameters
public function callBack($topic, $fn, $param, $value)
{
global $devices, $indexDevices, $notificationMethods;
switch($param)
{
case "availability":
if ($value != "online")
{
//your code here
logger("Device: " . $topic . "/" . $fn . "is offline");
}
break;
}
echo _("notification received from MQTT") . EOL;
//echo $param . "=> " . $value . EOL;
}
}
$hooks["availability"] = new availability;
?>
?>

View File

@ -68,41 +68,4 @@ class interval
public $endDate;
}
class notificationMethod
{
public $url;
public $msg;
public $active;
public $level;
function __construct($url)
{
$this->url = $url;
}
public function send($text=null)
{
if (empty($text)) $text= $this->msg;
if (!empty($msg))
{
$opts = array(
'http'=>array(
'method'=>"GET",
'header'=>"Accept-language: fr\r\n"
)
);
$context = stream_context_create($opts);
/* Envoi une requête HTTP vers $url
avec les en-têtes additionnels ci-dessus */
$fp = fopen($url . "/" . $msg, 'r', false, $context);
$response = stream_get_contents($fp, -1, 0);
fclose($fp);
}else
{
// TODO log_error("notificationMethod : $msg is null");
}
}
}
?>

View File

@ -1,106 +0,0 @@
class Message
{
public $id;
public $state = false;
public $msg;
}
class topic {
public $mid;
public $status;
public $info;
public $devices;
public $groups;
public $extensions;
public $config;
}
class device
{
public $method; //auto or manual
public $topic;
public $device;
public $ieeeAddress;
public $groupID;
public $friendlyName;
public $powerSource;
public $description;
public $functions;
public $payload;
public $availibility;
public function set($event)
{
publish($this, $this->payload, "set", $event);
}
public function get()
{
publish($this, $this->payload, "get", $event);
}
}
class ranges
{
public $start; //datetime
public $end; //datetime
}
class event
{
public $ieeeAddress;
public $topic;
public $param;
public $value;
public $device;
public $published;
public $dateTimeEvent; // datetime : next occurence for recurrent event
public $startDatetime;
public $stopDatetime;
public $recurrenceInterval; // interval : for recurrent event
public $exceptionInterval; // array of object ranges
}
class interval
{
public $startDate;
public $endDate;
}
class notificationMethod
{
public $url;
public $msg;
public $active;
public $level;
function __construct($url)
{
$this->url = $url;
}
public function send($text=null)
{
if (empty($text)) $text= $this->msg;
if (!empty($msg))
{
$opts = array(
'http'=>array(
'method'=>"GET",
'header'=>"Accept-language: fr\r\n"
)
);
$context = stream_context_create($opts);
/* Envoi une requête HTTP vers $url
avec les en-têtes additionnels ci-dessus */
$fp = fopen($url . "/" . $msg, 'r', false, $context);
$response = stream_get_contents($fp, -1, 0);
fclose($fp);
}else
{
// TODO log_error("notificationMethod : $msg is null");
}
}
}