a lot of bugs corrected\nrdc_wc_eclairage
This commit is contained in:
@ -5,18 +5,29 @@ logger(DEBUG,_("Including db_functions.php"), __FILE__ . ":" . __LINE__);
|
||||
//to save or not to save the DB, that is the question ...
|
||||
function storeDB($db, $filepath)
|
||||
{
|
||||
$data = serialize($db);
|
||||
return file_put_contents($filepath, $data);
|
||||
}
|
||||
logger(DEBUG,_("Storing database ") . $filepath, __FILE__ . ":" . __LINE__);
|
||||
$data = serialize($db);
|
||||
if (file_put_contents($filepath, $data) === false)
|
||||
{
|
||||
logger(DEBUG,_("Failed storing database ") . $filepath , __FILE__ . ":" . __LINE__);
|
||||
return false;
|
||||
}else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
function loadDB(& $db, $filepath)
|
||||
function loadDB($filepath)
|
||||
{
|
||||
logger(DEBUG,_("Loading database ") . $filepath, __FILE__ . ":" . __LINE__);
|
||||
$data = file_get_contents($filepath);
|
||||
if ($data === false)
|
||||
{
|
||||
logger(DEBUG,_("Failed loading database ") . $filepath , __FILE__ . ":" . __LINE__);
|
||||
return false;
|
||||
}
|
||||
$db = unserialize($data);
|
||||
return $db;
|
||||
}
|
||||
|
||||
function mkDevicesDB($topic, $json, $group=false)
|
||||
@ -52,14 +63,15 @@ function mkDevicesDB($topic, $json, $group=false)
|
||||
{
|
||||
//print_r($device);
|
||||
$device["device"]->groupID = $jsonDevice->id;
|
||||
$indexDevices[$device["device"]->groupID] = & $device["device"];
|
||||
$indexFriendlyNames[$topic][$fn] = & $device["device"];
|
||||
//$indexDevices[$device["device"]->groupID] = & $device["device"];
|
||||
//$indexFriendlyNames[$topic][$fn] = & $device["device"];
|
||||
}else
|
||||
{
|
||||
addDevice($topic, $device["device"], $fn, $jsonDevice);
|
||||
}
|
||||
}
|
||||
$dbInit += 1;
|
||||
mkIndexes();
|
||||
fwrite($logFh, "################################START##################################################");
|
||||
fwrite($logFh, var_export($devices, true));
|
||||
fwrite($logFh, "################################END##################################################");
|
||||
@ -84,8 +96,8 @@ function addDevice($topic, &$device, $fn, $jsonDevice )
|
||||
searchPropertyValue($fn, $device, $jsonDevice, $listProperties);
|
||||
|
||||
//indexing device
|
||||
$indexDevices[$device->ieeeAddress] = & $device;
|
||||
$indexFriendlyNames[$topic][$fn] = & $device;
|
||||
//$indexDevices[$device->ieeeAddress] = & $device;
|
||||
//$indexFriendlyNames[$topic][$fn] = & $device;
|
||||
}
|
||||
|
||||
function searchPropertyKey($fn, &$device, $inputObject, $listPropertiesKeys)
|
||||
@ -102,8 +114,8 @@ function searchPropertyKey($fn, &$device, $inputObject, $listPropertiesKeys)
|
||||
if (!array_key_exists($string, $device->properties))
|
||||
{
|
||||
$device->properties[$string]["value"] = null;
|
||||
}
|
||||
$device->properties[$string]["functions"] = array();
|
||||
}
|
||||
foreach($inputObject as $key2 => $value2)
|
||||
{
|
||||
if ($key2 != "property")
|
||||
@ -162,7 +174,7 @@ function changeDevice($topic, $fn, &$device, $payloadArray)
|
||||
}
|
||||
}
|
||||
|
||||
function iterateDevice($topic, $fn, $parentDevice, &$properties, $payloadArray, $propertyTree="")
|
||||
function iterateDevice($topic, $fn, &$parentDevice, &$properties, $payloadArray, $propertyTree="")
|
||||
{
|
||||
global $changed, $mohaDB, $testMode;
|
||||
//if (is_a($device, "device")) // = true if object
|
||||
@ -181,13 +193,16 @@ function iterateDevice($topic, $fn, $parentDevice, &$properties, $payloadArray,
|
||||
|
||||
if ($valueType == "array")
|
||||
{
|
||||
logger(DEBUG,_("valueType == array"), __FILE__ . ":" . __LINE__);
|
||||
//logger(DEBUG,_("valueType == array"), __FILE__ . ":" . __LINE__);
|
||||
$propertyTree .= $key . "/";
|
||||
$properties[$key] = array();
|
||||
if(!array_key_exists($key, $properties))
|
||||
{
|
||||
$properties[$key] = array();
|
||||
}
|
||||
iterateDevice($topic, $fn, $parentDevice, $properties[$key], $value, $propertyTree);
|
||||
}else
|
||||
{
|
||||
logger(DEBUG,_("valueType is ") . $valueType, __FILE__ . ":" . __LINE__);
|
||||
//logger(DEBUG,_("valueType is ") . $valueType, __FILE__ . ":" . __LINE__);
|
||||
//var_dump($properties);echo EOL;
|
||||
if (!array_key_exists($key, $properties))
|
||||
{
|
||||
@ -205,7 +220,7 @@ function getDevicesValues($topic)
|
||||
{
|
||||
global $indexDevices, $topics;
|
||||
logger(DEBUG, _("getDevicesValues function" ), __FILE__ . ":" . __LINE__ );
|
||||
foreach($indexDevices as $device)
|
||||
foreach($indexDevices as &$device)
|
||||
{
|
||||
if ($device->topic == $topic)
|
||||
{
|
||||
@ -220,9 +235,10 @@ function getDevicesValues($topic)
|
||||
{
|
||||
if (array_key_exists("access", $value))
|
||||
{
|
||||
if ($value["access"] & 5)
|
||||
if ($value["access"] & 4)
|
||||
{
|
||||
$device->payload[$property] = "";
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -256,23 +272,45 @@ function changeValue(&$property, $value, &$parentDevice, $propertyTree, $key)
|
||||
}
|
||||
}
|
||||
|
||||
function mkIndexes($devices)
|
||||
function mkIndexes()
|
||||
{
|
||||
global $indexDevices, $indexFriendlyNames;
|
||||
global $devices, $indexDevices, $indexFriendlyNames;
|
||||
$device = null;
|
||||
logger(INFO, _("function mkIndexes"), __FILE__ . ":" . __LINE__);
|
||||
foreach ($devices as $key => $object)
|
||||
foreach ($devices as $key => &$object)
|
||||
{
|
||||
//print "======####" . $key . EOL;
|
||||
if (is_a($object, "device"))
|
||||
{
|
||||
//echo "==========>" . $object->friendlyName . EOL;
|
||||
$indexDevices[$object->ieeeAddress] = &$object;
|
||||
$indexFriendlyNames[$object->friendlyName] = &$object;
|
||||
}else
|
||||
{
|
||||
mkIndexes($object);
|
||||
}
|
||||
print "======####" . $key . EOL;
|
||||
$r = iterate2device($object);
|
||||
}
|
||||
}
|
||||
|
||||
function iterate2device(&$object)
|
||||
{
|
||||
global $indexDevices, $indexFriendlyNames, $indexTypes;
|
||||
foreach ($object as $key => &$device)
|
||||
{
|
||||
if (is_a($device, "device"))
|
||||
{
|
||||
|
||||
$object = &$device;
|
||||
//print("=============" . $device->friendlyName);
|
||||
if (!array_key_exists($object->ieeeAddress, $indexDevices))
|
||||
{
|
||||
//print("============>");
|
||||
$indexDevices[$object->ieeeAddress] = &$object;
|
||||
$indexFriendlyNames[$object->topic][$object->friendlyName] = &$object;
|
||||
if (property_exists($object, "type"))
|
||||
{
|
||||
$indexTypes[$object->type][] = &$object;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}else
|
||||
{
|
||||
iterate2device($device);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
?>
|
||||
|
Reference in New Issue
Block a user