From 4e9aa8aeb524a8c8be6721715147caa642d384a5 Mon Sep 17 00:00:00 2001 From: daniel Tartavel Date: Sat, 1 Jan 2022 06:26:02 +0100 Subject: [PATCH] hooks are now in array --- events.php | 9 +++++---- hooks/scripts/panneau_salon.php | 12 ++++++------ moha.php | 9 +++++---- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/events.php b/events.php index 5e98ead..6f49933 100644 --- a/events.php +++ b/events.php @@ -8,7 +8,7 @@ function checkEvents() { if (!empty($event->dateTimeEvent) and $event->dateTimeEvent <= now()) { - echo "---->sending command" . EOL; + echo "---->sending command set " . $event->param . "=>" . $event->value . " to " . $event->device->friendlyName . EOL; publish($event->device, array($event->param => $event->value), "set", $key); //$event->published = now(); //echo "#################################\nUnsetting event $key \n###########################" . EOL; @@ -25,10 +25,10 @@ function setDelay(&$device, $delay, $unit="sec", $param, $value, $replace=false) //print_r($datetime); switch($unit) { - case "sec": + case "second": $unit = "S"; break; - case "min": + case "minute": $unit = "M"; break; case "hour": @@ -68,7 +68,7 @@ function setDelay(&$device, $delay, $unit="sec", $param, $value, $replace=false) -function searchEvent($device, $param , $value): int +function searchEvent($device, $param , $value) { global $events; echo "searching event" . EOL; @@ -85,6 +85,7 @@ function searchEvent($device, $param , $value): int return $key; } } + return false; } function deleteEvent($eventKey) diff --git a/hooks/scripts/panneau_salon.php b/hooks/scripts/panneau_salon.php index 31fe3cd..0e67a0d 100644 --- a/hooks/scripts/panneau_salon.php +++ b/hooks/scripts/panneau_salon.php @@ -1,9 +1,10 @@ functions[] = array($this,"callback"); //print_r($indexDevices[$ieeeAddress]); } - } + // callback fonction. Is called with these 4 parameters public function callBack($topic, $fn, $param, $value) { global $devices, $indexDevices; - switch($param) { case "occupancy": @@ -47,7 +47,7 @@ class panneau_salon } } -$panneau_salon = new panneau_salon(); +$hooks["rdc/panneau/salon"] = new rdc_panneau_salon(); //assignation of the function to the sensors devices //$indexDevices["0x00124b0022ebac5c"]->functions[] = array($panneau_salon,"getCallback"); // rdc-salon-mvmt2 //$indexDevices["0x588e81fffe2cf695"]->functions[] = array($panneau_salon,"getCallback"); // rdc-salon-mvmt diff --git a/moha.php b/moha.php index a1308ac..39f50c9 100644 --- a/moha.php +++ b/moha.php @@ -126,16 +126,17 @@ class notificationMethod //global variables $topics = array(); // list of topics $mids = array(); // list of message IDs -$logFh = null; // filehandle of log file $devices = array(); // array of device objetcs -$changed = array(); // list of changed devices -$notificationMethods = array(); // array of notification methods objects $indexDevices = array(); // index devices by ieee_address +$hooks = array(); // array of hooks +$notificationMethods = array(); // array of notification methods objects +$events = array(); // list of event objects +$changed = array(); // list of changed devices $dbInit = false; // flag to indicate that desvices db is initialized $connected = false; // connected to MQTT server $nSubscribed = 0; // Number of topics subsribed $included = false; // flag indicate scripts are loaded -$events = array(); // list of event objects +$logFh = null; // filehandle of log file // topics definition $topics["zigbee2mqtt"] = new topic;