1
0

modified device database and the code for managing it

This commit is contained in:
2022-02-12 15:23:58 +01:00
parent 314305bcb1
commit 7d1dd25f2a
13 changed files with 156 additions and 113 deletions

View File

@@ -34,6 +34,7 @@ class device
public $availability;
public $toConfirm;
public $triggerDevice;
public $properties = array();
public function __construct()
{
@@ -89,17 +90,17 @@ class watch
public function __construct($topic, $fn, $property, $condition, $value)
{
global $conditions, $acceptedValues, $indexDevices;
global $conditions, $indexDevices;
logger(DEBUG, _("New Notification"), __FILE__ . ":" . __LINE__);
if (($device = getDevice($topic, $fn)) !== false)
{
$this->topic = $topic;
if (property_exists($device, $property))
if (array_key_exists($property, $device->properties))
{
$this->property = $property;
if (!is_numeric($value) and array_search($value, $this->acceptedValues) === false)
if (!is_numeric($value) or array_search($value, $this->acceptedValues) === false)
{
logger(ERROR, _("Value is not numeric"), __FILE__ . ":" . __LINE__ );
logger(ERROR, _("Value is not numeric or not accepted"), __FILE__ . ":" . __LINE__ );
return false;
}
if (array_search($condition, $this->conditions))
@@ -112,7 +113,7 @@ class watch
logger(ERROR, sprintf(_("Condition %s is not one of the permitted : "), $condition) . print_r($conditions, true), __FILE__ . ":" . __LINE__ );
return false;
}
$indexDevices[$device->ieeeAddress]->$property["functions"][] = array($this,"notifyCallback");
$indexDevices[$device->ieeeAddress]->properties[$property]["functions"][] = array($this,"notifyCallback");
}else
{
logger(ERROR, _("Property do not exists"), __FILE__ . ":" . __LINE__ );
@@ -132,11 +133,9 @@ 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 );
$msg = sprintf(_("Device '%s' have property '%s' value %s %s %s"), $device->friendlyName, $property, bool2string($value), $this->condition, bool2string($this->PropertyValue) );
notify($msg);
}
}
}