From 80234fc505209fa359ac62d6d92ee96e67682571 Mon Sep 17 00:00:00 2001 From: daniel Tartavel Date: Tue, 15 Mar 2022 22:49:13 +0100 Subject: [PATCH] added callable function in event object --- class/main.php | 1 + events.php | 16 +++++++++++----- hooks/scripts/rdc_salon_eclairage.php | 2 +- topics_callbacks/zigbee2mqtt.php | 1 + 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/class/main.php b/class/main.php index 7c14d3c..aea035a 100644 --- a/class/main.php +++ b/class/main.php @@ -64,6 +64,7 @@ class event public $topic; public $param; public $value; + public $function; public $device; public $published; public $dateTimeEvent; // datetime : next occurence for recurrent event diff --git a/events.php b/events.php index 3381b01..504516e 100644 --- a/events.php +++ b/events.php @@ -15,7 +15,7 @@ function checkEvents() $now = now(); if (!empty($event->startDatetime)) { - logger(DEBUG, _("StarDatetime is set"), __FILE__ . ":" . __LINE__); + logger(DEBUG, _("StartDatetime is set"), __FILE__ . ":" . __LINE__); if($event->dateTimeEvent < $now) { logger(DEBUG, _("Event must be executed"), __FILE__ . ":" . __LINE__); @@ -35,11 +35,17 @@ function checkEvents() } if ($exception === false) { - 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->dateTimeEvent->add($event->recurrenceInterval)) === false) + if (is_callable($this->function)) { - logger(ERROR, _("Error in adding interval to event recurrence. event: ") . $key, __FILE__ . ":" . __LINE__); + $this->function(&$event); + }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->dateTimeEvent->add($event->recurrenceInterval)) === false) + { + logger(ERROR, _("Error in adding interval to event recurrence. event: ") . $key, __FILE__ . ":" . __LINE__); + } } } } diff --git a/hooks/scripts/rdc_salon_eclairage.php b/hooks/scripts/rdc_salon_eclairage.php index 65449cd..bab164c 100644 --- a/hooks/scripts/rdc_salon_eclairage.php +++ b/hooks/scripts/rdc_salon_eclairage.php @@ -14,7 +14,7 @@ class rdc_salon_eclairage extends hook public $delay = 3; // amount of time in $timeunit public $timeUnit = "minute"; // unit of time for delay, second, minute, hour, day, week, month, year - public $luminance_min = 60; + public $luminance_min = 50; public $luminance_max = 100; // callback fonction. Is called with these 4 parameters diff --git a/topics_callbacks/zigbee2mqtt.php b/topics_callbacks/zigbee2mqtt.php index 647d113..4a00781 100644 --- a/topics_callbacks/zigbee2mqtt.php +++ b/topics_callbacks/zigbee2mqtt.php @@ -73,6 +73,7 @@ function zigbee2mqttCallback($topic, $message) logger(DEBUG, _("friendlyname = ") . $fn, __FILE__ . ":" . __LINE__); if (!array_key_exists($fn, $indexFriendlyNames[$topicName])) { + mkDevicesDB($topicName, $message->payload); logger(ERROR, sprintf(_("device with friendlyname %s not found"), $fn), __FILE__ . ":" . __LINE__); }else {