a lot of bugs corrected\nrdc_wc_eclairage
This commit is contained in:
@ -81,7 +81,7 @@ class db extends mysqli
|
||||
|
||||
function moyenne($deviceObject, $property, $time)
|
||||
{
|
||||
$query = "SELECT AVG(value) WHERE device='" . $deviceObject->ieeeAddress . "' AND property='" . $property . "' AND TIMEDIFF(NOW(), 'date') < " . $time;
|
||||
$query = "SELECT AVG(value) FROM logs WHERE device='" . $deviceObject->ieeeAddress . "' AND property='" . $property . "' AND TIMEDIFF(NOW(), 'date') < " . $time;
|
||||
if(!$this->result = $this->query($query))
|
||||
{
|
||||
logger(ERROR, _("mysql query errror: ") . $this->error, __FILE__ . ":" . __LINE__);
|
||||
|
@ -5,40 +5,45 @@ class hook
|
||||
public $active = true;
|
||||
public $initialized = false;
|
||||
protected $devicelist;
|
||||
protected $propertyInitialized;
|
||||
|
||||
// list of devices we are listening to
|
||||
function __construct()
|
||||
{
|
||||
logger(INFO, _("Initializing hook: ") . $this->hookName);
|
||||
$this->installHooks();
|
||||
//$this->installHooks();
|
||||
foreach ($this->devicelist as $ieeeAddress => $property)
|
||||
{
|
||||
$this->propertyInitialized[$ieeeAddress][$property] = false;
|
||||
}
|
||||
if (method_exists($this, "init"))
|
||||
{
|
||||
$this->init();
|
||||
}
|
||||
}
|
||||
|
||||
function installHooks()
|
||||
function installHooks(&$indexDevices)
|
||||
{
|
||||
global $indexDevices;
|
||||
global $devices;
|
||||
$result = true;
|
||||
// assigne the function to the sensors devices
|
||||
if ($this->active === true)
|
||||
{
|
||||
foreach ($this->devicelist as $ieeeAddress => $property2change)
|
||||
foreach ($this->devicelist as $ieeeAddress => $property)
|
||||
{
|
||||
logger(DEBUG, _("Device: ") . $ieeeAddress, __FILE__ . ":" . __LINE__);
|
||||
if ($property2change[1] === false)
|
||||
if ($this->propertyInitialized[$ieeeAddress][$property] === false)
|
||||
{
|
||||
logger(DEBUG, _("Trying to store callback"), __FILE__ . ":" . __LINE__);
|
||||
if (isset($indexDevices[$ieeeAddress]))
|
||||
if (isset($indexDevices[$ieeeAddress]->properties[$property]["functions"]))
|
||||
{
|
||||
$property = $property2change[0];
|
||||
$indexDevices[$ieeeAddress]->properties[$property]["functions"][] = array($this,"callback");
|
||||
$property2change[1] = true;
|
||||
logger(DEBUG, sprintf(_("Property '%s' is initialized with callback"), $property2change[0]), __FILE__ . ":" . __LINE__);
|
||||
$indexDevices[$ieeeAddress]->properties[$property]["functions"][$this->hookName] = array($this,"callback");
|
||||
$this->propertyInitialized[$ieeeAddress][$property] = true;
|
||||
logger(DEBUG, sprintf(_("Property '%s' of %s is initialized with callback"), $property, $indexDevices[$ieeeAddress]->friendlyName), __FILE__ . ":" . __LINE__);
|
||||
|
||||
}else
|
||||
{
|
||||
logger(WARNING, sprintf(_("Hook %s can not initialize Property '%s' of device %s"), $this->hookName, $property2change[0], $ieeeAddress), __FILE__ . ":" . __LINE__);
|
||||
logger(WARNING, sprintf(_("Hook %s can not initialize Property '%s' of device %s"), $this->hookName, $property, $ieeeAddress), __FILE__ . ":" . __LINE__);
|
||||
$result = false;
|
||||
}
|
||||
}else
|
||||
@ -53,12 +58,13 @@ class hook
|
||||
logger(INFO, $this->hookName . _(" initialized"), __FILE__ . ":" . __LINE__);
|
||||
//var_dump($this);
|
||||
}
|
||||
}else
|
||||
}/*else
|
||||
{
|
||||
$this->initialized = true;
|
||||
logger(INFO, $this->hookName . _("hook is disabled"), __FILE__ . ":" . __LINE__);
|
||||
}
|
||||
|
||||
}*/
|
||||
//print(var_export($indexDevices[$ieeeAddress],true));
|
||||
//storeDB($devices,"debug.devices");
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
@ -127,7 +127,7 @@ class watch
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function notifyCallback(&$device, $property, $value)
|
||||
public function notifyCallback($device, $property, $value)
|
||||
{
|
||||
if (eval($this->function))
|
||||
{
|
||||
|
Reference in New Issue
Block a user