1
0

debugging hooks and events

This commit is contained in:
2022-01-20 00:26:57 +01:00
parent e4703dafc8
commit 10f2a1087a
9 changed files with 66 additions and 58 deletions

View File

@@ -10,19 +10,22 @@ function checkEvents()
$exception = false;
foreach ($events as $key => $event)
{
$now = now();
if (!empty($event->startDatetime))
{
if($event->dateTimeEvent <= now())
logger(DEBUG, _("StarDatetime is set"));
if($event->dateTimeEvent < $now)
{
logger(DEBUG, _("Event must be executed"));
if (!empty($event->exceptionInterval))
{
logger(DEBUG, _("Testing exceptions"));
foreach($event->exceptionInterval as $key => $value)
{
if($datetime("now") >= $value->start and $datetime("now") <= $value->end)
if($now > $value->start and $now < $value->end)
{
$exception = true;
}elseif($datetime("now") >= $value->stop)
}elseif($now > $value->stop)
{
unset($event->exceptionInterval[$key]);
}
@@ -30,19 +33,19 @@ function checkEvents()
}
if ($exception === false)
{
echo "---->sending command set " . $event->param . "=>" . $event->value . " to " . $event->device->friendlyName . EOL;
logger(DEBUG, sprintf(_("sending command set %s => %s for %s"), $event->param ,bool2string($event->value), $event->device->friendlyName));
publish(mktopic($event->device), array($event->param => $event->value), "set", $key);
if (($event->dateTimeEvent->add($event->recurrenceInterval)) === false)
{
logger(ERROR, _("Error in event recurrence. event: ") . $key);
logger(ERROR, _("Error in adding interval to event recurrence. event: ") . $key);
}
}
}
}elseif (!empty($event->dateTimeEvent) and $event->dateTimeEvent <= now())
}elseif (!empty($event->dateTimeEvent) and $event->dateTimeEvent < now())
{
logger(DEBUG, sprintf(_("---->sending command set %s => %s to %s"),$event->param, $event->value, $event->device->friendlyName));
logger(DEBUG, sprintf(_("Sending command set %s => %s to %s"),$event->param, bool2string($event->value), $event->device->friendlyName));
$mid = publish(mktopic($event->device), array($event->param => $event->value), "set"); //, $key);
$event->published = now();
$event->published = $now;
//echo "#################################\nUnsetting event $key \n###########################" . EOL;
unset($events[$key]);
}
@@ -50,7 +53,7 @@ function checkEvents()
//print_r($events);
}
function setOneshotEvent(&$device, $datetime, $param, $value, $replace=false)
function setOneshotEvent(&$device, $datetime, $property, $value, $replace=false)
{
global $events;
$events[] = new event;
@@ -58,12 +61,12 @@ function setOneshotEvent(&$device, $datetime, $param, $value, $replace=false)
$events[$key]->dateTimeEvent = new dateTime($datetime);
$events[$key]->ieeeAddress = $device->ieeeAddress;
$events[$key]->topic = $device->topic;
$events[$key]->param = $param;
$events[$key]->param = $property;
$events[$key]->value = $value;
$events[$key]->device = & $device;
}
function setRecurrentEvent(&$device, $param, $value, $startDatetime, $stopDatetime, $hours, $minutes, $seconds, $days, $weeks, $months, $years)
function setRecurrentEvent(&$device, $property, $value, $startDatetime, $stopDatetime, $hours, $minutes, $seconds, $days, $weeks, $months, $years)
{
global $events;
$string = "P";
@@ -84,7 +87,7 @@ function setRecurrentEvent(&$device, $param, $value, $startDatetime, $stopDateti
$event->ieee_address = $device->ieeeAddress;
$event->topic = $device->topic;
$event->device = & $device;
$event->param = $param;
$event->param = $property;
$event->value = $value;
$event->dateTimeEvent = $event->startDatetime;
if (($event->dateTimeEvent->add($event->recurrenceInterval)) === false)
@@ -94,7 +97,7 @@ function setRecurrentEvent(&$device, $param, $value, $startDatetime, $stopDateti
}
}
function setDelay(&$device, $delay, $unit="second", $param, $value, $replace=false)
function setDelay(&$device, $delay, $unit="second", $property, $value, $replace=false)
{
global $events;
$datetime = new dateTime();
@@ -134,30 +137,30 @@ function setDelay(&$device, $delay, $unit="second", $param, $value, $replace=fal
//print_r($datetime);
if ($replace)
{
$eventKey = searchEvent($device, $param, $value);
$eventKey = searchEvent($device, $property, $value);
if ($eventKey !== false) deleteEvent($eventKey);
}
//$dt = $datetime->format("Y-m-d\TH:i:s\Z");
$events[] = new event;
$key = key($events);
$key = array_key_last($events);
$events[$key]->dateTimeEvent = $datetime;
$events[$key]->ieeeAddress = $device->ieeeAddress;
$events[$key]->topic = $device->topic;
$events[$key]->param = $param;
$events[$key]->param = $property;
$events[$key]->value = $value;
$events[$key]->device = & $device;
echo "new event";
logger (DEBUG, _('Setting new delay in $events[]'));
}
function searchEvent($device, $param , $value)
function searchEvent($device, $property , $value)
{
global $events;
echo "searching event" . EOL;
logger(DEBUG, _("searching event for device %s, property %s and value %s"), $device->friendlyName, $property, bool2string($value));
foreach($events as $key => $event)
{
//echo "Event : $event => $value" . EOL;
//echo "===>";print_r($event); echo EOL;
if($event->topic == $device->topic and $event->param == $param and $event->value == $value and $event->ieeeAddress == $device->ieeeAddress)
if($event->topic == $device->topic and $event->param == $property and $event->value == $value and $event->ieeeAddress == $device->ieeeAddress)
{
//echo "==============================\nfound " . $key . "\n=================================" . EOL;
return $key;
@@ -169,7 +172,7 @@ function searchEvent($device, $param , $value)
function deleteEvent($eventKey)
{
global $events;
if ($eventKey !==false)
if ($eventKey !== false)
{
unset ($events[$eventKey]);
logger(INFO, _("delete event key =") . $eventKey);