a lot of debug
This commit is contained in:
@ -9,7 +9,7 @@ function storeDB($db, $filepath)
|
||||
$data = serialize($db);
|
||||
if (file_put_contents($filepath, $data) === false)
|
||||
{
|
||||
logger(DEBUG,_("Failed storing database ") . $filepath , __FILE__ . ":" . __LINE__);
|
||||
logger(ALERT,_("Failed storing database ") . $filepath , __FILE__ . ":" . __LINE__);
|
||||
return false;
|
||||
}else
|
||||
{
|
||||
@ -23,20 +23,24 @@ function loadDB($filepath)
|
||||
$data = file_get_contents($filepath);
|
||||
if ($data === false)
|
||||
{
|
||||
logger(DEBUG,_("Failed loading database ") . $filepath , __FILE__ . ":" . __LINE__);
|
||||
logger(ALERT,_("Failed loading database ") . $filepath , __FILE__ . ":" . __LINE__);
|
||||
return false;
|
||||
}
|
||||
$db = unserialize($data);
|
||||
if (($db = unserialize($data)) === false)
|
||||
{
|
||||
logger(ALERT,_("Failed unserializing database ") . $filepath , __FILE__ . ":" . __LINE__);
|
||||
}
|
||||
return $db;
|
||||
}
|
||||
|
||||
function mkDevicesDB($topic, $json, $group=false)
|
||||
{
|
||||
global $devices, $listProperties, $listPropertiesKeys, $indexDevices, $dbInit, $logFh, $hooks, $indexFriendlyNames;
|
||||
if (!isset($devices[$topic]))
|
||||
if (!array_key_exists($topic, $devices))
|
||||
{
|
||||
$devices[$topic]= array();
|
||||
}
|
||||
//fwrite($logFh, var_export($json, true));
|
||||
//print_r($json);
|
||||
foreach ($json as $jsonDevice)
|
||||
{
|
||||
@ -57,7 +61,7 @@ function addDevice($topic, $fn, $jsonDevice, $group=false )
|
||||
global $devices, $listProperties, $listPropertiesKeys, $hooks, $indexDevices, $indexFriendlyNames;
|
||||
$fnTree = explode("/", $fn);
|
||||
$device = & $devices[$topic];
|
||||
print_r($jsonDevice);
|
||||
//print_r($jsonDevice);
|
||||
foreach($fnTree as $fnPart)
|
||||
{
|
||||
if (!array_key_exists($fnPart, $device))
|
||||
@ -108,13 +112,13 @@ function searchPropertyKey($fn, &$device, $inputObject, $listPropertiesKeys)
|
||||
{
|
||||
//foreach($listPropertiesKeys as $propertyKey)
|
||||
//{
|
||||
logger(DEBUG, _("searching for property"), __FILE__ . ":" . __LINE__ );
|
||||
//logger(DEBUG, _("searching for property"), __FILE__ . ":" . __LINE__ );
|
||||
//if (is_object($inputObject))
|
||||
//{
|
||||
//print_r($inputObject);
|
||||
if (array_key_exists("property", $inputObject))
|
||||
{
|
||||
logger(DEBUG, _("property Key exists filling properties"), __FILE__ . ":" . __LINE__ );
|
||||
//logger(DEBUG, _("property Key exists filling properties"), __FILE__ . ":" . __LINE__ );
|
||||
$string = $inputObject["property"];
|
||||
if (!array_key_exists($string, $device->properties))
|
||||
{
|
||||
@ -136,11 +140,14 @@ function searchPropertyKey($fn, &$device, $inputObject, $listPropertiesKeys)
|
||||
{
|
||||
$device->type = $inputObject["type"];
|
||||
}
|
||||
/*foreach($inputObject as $key => $value)
|
||||
foreach($inputObject as $key => $value)
|
||||
{
|
||||
logger(DEBUG, sprintf(_("key = %s"), $key), __FILE__ . ":" . __LINE__ );
|
||||
searchPropertyKey($fn, $device, $value, $listPropertiesKeys);
|
||||
}*/
|
||||
//logger(DEBUG, sprintf(_("key = %s"), $key), __FILE__ . ":" . __LINE__ );
|
||||
if (is_array($value))
|
||||
{
|
||||
searchPropertyKey($fn, $device, $value, $listPropertiesKeys);
|
||||
}
|
||||
}
|
||||
}
|
||||
//print_r($device);
|
||||
//}
|
||||
@ -247,12 +254,16 @@ function getDevicesValues($topic)
|
||||
if ($value["access"] & 4)
|
||||
{
|
||||
$device->payload[$property] = "";
|
||||
$flag = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
//logger(DEBUG, print_r($device->payload, true), __FILE__ . ":" . __LINE__ );
|
||||
$device->get();
|
||||
if ($flag === true)
|
||||
{
|
||||
$device->get();
|
||||
}
|
||||
}else
|
||||
{
|
||||
logger(DEBUG, _("no properties to get for device: " . $device->friendlyName ), __FILE__ . ":" . __LINE__ );
|
||||
@ -302,24 +313,32 @@ function mkIndexes()
|
||||
|
||||
function iterate2device(&$object)
|
||||
{
|
||||
global $indexDevices, $indexFriendlyNames, $indexTypes;
|
||||
global $indexDevices, $indexFriendlyNames, $indexTypes, $indexProperties;
|
||||
foreach ($object as $key => &$device)
|
||||
{
|
||||
if (is_a($device, "device"))
|
||||
{
|
||||
|
||||
$object = &$device;
|
||||
//$object = &$device;
|
||||
//print("=============" . $device->friendlyName);
|
||||
//if (!array_key_exists($object->ieeeAddress, $indexDevices))
|
||||
//{
|
||||
//print("============>");
|
||||
$indexDevices[$object->ieeeAddress] = &$object;
|
||||
$indexFriendlyNames[$object->friendlyName] = &$object;
|
||||
if (property_exists($object, "type"))
|
||||
$indexDevices[$device->ieeeAddress] = &$device;
|
||||
$indexFriendlyNames[$device->friendlyName] = &$device;
|
||||
if (property_exists($device, "type"))
|
||||
{
|
||||
$indexTypes[$object->type][] = &$object;
|
||||
$indexTypes[$device->type][] = &$object;
|
||||
}
|
||||
$properties = array_keys($device->properties);
|
||||
foreach($properties as $property)
|
||||
{
|
||||
$indexProperties[$property][$device->ieeeAddress] = &$device;
|
||||
}
|
||||
//}
|
||||
//return true;
|
||||
}elseif (empty($device))
|
||||
{
|
||||
return true;
|
||||
}else
|
||||
{
|
||||
|
Reference in New Issue
Block a user