2022-01-02 13:07:02 +01:00
|
|
|
<?php
|
2022-01-28 23:05:58 +01:00
|
|
|
logger(DEBUG, _("Including class main.php"), __FILE__ . ":" . __LINE__);
|
2022-01-17 00:18:50 +01:00
|
|
|
|
2022-01-02 13:07:02 +01:00
|
|
|
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;
|
2022-01-08 11:51:50 +01:00
|
|
|
public $callback;
|
2022-01-02 13:07:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
class device
|
|
|
|
{
|
2022-01-19 00:22:34 +01:00
|
|
|
public $method; //0 = auto or 1 = manual
|
2022-01-02 13:07:02 +01:00
|
|
|
public $topic;
|
|
|
|
public $ieeeAddress;
|
|
|
|
public $groupID;
|
|
|
|
public $friendlyName;
|
|
|
|
public $powerSource;
|
|
|
|
public $description;
|
|
|
|
public $functions;
|
|
|
|
public $payload;
|
2022-01-19 00:22:34 +01:00
|
|
|
public $availability;
|
2022-01-23 09:46:06 +01:00
|
|
|
public $toConfirm;
|
2022-01-27 18:41:16 +01:00
|
|
|
public $triggerDevice;
|
2022-01-02 13:07:02 +01:00
|
|
|
|
2022-01-27 18:41:16 +01:00
|
|
|
public function __construct()
|
2022-01-02 13:07:02 +01:00
|
|
|
{
|
2022-01-19 00:22:34 +01:00
|
|
|
$this->availability = array("value" => null, "functions" => array());
|
|
|
|
}
|
|
|
|
|
|
|
|
public function set($method=0) //, $event = null)
|
|
|
|
{
|
|
|
|
$this->method = $method;
|
|
|
|
publish($this->topic . "/" . $this->friendlyName, $this->payload, "set"); //, $event);
|
2022-01-02 13:07:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function get()
|
|
|
|
{
|
2022-01-19 00:22:34 +01:00
|
|
|
publish($this->topic . "/" . $this->friendlyNames, $this->payload, "get"); //, $event);
|
2022-01-02 13:07:02 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2022-01-30 00:21:50 +01:00
|
|
|
class watch
|
|
|
|
{
|
|
|
|
public $topic;
|
|
|
|
public $property;
|
2022-01-30 19:59:22 +01:00
|
|
|
public $PropertyValue;
|
2022-01-30 00:21:50 +01:00
|
|
|
public $function;
|
2022-02-02 21:18:44 +01:00
|
|
|
public $conditions = array(
|
2022-01-30 00:21:50 +01:00
|
|
|
"<", ">", "==", ">=", "<="
|
|
|
|
);
|
2022-02-02 21:18:44 +01:00
|
|
|
public $acceptedValues = array(
|
|
|
|
"ON", "OFF"
|
|
|
|
);
|
2022-01-30 19:59:22 +01:00
|
|
|
public $condition;
|
2022-01-30 00:21:50 +01:00
|
|
|
|
|
|
|
public function __construct($topic, $fn, $property, $condition, $value)
|
|
|
|
{
|
2022-02-02 21:18:44 +01:00
|
|
|
global $conditions, $acceptedValues, $indexDevices;
|
|
|
|
logger(DEBUG, _("New Notification"), __FILE__ . ":" . __LINE__);
|
|
|
|
if (($device = getDevice($topic, $fn)) !== false)
|
2022-01-30 00:21:50 +01:00
|
|
|
{
|
|
|
|
$this->topic = $topic;
|
2022-02-02 21:18:44 +01:00
|
|
|
if (property_exists($device, $property))
|
2022-01-30 00:21:50 +01:00
|
|
|
{
|
|
|
|
$this->property = $property;
|
2022-02-02 21:18:44 +01:00
|
|
|
if (!is_numeric($value) and array_search($value, $this->acceptedValues) === false)
|
2022-01-30 00:21:50 +01:00
|
|
|
{
|
|
|
|
logger(ERROR, _("Value is not numeric"), __FILE__ . ":" . __LINE__ );
|
|
|
|
return false;
|
|
|
|
}
|
2022-02-02 21:18:44 +01:00
|
|
|
if (array_search($condition, $this->conditions))
|
2022-01-30 00:21:50 +01:00
|
|
|
{
|
2022-02-02 21:18:44 +01:00
|
|
|
$this->condition = $condition;
|
|
|
|
$this->function = '$value ' . $condition . " " . $value . ";";
|
|
|
|
logger(DEBUG, _("Test function is ") . $this->function, __FILE__ . ":" . __LINE__ );
|
2022-01-30 00:21:50 +01:00
|
|
|
}else
|
|
|
|
{
|
2022-02-02 21:18:44 +01:00
|
|
|
logger(ERROR, sprintf(_("Condition %s is not one of the permitted : "), $condition) . print_r($conditions, true), __FILE__ . ":" . __LINE__ );
|
2022-01-30 00:21:50 +01:00
|
|
|
return false;
|
|
|
|
}
|
2022-02-02 21:18:44 +01:00
|
|
|
$indexDevices[$device->ieeeAddress]->$property["functions"][] = array($this,"notifyCallback");
|
2022-01-30 00:21:50 +01:00
|
|
|
}else
|
|
|
|
{
|
|
|
|
logger(ERROR, _("Property do not exists"), __FILE__ . ":" . __LINE__ );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}else
|
|
|
|
{
|
|
|
|
logger(ERROR, _("Device do not exists"), __FILE__ . ":" . __LINE__ );
|
|
|
|
return false;
|
|
|
|
}
|
2022-02-02 21:18:44 +01:00
|
|
|
logger(DEBUG, var_export($this, true), __FILE__ . ":" . __LINE__ );
|
2022-01-30 00:21:50 +01:00
|
|
|
return $this;
|
|
|
|
}
|
2022-01-30 19:59:22 +01:00
|
|
|
|
|
|
|
public function notifyCallback(&$device, $property, $value)
|
|
|
|
{
|
|
|
|
if (eval($this->function))
|
|
|
|
{
|
2022-02-02 21:18:44 +01:00
|
|
|
logger(DEBUG, _("notifyCallback"));
|
2022-01-30 19:59:22 +01:00
|
|
|
$msg = sprintf(_("Device '%s' have property '%s' value %s %s %s"), $device->friendlyName, $property, $value, $this->condition, $this->PropertyValue );
|
|
|
|
notify($msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2022-01-30 00:21:50 +01:00
|
|
|
}
|
|
|
|
|
2022-01-02 13:07:02 +01:00
|
|
|
class interval
|
|
|
|
{
|
|
|
|
public $startDate;
|
|
|
|
public $endDate;
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|