debugging api and add notify command
This commit is contained in:
@@ -23,7 +23,6 @@ class device
|
||||
{
|
||||
public $method; //0 = auto or 1 = manual
|
||||
public $topic;
|
||||
public $device;
|
||||
public $ieeeAddress;
|
||||
public $groupID;
|
||||
public $friendlyName;
|
||||
@@ -78,37 +77,41 @@ class watch
|
||||
public $topic;
|
||||
public $property;
|
||||
public $PropertyValue;
|
||||
public $device;
|
||||
public $function;
|
||||
private $conditions = array(
|
||||
public $conditions = array(
|
||||
"<", ">", "==", ">=", "<="
|
||||
);
|
||||
public $acceptedValues = array(
|
||||
"ON", "OFF"
|
||||
);
|
||||
public $condition;
|
||||
|
||||
public function __construct($topic, $fn, $property, $condition, $value)
|
||||
{
|
||||
logger(DEBUG, _("New Notify object"), __FILE__ . ":" . __LINE__);
|
||||
if (($this->device = getDevice($topic, $fn)) === false)
|
||||
global $conditions, $acceptedValues, $indexDevices;
|
||||
logger(DEBUG, _("New Notification"), __FILE__ . ":" . __LINE__);
|
||||
if (($device = getDevice($topic, $fn)) !== false)
|
||||
{
|
||||
$this->topic = $topic;
|
||||
if (array_key_exist($property, $this->device))
|
||||
if (property_exists($device, $property))
|
||||
{
|
||||
$this->property = $property;
|
||||
if (!is_numeric($value))
|
||||
if (!is_numeric($value) and array_search($value, $this->acceptedValues) === false)
|
||||
{
|
||||
logger(ERROR, _("Value is not numeric"), __FILE__ . ":" . __LINE__ );
|
||||
return false;
|
||||
}
|
||||
if (array_search($condition, $conditions))
|
||||
if (array_search($condition, $this->conditions))
|
||||
{
|
||||
$this->function = '$value ' . $condition . " " . $value;
|
||||
logger(DEBUG, _("Test function is ") . $this->function);
|
||||
$this->condition = $condition;
|
||||
$this->function = '$value ' . $condition . " " . $value . ";";
|
||||
logger(DEBUG, _("Test function is ") . $this->function, __FILE__ . ":" . __LINE__ );
|
||||
}else
|
||||
{
|
||||
logger(ERROR, _("Condition is not one of the permitted"), __FILE__ . ":" . __LINE__ );
|
||||
logger(ERROR, sprintf(_("Condition %s is not one of the permitted : "), $condition) . print_r($conditions, true), __FILE__ . ":" . __LINE__ );
|
||||
return false;
|
||||
}
|
||||
$this->device[$ieeeAddress]->$property["functions"][] = array($this,"notifyCallback");
|
||||
$indexDevices[$device->ieeeAddress]->$property["functions"][] = array($this,"notifyCallback");
|
||||
}else
|
||||
{
|
||||
logger(ERROR, _("Property do not exists"), __FILE__ . ":" . __LINE__ );
|
||||
@@ -119,6 +122,7 @@ class watch
|
||||
logger(ERROR, _("Device do not exists"), __FILE__ . ":" . __LINE__ );
|
||||
return false;
|
||||
}
|
||||
logger(DEBUG, var_export($this, true), __FILE__ . ":" . __LINE__ );
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -126,6 +130,7 @@ class watch
|
||||
{
|
||||
if (eval($this->function))
|
||||
{
|
||||
logger(DEBUG, _("notifyCallback"));
|
||||
$msg = sprintf(_("Device '%s' have property '%s' value %s %s %s"), $device->friendlyName, $property, $value, $this->condition, $this->PropertyValue );
|
||||
notify($msg);
|
||||
}
|
||||
|
Reference in New Issue
Block a user