1
0

some debbuging

This commit is contained in:
2022-01-02 18:14:13 +01:00
parent 2e6b2fe5cb
commit d79463fbd4
11 changed files with 147 additions and 242 deletions

View File

@ -10,8 +10,11 @@ function storeDB($db, $filepath)
function mkDevicesDB($topic, $json, $group=false)
{
global $devices, $listProperties, $listPropertiesKeys, $indexDevices, $dbInit, $logFh;
if (!isset($devices[$topic])) $devices[$topic]= array();
global $devices, $listProperties, $listPropertiesKeys, $indexDevices, $dbInit, $logFh, $hooks;
if (!isset($devices[$topic]))
{
$devices[$topic]= array();
}
foreach ($json as $jsonDevice)
{
//print_r($device);
@ -20,11 +23,16 @@ function mkDevicesDB($topic, $json, $group=false)
$device = & $devices[$topic];
foreach($fnTree as $fnPart)
{
$device[$fnPart] = array();
if (!isset($device[$fnPart]))
{
$device[$fnPart] = array();
}
$device = & $device[$fnPart];
}
$device["device"] = new device;
if (!isset($device["device"]))
{
$device["device"] = new device;
}
$device["device"]->topic = $topic;
//$device["device"]->device = $jsonDevice;
$device["device"]->friendlyName = $jsonDevice->friendly_name;
@ -35,20 +43,7 @@ function mkDevicesDB($topic, $json, $group=false)
$indexDevices[$device["device"]->groupID] = $jsonDevice->friendly_name;
}else
{
$device["device"]->type = $jsonDevice->type;
$device["device"]->ieeeAddress = $jsonDevice->ieee_address;
if ( !empty($jsonDevice->power_source ) )
{
$device["device"]->powerSource = $jsonDevice->power_source;
}
if ($jsonDevice->definition != null)
{
$device["device"]->description = $jsonDevice->definition->description;
searchPropertyKey($fn, $device["device"], $jsonDevice->definition->exposes, $listPropertiesKeys);
}
searchPropertyValue($fn, $device["device"], $jsonDevice, $listProperties);
$indexDevices[$device["device"]->ieeeAddress] = & $device["device"];
//print_r($device);
addDevice($device, $fn, $jsonDevice);
}
}
$dbInit += 1;
@ -60,6 +55,32 @@ function mkDevicesDB($topic, $json, $group=false)
//print_r($devices);
}
function addDevice(& $device, $fn, $jsonDevice )
{
global $listProperties, $listPropertiesKeys, $hooks, $indexDevices;
$device["device"]->type = $jsonDevice->type;
$device["device"]->ieeeAddress = $jsonDevice->ieee_address;
if ( !empty($jsonDevice->power_source ) )
{
$device["device"]->powerSource = $jsonDevice->power_source;
}
if ($jsonDevice->definition != null)
{
$device["device"]->description = $jsonDevice->definition->description;
searchPropertyKey($fn, $device["device"], $jsonDevice->definition->exposes, $listPropertiesKeys);
}
searchPropertyValue($fn, $device["device"], $jsonDevice, $listProperties);
// adding callback function for availability
//print_r($hooks);
$device["device"]->functions[] = $hooks["availability"]->getHook();
//indexing device
$indexDevices[$device["device"]->ieeeAddress] = & $device["device"];
//print_r($device);
}
function searchPropertyKey($fn, &$device, $object, $listPropertiesKeys)
{
foreach($listPropertiesKeys as $property)
@ -101,7 +122,7 @@ function changeDevice($topic, $fn, &$device, $payloadArray)
function iterateDevice($topic, $fn, &$device, $payloadArray)
{
global $changed;
print_r($payloadArray);
//print_r($payloadArray);
//echo "device =>";print_r($device);echo EOL;
foreach($payloadArray as $key => $value)
{
@ -128,8 +149,11 @@ function iterateDevice($topic, $fn, &$device, $payloadArray)
{
if (empty($device->$key) or $value != null)
{
if (isset($device->$key)) $oldValue = $device->$key;
if ($oldValue != $value)
if (isset($device->$key))
{
$oldValue = $device->$key;
}if ($oldValue != $value)
{
$device->{$key} = $value;
$changed[$fn]["key"] = $key;
@ -145,14 +169,15 @@ function iterateDevice($topic, $fn, &$device, $payloadArray)
}
echo " to " . $value . EOL;*/
}
//print_r($device->functions);
//print_r($device->functions); print_r($value);
if (!empty($device->functions))
{
echo "executing notifications functions " . EOL;
foreach($device->functions as $function)
{
//print_r($function);
$function($topic, $fn, $key, $value);
$function($device, $key, $value);
}
}
}