hooks are now classes and devices scan exposes to add properties
This commit is contained in:
@ -15,7 +15,7 @@ function deviceTree(string $topic, array $fnTree, array &$device)
|
||||
|
||||
function mkDevicesDB($topic, $json, $group=false)
|
||||
{
|
||||
global $devices, $listProperties, $indexDevices, $dbInit, $logFh;
|
||||
global $devices, $listProperties, $listPropertiesKeys, $indexDevices, $dbInit, $logFh;
|
||||
if (!isset($devices[$topic])) $devices[$topic]= array();
|
||||
foreach ($json as $jsonDevice)
|
||||
{
|
||||
@ -49,22 +49,40 @@ function mkDevicesDB($topic, $json, $group=false)
|
||||
if ($jsonDevice->definition != null)
|
||||
{
|
||||
$device["device"]->description = $jsonDevice->definition->description;
|
||||
searchPropertyKey($fn, $device["device"], $jsonDevice->definition->exposes, $listPropertiesKeys);
|
||||
}
|
||||
//searchProperty($fn, $device["device"], $jsonDevice, $listProperties);
|
||||
searchPropertyValue($fn, $device["device"], $jsonDevice, $listProperties);
|
||||
$indexDevices[$device["device"]->ieeeAddress] = & $device["device"];
|
||||
//print_r($device);
|
||||
}
|
||||
}
|
||||
$dbInit = true;
|
||||
$dbInit += 1;
|
||||
fwrite($logFh, "################################START##################################################");
|
||||
fwrite($logFh, print_r($devices, true));
|
||||
fwrite($logFh, "################################END##################################################");
|
||||
|
||||
echo "Devices DB made" .EOL;
|
||||
echo "Devices DB made" . EOL;
|
||||
//print_r($devices);
|
||||
}
|
||||
|
||||
function searchProperty($fn, &$device, $object, $listProperties)
|
||||
function searchPropertyKey($fn, &$device, $object, $listPropertiesKeys)
|
||||
{
|
||||
foreach($listPropertiesKeys as $property)
|
||||
{
|
||||
foreach($object as $key => $value)
|
||||
{
|
||||
|
||||
if ( isset($value->property))
|
||||
{
|
||||
//echo "property ===> " . $value->property . EOL;
|
||||
$device->{$value->property} = null;
|
||||
}
|
||||
}
|
||||
//print_r($device);
|
||||
}
|
||||
}
|
||||
|
||||
function searchPropertyValue($fn, &$device, $object, $listProperties)
|
||||
{
|
||||
$objectArray = (array)$object;
|
||||
foreach($listProperties as $key => $value)
|
||||
@ -93,16 +111,16 @@ function changeDevice($topic, $fn, &$device, $json)
|
||||
|
||||
//print_r($json);
|
||||
$fnTree = explode("/", $fn);
|
||||
print_r($json);
|
||||
//print_r($json);
|
||||
if ( ($jsonDevice = json_decode($json)) === null )
|
||||
{
|
||||
echo "json ========>>>>>>> " . print_r($json,true) . EOL;
|
||||
//echo "json ========>>>>>>> " . print_r($json,true) . EOL;
|
||||
if (!isset($device->value))
|
||||
{
|
||||
$device->{"value"} = $json;
|
||||
$device->type = true; //set this as parameter and not device
|
||||
}
|
||||
print_r($device);
|
||||
//print_r($device);
|
||||
}else
|
||||
{
|
||||
iterateDevice($topic, $fn, $device, $jsonDevice);
|
||||
|
Reference in New Issue
Block a user