DTux
/
dtux__moha
Archived
1
0
Fork 0
This repository has been archived on 2023-11-30. You can view files and clone it, but cannot push or open issues or pull requests.
dtux__moha/class/main.php

160 lines
3.8 KiB
PHP

<?php
logger(DEBUG, _("Including class main.php"), __FILE__ . ":" . __LINE__);
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;
public $callback;
public $getOnStart = false;
public $lastSeen;
public $timeOut = 5;
public $notificationSent = false;
}
class device
{
public $topic;
public $ieeeAddress;
public $groupID;
public $friendlyName;
public $powerSource;
public $description;
public $functions;
public $payload;
public $toConfirm;
public $triggerDevice;
public $properties = array();
public $lastSeen;
public $users2notify = array();
public function __construct()
{
$this->properties["availability"] = array("value" => null, "functions" => array());
}
public function set($property, $method = null) //, $event = null)
{
if ($method !== null)
{
$this->properties[$property]["method"] = $method;
}
publish($this->topic . "/" . $this->friendlyName, $this->payload, "set");//, $event);
}
public function get()
{
publish($this->topic . "/" . $this->friendlyName, $this->payload, "get"); //, $event);
}
}
class ranges
{
public $start; //datetime
public $end; //datetime
}
class event
{
public $id;
public $key;
public $ieeeAddress;
public $topic;
public $param;
public $value;
public $function;
public $device;
public $published;
public $dateTimeEvent; // recurrent event: datetime
public $startDatetime;
public $stopDatetime;
public $recurrence; // recurrent event: interval or date to add
public $exceptionInterval; // array of object ranges
public $method; // cf: constants.php (IDLE, AUTO, MANUAL)
public $isInterval = false; // 0 => recurence by date 1 => by interval
}
class watch
{
public $topic;
public $property;
public $PropertyValue;
public $function;
public $conditions = array(
"<", ">", "==", ">=", "<="
);
public $acceptedValues = array(
"ON", "OFF"
);
public $condition;
public function __construct($topic, $fn, $property, $condition, $value)
{
global $conditions, $indexDevices;
logger(DEBUG, _("New Notification"), __FILE__ . ":" . __LINE__);
if (($device = getDevice($topic, $fn)) !== false)
{
$this->topic = $topic;
if (array_key_exists($property, $device->properties))
{
$this->property = $property;
if (!is_numeric($value) or array_search($value, $this->acceptedValues) === false)
{
logger(ERROR, _("Value is not numeric or not accepted"), __FILE__ . ":" . __LINE__ );
return false;
}
if (array_search($condition, $this->conditions))
{
$this->condition = $condition;
$this->function = '$value ' . $condition . " " . $value . ";";
logger(DEBUG, _("Test function is ") . $this->function, __FILE__ . ":" . __LINE__ );
}else
{
logger(ERROR, sprintf(_("Condition %s is not one of the permitted : "), $condition) . print_r($conditions, true), __FILE__ . ":" . __LINE__ );
return false;
}
$indexDevices[$device->ieeeAddress]->properties[$property]["functions"][] = array($this,"notifyCallback");
}else
{
logger(ERROR, _("Property do not exists"), __FILE__ . ":" . __LINE__ );
return false;
}
}else
{
logger(ERROR, _("Device do not exists"), __FILE__ . ":" . __LINE__ );
return false;
}
logger(DEBUG, var_export($this, true), __FILE__ . ":" . __LINE__ );
return $this;
}
public function notifyCallback($device, $property, $value)
{
if (eval($this->function))
{
logger(DEBUG, _("notifyCallback"));
$msg = sprintf(_("Device '%s' have property '%s' value %s %s %s"), $device->friendlyName, $property, bool2string($value), $this->condition, bool2string($this->PropertyValue) );
notify($msg, $device);
}
}
}
class interval
{
public $startDate;
public $endDate;
}
?>