added managing events
This commit is contained in:
parent
f2b24bc0fe
commit
260d220326
@ -8,11 +8,6 @@ function storeDB($db, $filepath)
|
||||
fclose($fp);
|
||||
}
|
||||
|
||||
function deviceTree(string $topic, array $fnTree, array &$device)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
function mkDevicesDB($topic, $json, $group=false)
|
||||
{
|
||||
global $devices, $listProperties, $listPropertiesKeys, $indexDevices, $dbInit, $logFh;
|
||||
|
99
events.php
99
events.php
@ -1,12 +1,43 @@
|
||||
<?php
|
||||
|
||||
/* for all functions, datetime parameter format is 'dd/mm/yy hh:mm:ss' */
|
||||
|
||||
|
||||
function checkEvents()
|
||||
{
|
||||
global $events, $indexDevices, $devices;
|
||||
//echo "===========> checking events" . EOL;
|
||||
$exception = false;
|
||||
foreach ($events as $key => $event)
|
||||
{
|
||||
if (!empty($event->dateTimeEvent) and $event->dateTimeEvent <= now())
|
||||
if (!empty($event->startDatetime))
|
||||
{
|
||||
if (($event->dateTimeEvent->add($event->recurrenceInterval)) === false)
|
||||
{
|
||||
logger(LOG_ERROR, "Error in event recurrence. event: " . $key);
|
||||
|
||||
}elseif($event->dateTimeEvent <= now())
|
||||
{
|
||||
if (!empty($event->exceptionInterval))
|
||||
{
|
||||
foreach($event->exceptionInterval as $key => $value)
|
||||
{
|
||||
if($datetime("now") >= $value->start and $datetime("now") <= $value->end)
|
||||
{
|
||||
$exception = true;
|
||||
}elseif($datetime("now") >= $value->stop)
|
||||
{
|
||||
unset($event->exceptionInterval[$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($exception === false)
|
||||
{
|
||||
echo "---->sending command set " . $event->param . "=>" . $event->value . " to " . $event->device->friendlyName . EOL;
|
||||
publish($event->device, array($event->param => $event->value), "set", $key);
|
||||
}
|
||||
}
|
||||
}elseif (!empty($event->dateTimeEvent) and $event->dateTimeEvent <= now())
|
||||
{
|
||||
echo "---->sending command set " . $event->param . "=>" . $event->value . " to " . $event->device->friendlyName . EOL;
|
||||
publish($event->device, array($event->param => $event->value), "set", $key);
|
||||
@ -18,7 +49,46 @@ function checkEvents()
|
||||
//print_r($events);
|
||||
}
|
||||
|
||||
function setDelay(&$device, $delay, $unit="sec", $param, $value, $replace=false)
|
||||
function setOneshotEvent(&$device, $datetime, $param, $value, $replace=false)
|
||||
{
|
||||
global $events;
|
||||
$events[] = new event;
|
||||
$key = key($events);
|
||||
$events[$key]->dateTimeEvent = new dateTime($datetime);
|
||||
$events[$key]->ieeeAddress = $device->ieeeAddress;
|
||||
$events[$key]->topic = $device->topic;
|
||||
$events[$key]->param = $param;
|
||||
$events[$key]->value = $value;
|
||||
$events[$key]->device = & $device;
|
||||
}
|
||||
|
||||
function setRecurrentEvent(&$device, $param, $value, $startDatetime, $stopDatetime, $hours, $minutes, $seconds, $days, $weeks, $months, $years)
|
||||
{
|
||||
global $events;
|
||||
$string = "P";
|
||||
if (!empty($years)) $string .= $days . "Y";
|
||||
if (!empty($months)) $string .= $days . "M";
|
||||
if (!empty($week)) $string .= $week . "W";
|
||||
if (!empty($days)) $string .= $days . "D";
|
||||
$string .= "T";
|
||||
if (!empty($hours)) $string .= $days . "H";
|
||||
if (!empty($months)) $string .= $days . "M";
|
||||
if (!empty($seconds)) $string .= $days . "S";
|
||||
|
||||
$event = new event;
|
||||
|
||||
$event->recurrenceInterval = new DateInterval($string);
|
||||
$event->startDatetime = new datetime($startDatetime);
|
||||
$event->stopDatetime = new datetime($stopDatetime);
|
||||
$event->ieee_address = $device->ieeeAddress;
|
||||
$event->topic = $device->topic;
|
||||
$event->device = & $device;
|
||||
$event->param = $param;
|
||||
$event->value = $value;
|
||||
$event->dateTimeEvent = $event->startDatetime;
|
||||
}
|
||||
|
||||
function setDelay(&$device, $delay, $unit="second", $param, $value, $replace=false)
|
||||
{
|
||||
global $events;
|
||||
$datetime = new dateTime();
|
||||
@ -26,29 +96,36 @@ function setDelay(&$device, $delay, $unit="sec", $param, $value, $replace=false)
|
||||
switch($unit)
|
||||
{
|
||||
case "second":
|
||||
$unit = "S";
|
||||
$s = "S";
|
||||
break;
|
||||
case "minute":
|
||||
$unit = "M";
|
||||
$s = "M";
|
||||
break;
|
||||
case "hour":
|
||||
$unit = "H";
|
||||
$s = "H";
|
||||
break;
|
||||
case "day":
|
||||
$unit = "D";
|
||||
$s = "D";
|
||||
break;
|
||||
case "week":
|
||||
$unit = "W";
|
||||
$s = "W";
|
||||
break;
|
||||
case "month":
|
||||
$unit = "M";
|
||||
$s = "M";
|
||||
break;
|
||||
case "year":
|
||||
$unit = "Y";
|
||||
$s = "Y";
|
||||
break;
|
||||
}
|
||||
$datetime->add(new DateInterval('PT'. $delay . $unit));
|
||||
//print_r($device);
|
||||
if (empty($s))
|
||||
{
|
||||
logger(LOG_ERROR, __("setDelay error: unit is empty"));
|
||||
}
|
||||
if (($datetime->add(new DateInterval('PT'. $delay . $s))) === false)
|
||||
{
|
||||
logger(LOG_ERROR, __("setDelay error: datetime->add"));
|
||||
}
|
||||
print_r($datetime);
|
||||
if ($replace)
|
||||
{
|
||||
$eventKey = searchEvent($device, $param, $value);
|
||||
|
@ -4,7 +4,7 @@ class rdc_panneau_salon
|
||||
// list of devices we are listening to
|
||||
private $devicelist = array("0x00124b0022ebac5c", "0x588e81fffe2cf695", "0x00124b001f900753", "0x04cf8cdf3c78aff0");
|
||||
public $delay = 3; // amount of time in $timeunit
|
||||
public $timeUnit = "minutes"; // unit of time for delay, second, minute, day, week, month, year
|
||||
public $timeUnit = "minute"; // unit of time for delay, second, minute, day, week, month, year
|
||||
|
||||
function __construct()
|
||||
{
|
||||
|
23
moha.php
23
moha.php
@ -59,6 +59,12 @@ class device
|
||||
}
|
||||
}
|
||||
|
||||
class ranges
|
||||
{
|
||||
public $start; //datetime
|
||||
public $end; //datetime
|
||||
}
|
||||
|
||||
class event
|
||||
{
|
||||
public $ieeeAddress;
|
||||
@ -67,18 +73,11 @@ class event
|
||||
public $value;
|
||||
public $device;
|
||||
public $published;
|
||||
public $dateTimeEvent;
|
||||
public $recurrenceDay;
|
||||
public $recurrenceMonth;
|
||||
public $recurrenceYear;
|
||||
public $recurrenceWeek;
|
||||
public $recurrenceHours;
|
||||
public $recurrenceMinutes;
|
||||
public $time;
|
||||
public $day;
|
||||
public $week;
|
||||
public $month;
|
||||
public $exceptionInterval;
|
||||
public $dateTimeEvent; // datetime : next occurence for recurrent event
|
||||
public $startDatetime;
|
||||
public $stopDatetime;
|
||||
public $recurrenceInterval; // interval : for recurrent event
|
||||
public $exceptionInterval; // array of object ranges
|
||||
}
|
||||
|
||||
class interval
|
||||
|
Loading…
Reference in New Issue
Block a user