adding command test in apiserver\nsome debugging\nfree sms now running fine
This commit is contained in:
88
events.php
88
events.php
@@ -7,13 +7,15 @@ logger(DEBUG, _("Including events.php"), __FILE__ . ":" . __LINE__);
|
||||
function checkEvents()
|
||||
{
|
||||
global $logLevel, $events;
|
||||
logger(DEBUG, _("Checking events"), __FILE__ . ":" . __LINE__);
|
||||
|
||||
$oldLevel = $logLevel;
|
||||
//$logLevel = DEBUG;
|
||||
$exception = false;
|
||||
if ($events === null)
|
||||
/*if ($events === null)
|
||||
{
|
||||
$events = array();
|
||||
}
|
||||
}*/
|
||||
foreach ($events as $key => &$event)
|
||||
{
|
||||
$now = now();
|
||||
@@ -23,7 +25,8 @@ function checkEvents()
|
||||
if($event->dateTimeEvent < $now)
|
||||
{
|
||||
logger(DEBUG, _("Event must be executed"), __FILE__ . ":" . __LINE__);
|
||||
if (!empty($event->exceptionInterval))
|
||||
|
||||
if (!empty($event->exceptionInterval) and $event->isInterval == true)
|
||||
{
|
||||
logger(DEBUG, _("Testing exceptions"), __FILE__ . ":" . __LINE__);
|
||||
foreach($event->exceptionInterval as $key => $value)
|
||||
@@ -37,20 +40,24 @@ function checkEvents()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($exception === false)
|
||||
{
|
||||
if (is_callable($this->function))
|
||||
if (is_callable($event->function))
|
||||
{
|
||||
$this->function($event);
|
||||
logger(DEBUG, _("executing function") . $event->function[1], __FILE__ . ":" . __LINE__);
|
||||
$event->function();
|
||||
$event->published = $now;
|
||||
}else
|
||||
{
|
||||
logger(DEBUG, sprintf(_("sending command set %s => %s for %s"), $event->param ,bool2string($event->value), $event->device->friendlyName), __FILE__ . ":" . __LINE__);
|
||||
publish(mktopic($event->device), array($event->param => $event->value), "set");
|
||||
if ($event->method !== null) $event->device->properties[$event->param]["method"] = $event->method;
|
||||
if (($event->dateTimeEvent->add($event->recurrenceInterval)) === false)
|
||||
{
|
||||
logger(ERROR, _("Error in adding interval to event recurrence. event: ") . $key, __FILE__ . ":" . __LINE__);
|
||||
}
|
||||
$event->published = $now;
|
||||
}
|
||||
if ($event->method !== null) $event->device->properties[$event->param]["method"] = $event->method;
|
||||
if (($event->dateTimeEvent->add($event->recurrenceInterval)) === false)
|
||||
{
|
||||
logger(ERROR, _("Error in adding interval to event recurrence. event: ") . $key, __FILE__ . ":" . __LINE__);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -89,9 +96,11 @@ function setOneshotEvent(device &$deviceObject, string $datetime, $property, $va
|
||||
|
||||
// startDatetime and stopDatetime format : "yyyy-mm-dd hh:mm:ss"
|
||||
|
||||
function setRecurrentEvent(device &$deviceObject, string $property, $value, string $startDatetime, string $stopDatetime, int $hours, int $minutes, int $seconds, int $days, int $weeks, int $months, int $years, int $method = null)
|
||||
function setRecurrentEvent($function, $ieeeAddress, string $property, $value, bool $isInterval, string $startDatetime, string $stopDatetime, int $hours, int $minutes, int $seconds, int $days, int $weeks, int $months, int $years, int $method = null)
|
||||
{
|
||||
global $events;
|
||||
global $events, $indexDevices;
|
||||
logger(INFO, _("Setting recurrent event"), __FILE__ . ":" . __LINE__);
|
||||
|
||||
$string = "P";
|
||||
if (!empty($years)) $string .= $years . "Y";
|
||||
if (!empty($months)) $string .= $months . "M";
|
||||
@@ -101,24 +110,51 @@ function setRecurrentEvent(device &$deviceObject, string $property, $value, stri
|
||||
if (!empty($hours)) $string .= $hours . "H";
|
||||
if (!empty($months)) $string .= $months . "M";
|
||||
if (!empty($seconds)) $string .= $seconds . "S";
|
||||
|
||||
logger(DEBUG, _("reccurrent event string : ") . $string, __FILE__ . ":" . __LINE__);
|
||||
|
||||
|
||||
$event = new event;
|
||||
|
||||
$event->recurrenceInterval = new DateInterval($string);
|
||||
$event->startDatetime = new datetime($startDatetime);
|
||||
$event->stopDatetime = new datetime($stopDatetime);
|
||||
$event->ieee_address = $deviceObject->ieeeAddress;
|
||||
$event->topic = $deviceObject->topic;
|
||||
$event->device = & $deviceObject;
|
||||
$event->param = $property;
|
||||
$event->value = $value;
|
||||
$event->dateTimeEvent = $event->startDatetime;
|
||||
if (($event->dateTimeEvent->add($event->recurrenceInterval)) === false)
|
||||
// pb in recurrent event in case of date and not interval
|
||||
if ($isInterval === true)
|
||||
{
|
||||
logger(ERROR, _("Error in event recurrence. event: ") . $key, __FILE__ . ":" . __LINE__);
|
||||
|
||||
$event->recurrenceInterval = new DateInterval($string);
|
||||
}else
|
||||
{
|
||||
$event->recurrenceInterval = 0;
|
||||
}
|
||||
|
||||
if (!empty($startDatetime))
|
||||
{
|
||||
$event->startDatetime = new datetime($startDatetime);
|
||||
}else
|
||||
{
|
||||
$event->startDatetime = now();
|
||||
}
|
||||
$event->dateTimeEvent = $event->startDatetime;
|
||||
|
||||
if (!empty($stopDatetime))
|
||||
{
|
||||
$event->stopDatetime = new datetime($stopDatetime);
|
||||
}
|
||||
if (!empty($ieeeAddress))
|
||||
{
|
||||
$event->ieee_address = $ieeeAddress;
|
||||
$event->topic = $indexDevices[$deviceObject]->topic;
|
||||
$event->device = &$indexDevices[$deviceObject];
|
||||
$event->param = $property;
|
||||
$event->value = $value;
|
||||
}
|
||||
|
||||
if ($event->recurrenceInterval != 0)
|
||||
{
|
||||
if (($event->dateTimeEvent->add($event->recurrenceInterval)) === false)
|
||||
{
|
||||
logger(ERROR, _("Error in event recurrence. event: ") . $key, __FILE__ . ":" . __LINE__);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
if ($method !== null) $event->method = $method;
|
||||
return 0;
|
||||
}
|
||||
|
||||
function setDelay(device &$deviceObject, float $delay, string $unit, string $property, $value, bool $replace=false, int $method = null)
|
||||
|
||||
Reference in New Issue
Block a user