From 5b4d6ba9d513d7128a21047e76eec886cc97e0d8 Mon Sep 17 00:00:00 2001 From: Daniel Tartavel Date: Fri, 9 Sep 2022 16:53:49 +0200 Subject: [PATCH] debbuging --- db_functions.php | 18 +++++++++++++++--- events.php | 3 +-- moha.php | 15 +++++++++++---- utils.php | 2 ++ 4 files changed, 29 insertions(+), 9 deletions(-) diff --git a/db_functions.php b/db_functions.php index 9763fad..9b76b83 100644 --- a/db_functions.php +++ b/db_functions.php @@ -124,7 +124,13 @@ function searchPropertyKey($fn, &$device, $inputObject, $listPropertiesKeys) { $device->properties[$string]["value"] = null; $device->properties[$string]["functions"] = array(); - $device->properties[$string]["method"] = IDLE; + if(array_key_exists("access", $inputObject)) + { + if ($inputObject["access"] && 2) + { + $device->properties[$string]["method"] = IDLE; + } + } } foreach($inputObject as $key2 => $value2) { @@ -223,7 +229,13 @@ function iterateDevice($topic, $fn, &$parentDevice, &$properties, $payloadArray, { $properties[$key] = array("value" => $value); $properties[$key]["functions"] = array(); - $properties[$key]["method"] = IDLE; + if (array_key_exists("access", $properties[$key])) + { + if ($properties[$key]["access]"] && 2) + { + $properties[$key]["method"] = IDLE; + } + } }elseif ($properties[$key]["value"] !== $value) { changeValue($properties[$key], $value, $parentDevice, $propertyTree, $key); @@ -290,7 +302,7 @@ function changeValue(&$property, $value, &$parentDevice, $propertyTree, $key) logger(DEBUG, _("Changed value of ") . $r . "=> " . bool2string($value) , __FILE__ . ":" . __LINE__); if (!empty($property["functions"])) { - logger(DEBUG,_("executing notifications functions"), __FILE__ . ":" . __LINE__); + logger(DEBUG,_("executing CallBack"), __FILE__ . ":" . __LINE__); foreach($property["functions"] as $function) { try diff --git a/events.php b/events.php index c6a63db..cef6188 100644 --- a/events.php +++ b/events.php @@ -333,13 +333,12 @@ function setDelay(device &$deviceObject, float $delay, string $unit, string $pro $logLevel = $oldLevel; } -function removeEvent(device $deviceObject, string $property , $value, int $method = IDLE) +function removeEvent(device $deviceObject, string $property , $value) { global $events; $eventKey = searchEvent($deviceObject, $property , $value); if ($eventKey !== false) { - if ($method !== null) $events[$eventKey]->device->method = $method; deleteEvent($eventKey); } } diff --git a/moha.php b/moha.php index b6feb6c..4b5e4d1 100644 --- a/moha.php +++ b/moha.php @@ -76,14 +76,19 @@ function notify($message, $device) global $notificationMethods, $defaultUser; $result = false; $destinataire = array(); - if (empty($device)) + + logger(DEBUG, _("notify function "), __FILE__ . ":" . __LINE__); + + if (empty($device) or !isset($device)) { $destinataire[] = reset($defaultUser); //default user if no device + logger(DEBUG, _("notify: destinataire ==>") . print_r($destinataire, true), __FILE__ . ":" . __LINE__); + }else { - //TODO destinataire selon fichier de config if (empty($device->users)) { + logger(DEBUG, _("notify: pas d'utilisateur pour ce device"), true, __FILE__ . ":" . __LINE__); foreach($defaultUser as $topic => $nom) { if ( str_contains($device->friendlyName, $topic)) @@ -101,7 +106,7 @@ function notify($message, $device) { foreach($destinataire as $dest) { - $result = $result | $value->send($message, $dest); + $result |= $value->send($message, $dest); } } return $result; @@ -111,6 +116,7 @@ function logger($level, $log, $pos = "", $device=null, $notif = true) { global $logFh, $logLevel, $notificationLevel, $logLevels; $logString = $logLevels[$level] . " " ; + if ($pos !== false) { $logString .= $pos; @@ -124,9 +130,10 @@ function logger($level, $log, $pos = "", $device=null, $notif = true) $test = $level & $notificationLevel; if (($test != 0) and ($notif === true)) { + echo _("logger: Notification to user") . __FILE__ . ":" . __LINE__; if(notify("Moha\n" . $logString, $device) === false) { - logger(INFO, _("Notification not sent"), __FILE__ . ":" . __LINE__, false); + echo _("logger; Notification not sent") . __FILE__ . ":" . __LINE__; return true; } } diff --git a/utils.php b/utils.php index 16dfeac..a6723fd 100644 --- a/utils.php +++ b/utils.php @@ -60,6 +60,8 @@ function testActionneurs(array $actionneurs) //return 0 for no actionneurs and logger(ERROR, _("no device : ") . $device[0] . bool2string($r), __FILE__ . ":" . __LINE__ ); } } + logger(DEBUG, _("testActionneurs : result is ") . bool2string($r), __FILE__ . ":" . __LINE__ ); + return $r; }