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,8 +124,14 @@ function searchPropertyKey($fn, &$device, $inputObject, $listPropertiesKeys)
{
$device->properties[$string]["value"] = null;
$device->properties[$string]["functions"] = array();
if(array_key_exists("access", $inputObject))
{
if ($inputObject["access"] && 2)
{
$device->properties[$string]["method"] = IDLE;
}
}
}
foreach($inputObject as $key2 => $value2)
{
if ($key2 != "property")
@ -223,7 +229,13 @@ function iterateDevice($topic, $fn, &$parentDevice, &$properties, $payloadArray,
{
$properties[$key] = array("value" => $value);
$properties[$key]["functions"] = array();
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

View File

@ -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);
}
}

View File

@ -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;
}
}

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(DEBUG, _("testActionneurs : result is ") . bool2string($r), __FILE__ . ":" . __LINE__ );
return $r;
}