1
0

debbuging

This commit is contained in:
Daniel Tartavel 2022-09-09 16:53:49 +02:00
parent 918a571b5c
commit 5b4d6ba9d5
4 changed files with 29 additions and 9 deletions

View File

@ -124,7 +124,13 @@ function searchPropertyKey($fn, &$device, $inputObject, $listPropertiesKeys)
{ {
$device->properties[$string]["value"] = null; $device->properties[$string]["value"] = null;
$device->properties[$string]["functions"] = array(); $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) foreach($inputObject as $key2 => $value2)
{ {
@ -223,7 +229,13 @@ function iterateDevice($topic, $fn, &$parentDevice, &$properties, $payloadArray,
{ {
$properties[$key] = array("value" => $value); $properties[$key] = array("value" => $value);
$properties[$key]["functions"] = array(); $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) }elseif ($properties[$key]["value"] !== $value)
{ {
changeValue($properties[$key], $value, $parentDevice, $propertyTree, $key); 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__); logger(DEBUG, _("Changed value of ") . $r . "=> " . bool2string($value) , __FILE__ . ":" . __LINE__);
if (!empty($property["functions"])) if (!empty($property["functions"]))
{ {
logger(DEBUG,_("executing notifications functions"), __FILE__ . ":" . __LINE__); logger(DEBUG,_("executing CallBack"), __FILE__ . ":" . __LINE__);
foreach($property["functions"] as $function) foreach($property["functions"] as $function)
{ {
try try

View File

@ -333,13 +333,12 @@ function setDelay(device &$deviceObject, float $delay, string $unit, string $pro
$logLevel = $oldLevel; $logLevel = $oldLevel;
} }
function removeEvent(device $deviceObject, string $property , $value, int $method = IDLE) function removeEvent(device $deviceObject, string $property , $value)
{ {
global $events; global $events;
$eventKey = searchEvent($deviceObject, $property , $value); $eventKey = searchEvent($deviceObject, $property , $value);
if ($eventKey !== false) if ($eventKey !== false)
{ {
if ($method !== null) $events[$eventKey]->device->method = $method;
deleteEvent($eventKey); deleteEvent($eventKey);
} }
} }

View File

@ -76,14 +76,19 @@ function notify($message, $device)
global $notificationMethods, $defaultUser; global $notificationMethods, $defaultUser;
$result = false; $result = false;
$destinataire = array(); $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 $destinataire[] = reset($defaultUser); //default user if no device
logger(DEBUG, _("notify: destinataire ==>") . print_r($destinataire, true), __FILE__ . ":" . __LINE__);
}else }else
{ {
//TODO destinataire selon fichier de config
if (empty($device->users)) if (empty($device->users))
{ {
logger(DEBUG, _("notify: pas d'utilisateur pour ce device"), true, __FILE__ . ":" . __LINE__);
foreach($defaultUser as $topic => $nom) foreach($defaultUser as $topic => $nom)
{ {
if ( str_contains($device->friendlyName, $topic)) if ( str_contains($device->friendlyName, $topic))
@ -101,7 +106,7 @@ function notify($message, $device)
{ {
foreach($destinataire as $dest) foreach($destinataire as $dest)
{ {
$result = $result | $value->send($message, $dest); $result |= $value->send($message, $dest);
} }
} }
return $result; return $result;
@ -111,6 +116,7 @@ function logger($level, $log, $pos = "", $device=null, $notif = true)
{ {
global $logFh, $logLevel, $notificationLevel, $logLevels; global $logFh, $logLevel, $notificationLevel, $logLevels;
$logString = $logLevels[$level] . " " ; $logString = $logLevels[$level] . " " ;
if ($pos !== false) if ($pos !== false)
{ {
$logString .= $pos; $logString .= $pos;
@ -124,9 +130,10 @@ function logger($level, $log, $pos = "", $device=null, $notif = true)
$test = $level & $notificationLevel; $test = $level & $notificationLevel;
if (($test != 0) and ($notif === true)) if (($test != 0) and ($notif === true))
{ {
echo _("logger: Notification to user") . __FILE__ . ":" . __LINE__;
if(notify("Moha\n" . $logString, $device) === false) if(notify("Moha\n" . $logString, $device) === false)
{ {
logger(INFO, _("Notification not sent"), __FILE__ . ":" . __LINE__, false); echo _("logger; Notification not sent") . __FILE__ . ":" . __LINE__;
return true; return true;
} }
} }

View File

@ -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(ERROR, _("no device : ") . $device[0] . bool2string($r), __FILE__ . ":" . __LINE__ );
} }
} }
logger(DEBUG, _("testActionneurs : result is ") . bool2string($r), __FILE__ . ":" . __LINE__ );
return $r; return $r;
} }