2021-12-30 16:18:32 +01:00
|
|
|
<?php
|
|
|
|
|
2022-01-28 23:05:58 +01:00
|
|
|
logger(DEBUG,_("Including db_functions.php"), __FILE__ . ":" . __LINE__);
|
2022-01-17 00:18:50 +01:00
|
|
|
|
2022-02-07 16:58:42 +01:00
|
|
|
//to save or not to save the DB, that is the question ...
|
2021-12-30 16:18:32 +01:00
|
|
|
function storeDB($db, $filepath)
|
|
|
|
{
|
2022-01-17 00:18:50 +01:00
|
|
|
$data = serialize($db);
|
2022-02-07 16:58:42 +01:00
|
|
|
return file_put_contents($filepath, $data);
|
2022-01-17 00:18:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function loadDB(& $db, $filepath)
|
|
|
|
{
|
|
|
|
$data = file_get_contents($filepath);
|
2022-02-07 16:58:42 +01:00
|
|
|
if ($data === false)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2022-01-17 00:18:50 +01:00
|
|
|
$db = unserialize($data);
|
2021-12-30 16:18:32 +01:00
|
|
|
}
|
|
|
|
|
2021-12-31 14:34:20 +01:00
|
|
|
function mkDevicesDB($topic, $json, $group=false)
|
2021-12-30 16:18:32 +01:00
|
|
|
{
|
2022-01-02 18:14:13 +01:00
|
|
|
global $devices, $listProperties, $listPropertiesKeys, $indexDevices, $dbInit, $logFh, $hooks;
|
|
|
|
if (!isset($devices[$topic]))
|
|
|
|
{
|
|
|
|
$devices[$topic]= array();
|
|
|
|
}
|
2022-02-23 10:23:16 +01:00
|
|
|
//print_r($json);
|
2021-12-31 14:34:20 +01:00
|
|
|
foreach ($json as $jsonDevice)
|
2021-12-30 16:18:32 +01:00
|
|
|
{
|
2022-02-23 10:23:16 +01:00
|
|
|
|
2021-12-31 14:34:20 +01:00
|
|
|
$fn = $jsonDevice->friendly_name;
|
|
|
|
$fnTree = explode("/", $fn);
|
|
|
|
$device = & $devices[$topic];
|
|
|
|
foreach($fnTree as $fnPart)
|
2021-12-30 16:18:32 +01:00
|
|
|
{
|
2022-01-17 00:18:50 +01:00
|
|
|
if (!array_key_exists($fnPart, $device))
|
2022-01-02 18:14:13 +01:00
|
|
|
{
|
|
|
|
$device[$fnPart] = array();
|
|
|
|
}
|
2021-12-31 14:34:20 +01:00
|
|
|
$device = & $device[$fnPart];
|
2021-12-30 16:18:32 +01:00
|
|
|
}
|
2022-01-17 00:18:50 +01:00
|
|
|
if (!array_key_exists("device", $device))
|
2022-01-02 18:14:13 +01:00
|
|
|
{
|
|
|
|
$device["device"] = new device;
|
|
|
|
}
|
2021-12-31 14:34:20 +01:00
|
|
|
$device["device"]->topic = $topic;
|
|
|
|
//$device["device"]->device = $jsonDevice;
|
2022-02-12 15:23:58 +01:00
|
|
|
$device["device"]->friendlyName = $fn;
|
2021-12-31 14:34:20 +01:00
|
|
|
if ($group)
|
|
|
|
{
|
|
|
|
//print_r($device);
|
|
|
|
$device["device"]->groupID = $jsonDevice->id;
|
2022-02-12 15:23:58 +01:00
|
|
|
$indexDevices[$device["device"]->groupID] = & $device["device"];
|
|
|
|
$indexFriendlyNames[$fn] = & $device["device"];
|
2021-12-31 14:34:20 +01:00
|
|
|
}else
|
2021-12-30 16:18:32 +01:00
|
|
|
{
|
2022-02-23 10:23:16 +01:00
|
|
|
addDevice($device["device"], $fn, $jsonDevice);
|
2021-12-30 16:18:32 +01:00
|
|
|
}
|
|
|
|
}
|
2021-12-31 23:09:58 +01:00
|
|
|
$dbInit += 1;
|
2021-12-31 14:34:20 +01:00
|
|
|
fwrite($logFh, "################################START##################################################");
|
2022-02-02 21:18:44 +01:00
|
|
|
fwrite($logFh, var_export($devices, true));
|
2021-12-31 14:34:20 +01:00
|
|
|
fwrite($logFh, "################################END##################################################");
|
|
|
|
|
2022-01-28 23:05:58 +01:00
|
|
|
logger(DEBUG, _("Devices DB made"), __FILE__ . ":" . __LINE__);
|
2021-12-30 16:18:32 +01:00
|
|
|
//print_r($devices);
|
|
|
|
}
|
|
|
|
|
2022-01-02 18:14:13 +01:00
|
|
|
function addDevice(& $device, $fn, $jsonDevice )
|
|
|
|
{
|
2022-02-12 15:23:58 +01:00
|
|
|
global $listProperties, $listPropertiesKeys, $hooks, $indexDevices, $indexFriendlyNames;
|
2022-02-23 10:23:16 +01:00
|
|
|
$device->type = $jsonDevice->type;
|
|
|
|
$device->ieeeAddress = $jsonDevice->ieee_address;
|
2022-01-02 18:14:13 +01:00
|
|
|
if ( !empty($jsonDevice->power_source ) )
|
|
|
|
{
|
2022-02-23 10:23:16 +01:00
|
|
|
$device->powerSource = $jsonDevice->power_source;
|
2022-01-02 18:14:13 +01:00
|
|
|
}
|
|
|
|
if ($jsonDevice->definition != null)
|
|
|
|
{
|
2022-02-23 10:23:16 +01:00
|
|
|
$device->description = $jsonDevice->definition->description;
|
|
|
|
searchPropertyKey($fn, $device, $jsonDevice->definition->exposes, $listPropertiesKeys);
|
2022-01-02 18:14:13 +01:00
|
|
|
}
|
2022-02-23 10:23:16 +01:00
|
|
|
searchPropertyValue($fn, $device, $jsonDevice, $listProperties);
|
2022-01-02 18:14:13 +01:00
|
|
|
|
|
|
|
//indexing device
|
2022-02-23 10:23:16 +01:00
|
|
|
$indexDevices[$device->ieeeAddress] = & $device;
|
|
|
|
$indexFriendlyNames[$fn] = & $device;
|
2022-01-02 18:14:13 +01:00
|
|
|
}
|
|
|
|
|
2022-02-23 10:23:16 +01:00
|
|
|
function searchPropertyKey($fn, &$device, $inputObject, $listPropertiesKeys)
|
2021-12-31 23:09:58 +01:00
|
|
|
{
|
2022-02-23 10:23:16 +01:00
|
|
|
//foreach($listPropertiesKeys as $propertyKey)
|
|
|
|
//{
|
|
|
|
logger(DEBUG, _("searching for property"), __FILE__ . ":" . __LINE__ );
|
|
|
|
if (is_object($inputObject))
|
2021-12-31 23:09:58 +01:00
|
|
|
{
|
2022-02-23 10:23:16 +01:00
|
|
|
if (property_exists($inputObject, "property"))
|
2021-12-31 23:09:58 +01:00
|
|
|
{
|
2022-02-23 10:23:16 +01:00
|
|
|
logger(DEBUG, _("propertyKey exists filling properties"), __FILE__ . ":" . __LINE__ );
|
|
|
|
$string = $inputObject->property;
|
|
|
|
$device->properties[$string]["value"] = null;
|
|
|
|
$device->properties[$string]["functions"] = array();
|
|
|
|
|
|
|
|
foreach($inputObject as $key2 => $value2)
|
2022-01-03 21:11:52 +01:00
|
|
|
{
|
2022-02-23 10:23:16 +01:00
|
|
|
|
|
|
|
if ($key2 != "property")
|
|
|
|
{
|
|
|
|
$device->properties[$string][$key2] = $value2;
|
|
|
|
logger(DEBUG, sprintf(_("property %s value %s"), $key2, print_r($device->properties[$string][$key2])), __FILE__ . ":" . __LINE__ );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}else
|
|
|
|
{
|
|
|
|
if (property_exists($inputObject, "type"))
|
|
|
|
{
|
|
|
|
$device->type = $inputObject->type;
|
2022-01-03 21:11:52 +01:00
|
|
|
}
|
2022-02-23 10:23:16 +01:00
|
|
|
foreach($inputObject as $key => $value)
|
2021-12-31 23:09:58 +01:00
|
|
|
{
|
2022-02-23 10:23:16 +01:00
|
|
|
logger(DEBUG, sprintf(_("key = %s"), $key), __FILE__ . ":" . __LINE__ );
|
|
|
|
searchPropertyKey($fn, $device, $value, $listPropertiesKeys);
|
2021-12-31 23:09:58 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
//print_r($device);
|
2022-02-23 10:23:16 +01:00
|
|
|
}elseif (is_array($inputObject))
|
|
|
|
{
|
|
|
|
foreach($inputObject as $value)
|
|
|
|
{
|
|
|
|
logger(DEBUG, _("value is object or group, iterating"), __FILE__ . ":" . __LINE__ );
|
|
|
|
searchPropertyKey($fn, $device, $value, $listPropertiesKeys);
|
|
|
|
}
|
2021-12-31 23:09:58 +01:00
|
|
|
}
|
2022-02-23 10:23:16 +01:00
|
|
|
|
2021-12-31 23:09:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function searchPropertyValue($fn, &$device, $object, $listProperties)
|
2021-12-30 16:18:32 +01:00
|
|
|
{
|
|
|
|
$objectArray = (array)$object;
|
|
|
|
foreach($listProperties as $key => $value)
|
|
|
|
{
|
|
|
|
if (in_array($value, $objectArray))
|
|
|
|
{
|
|
|
|
//echo "$value trouvé =>";
|
|
|
|
$device->$key = $value;
|
|
|
|
//echo $device->$key . EOL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-02 12:14:30 +01:00
|
|
|
function changeDevice($topic, $fn, &$device, $payloadArray)
|
2021-12-30 16:18:32 +01:00
|
|
|
{
|
2022-01-02 12:14:30 +01:00
|
|
|
//print_r($payloadArray);
|
2022-01-03 21:11:52 +01:00
|
|
|
if (!empty($payloadArray))
|
|
|
|
{
|
2022-02-02 21:18:44 +01:00
|
|
|
//echo "==================== New ChangeDevice =====================" .EOL;
|
|
|
|
|
2022-01-17 00:18:50 +01:00
|
|
|
iterateDevice($topic, $fn, $device, $device, $payloadArray);
|
2022-01-03 21:11:52 +01:00
|
|
|
}else
|
|
|
|
{
|
2022-01-30 00:21:50 +01:00
|
|
|
logger(ERROR, $fn . _(" => payloadArray is empty!"), __FILE__ . ":" . __LINE__);
|
2022-01-03 21:11:52 +01:00
|
|
|
}
|
|
|
|
|
2021-12-30 16:18:32 +01:00
|
|
|
}
|
|
|
|
|
2022-01-17 00:18:50 +01:00
|
|
|
function iterateDevice($topic, $fn, $parentDevice, &$device, $payloadArray, $propertyTree="")
|
2021-12-30 16:18:32 +01:00
|
|
|
{
|
2022-01-17 21:01:11 +01:00
|
|
|
global $changed, $mohaDB, $testMode;
|
2022-02-12 15:23:58 +01:00
|
|
|
$deviceType = (is_a($device, "device")); // = true if object
|
2022-02-02 21:18:44 +01:00
|
|
|
//echo "==================== New iterate =====================" .EOL;
|
2022-02-23 10:23:16 +01:00
|
|
|
//echo "deviceType = "; var_dump($deviceType); echo EOL;
|
2021-12-30 16:18:32 +01:00
|
|
|
//echo "device =>";print_r($device);echo EOL;
|
2022-01-17 00:18:50 +01:00
|
|
|
//echo "PropertyTree ==============> " . $propertyTree . EOL;
|
2022-01-02 12:14:30 +01:00
|
|
|
foreach($payloadArray as $key => $value)
|
2021-12-30 16:18:32 +01:00
|
|
|
{
|
2022-01-08 23:45:38 +01:00
|
|
|
$oldValue = null;
|
2021-12-30 16:18:32 +01:00
|
|
|
//echo "key =>"; print_r($key); echo EOL;
|
2022-02-23 10:23:16 +01:00
|
|
|
//echo "value =>"; var_dump($value); echo EOL;
|
2021-12-30 16:18:32 +01:00
|
|
|
//echo "type : " . gettype($value) .EOL;
|
2022-01-17 00:18:50 +01:00
|
|
|
$valueType = gettype($value);
|
2022-02-02 21:18:44 +01:00
|
|
|
if ($valueType == "object")
|
2021-12-30 16:18:32 +01:00
|
|
|
{
|
2022-02-23 10:23:16 +01:00
|
|
|
//logger(DEBUG, _("valueType == object"), __FILE__ . ":" . __LINE__);
|
|
|
|
|
2022-01-17 00:18:50 +01:00
|
|
|
$propertyTree .= $key . "/";
|
2022-02-02 21:18:44 +01:00
|
|
|
//echo "PropertyTree " . $propertyTree . EOL;
|
2021-12-30 16:18:32 +01:00
|
|
|
//echo " is Object" . EOL;
|
2022-01-17 00:18:50 +01:00
|
|
|
if ($deviceType === true )
|
2021-12-30 16:18:32 +01:00
|
|
|
{
|
2022-02-02 21:18:44 +01:00
|
|
|
//echo "deviceType = true" . EOL;
|
2022-02-12 15:23:58 +01:00
|
|
|
if (!array_key_exists($key, $device->properties))
|
2022-01-17 00:18:50 +01:00
|
|
|
{
|
2022-02-02 21:18:44 +01:00
|
|
|
//echo "Property do not exists" . EOL;
|
2022-02-12 15:23:58 +01:00
|
|
|
$device->properties[$key] = new stdClass;
|
2022-01-17 00:18:50 +01:00
|
|
|
}
|
|
|
|
//echo "iterating" . EOL;
|
2022-02-02 21:18:44 +01:00
|
|
|
//echo "===============>";
|
|
|
|
|
2022-02-12 15:23:58 +01:00
|
|
|
iterateDevice($topic, $fn, $parentDevice, $device->properties[$key], $value, $propertyTree);
|
2022-02-23 10:23:16 +01:00
|
|
|
}elseif(is_array($device))
|
2022-01-17 00:18:50 +01:00
|
|
|
{
|
|
|
|
//echo "is array";
|
2022-02-23 10:23:16 +01:00
|
|
|
if (!array_key_exists($key, $device))
|
2022-01-17 00:18:50 +01:00
|
|
|
{
|
2022-02-23 10:23:16 +01:00
|
|
|
$device[$key] = new stdClass;
|
2022-01-17 00:18:50 +01:00
|
|
|
}
|
|
|
|
//echo "iterating" . EOL;
|
2022-02-23 10:23:16 +01:00
|
|
|
iterateDevice($topic, $fn, $parentDevice, $device[$key], $value, $propertyTree);
|
|
|
|
}elseif(is_object($device))
|
|
|
|
{
|
|
|
|
if (!property_exists($device, $key))
|
|
|
|
{
|
|
|
|
$device->$key = new stdClass;
|
|
|
|
}
|
|
|
|
iterateDevice($topic, $fn, $parentDevice, $device->$key, $value, $propertyTree);
|
2021-12-30 16:18:32 +01:00
|
|
|
}
|
2022-01-17 00:18:50 +01:00
|
|
|
|
|
|
|
}elseif ($valueType == "array")
|
2021-12-30 16:18:32 +01:00
|
|
|
{
|
2022-02-23 10:23:16 +01:00
|
|
|
//logger(DEBUG,_("valueType == array"), __FILE__ . ":" . __LINE__);
|
2022-01-17 00:18:50 +01:00
|
|
|
$propertyTree .= $key . "/";
|
|
|
|
if ($deviceType === true )
|
|
|
|
{
|
2022-02-12 15:23:58 +01:00
|
|
|
$device->properties[$key] = array();
|
|
|
|
iterateDevice($topic, $fn, $parentDevice, $device->properties[$key], $value, $propertyTree);
|
2022-02-23 10:23:16 +01:00
|
|
|
}elseif(is_array($device))
|
2022-01-17 00:18:50 +01:00
|
|
|
{
|
2022-02-23 10:23:16 +01:00
|
|
|
$device[$key] = array();
|
|
|
|
iterateDevice($topic, $fn, $parentDevice, $device[$key], $value, $propertyTree);
|
|
|
|
}elseif(is_object($device))
|
|
|
|
{
|
|
|
|
$device->$key = array();
|
|
|
|
iterateDevice($topic, $fn, $parentDevice, $device->$key, $value, $propertyTree);
|
2022-01-17 00:18:50 +01:00
|
|
|
}
|
2021-12-30 16:18:32 +01:00
|
|
|
|
|
|
|
}else
|
|
|
|
{
|
2022-02-23 10:23:16 +01:00
|
|
|
//logger(DEBUG,_("valueType is ") . $valueType, __FILE__ . ":" . __LINE__);
|
|
|
|
|
2022-02-02 21:18:44 +01:00
|
|
|
//var_dump($device);echo EOL;
|
2022-02-23 10:23:16 +01:00
|
|
|
if (is_a($device, "device"))
|
|
|
|
{
|
|
|
|
//logger(DEBUG,_("This is an object 'device'"), __FILE__ . ":" . __LINE__);
|
|
|
|
if(array_key_exists($key, $device->properties))
|
2022-01-02 18:14:13 +01:00
|
|
|
{
|
2022-02-23 10:23:16 +01:00
|
|
|
if ($device->properties[$key]["value"] != $value)
|
2022-01-17 00:18:50 +01:00
|
|
|
{
|
2022-02-23 10:23:16 +01:00
|
|
|
changeValue($device->properties[$key]["value"], $value, $parentDevice, $propertyTree, $key);
|
|
|
|
}
|
|
|
|
}else
|
|
|
|
{
|
|
|
|
$device->properties[$key] = array("value" => $value);
|
|
|
|
$device->properties[$key]["functions"] = array();
|
|
|
|
}
|
|
|
|
}elseif (is_array($device))
|
|
|
|
{
|
|
|
|
//logger(DEBUG,_("deviceType") . $deviceType, __FILE__ . ":" . __LINE__);
|
|
|
|
if (array_key_exists($key, $device))
|
|
|
|
{
|
|
|
|
if (is_array($device[$key]))
|
|
|
|
{
|
|
|
|
if ($device[$key]["value"] != $value)
|
|
|
|
{
|
|
|
|
changeValue($device->$key["value"], $value, $parentDevice, $propertyTree, $key);
|
|
|
|
}
|
2022-01-17 00:18:50 +01:00
|
|
|
}else
|
|
|
|
{
|
2022-02-23 10:23:16 +01:00
|
|
|
changeValue($device[$key], $value, $parentDevice, $propertyTree, $key);
|
2022-01-17 00:18:50 +01:00
|
|
|
}
|
2022-01-05 00:01:41 +01:00
|
|
|
}else
|
2021-12-30 16:18:32 +01:00
|
|
|
{
|
2022-02-23 10:23:16 +01:00
|
|
|
$device[$key] = array("value" => $value);
|
|
|
|
$device[$key]["functions"] = array();
|
2022-01-05 00:01:41 +01:00
|
|
|
}
|
2022-02-23 10:23:16 +01:00
|
|
|
}elseif (is_object($device))
|
|
|
|
{
|
|
|
|
if(property_exists($device, $key))
|
2022-01-05 00:01:41 +01:00
|
|
|
{
|
2022-02-23 10:23:16 +01:00
|
|
|
if (is_array($device->$key))
|
|
|
|
{
|
|
|
|
if ($device->$key["value"] != $value)
|
|
|
|
{
|
|
|
|
changeValue($device->$key["value"], $value, $parentDevice, $propertyTree, $key);
|
|
|
|
}
|
|
|
|
}else
|
2021-12-30 16:18:32 +01:00
|
|
|
{
|
2022-02-23 10:23:16 +01:00
|
|
|
if ($device->$key != $value)
|
2022-02-12 15:23:58 +01:00
|
|
|
{
|
2022-02-23 10:23:16 +01:00
|
|
|
changeValue($device->$key, $value, $parentDevice, $propertyTree, $key);
|
2022-02-12 15:23:58 +01:00
|
|
|
}
|
2021-12-30 16:18:32 +01:00
|
|
|
}
|
2022-02-23 10:23:16 +01:00
|
|
|
}else
|
|
|
|
{
|
|
|
|
$device->$key = array("value" => $value);
|
|
|
|
$device->$key["functions"] = array();
|
2021-12-30 16:18:32 +01:00
|
|
|
}
|
2022-02-23 10:23:16 +01:00
|
|
|
}
|
2021-12-30 16:18:32 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-07 16:58:42 +01:00
|
|
|
function getDevicesValues($topic)
|
2022-01-06 13:03:26 +01:00
|
|
|
{
|
2022-02-07 16:58:42 +01:00
|
|
|
global $indexDevices, $topics;
|
2022-02-23 10:23:16 +01:00
|
|
|
logger(DEBUG, _("getDevicesValues function" ), __FILE__ . ":" . __LINE__ );
|
2022-02-07 16:58:42 +01:00
|
|
|
foreach($indexDevices as $device)
|
|
|
|
{
|
|
|
|
if ($device->topic == $topic)
|
|
|
|
{
|
2022-02-23 10:23:16 +01:00
|
|
|
logger(DEBUG, "device: " . $device->friendlyName, __FILE__ . ":" . __LINE__ );
|
|
|
|
$device->payload = array();
|
2022-02-07 16:58:42 +01:00
|
|
|
$flag = false;
|
2022-02-12 15:23:58 +01:00
|
|
|
//$properties = array_slice($device, 12);
|
|
|
|
//logger(DEBUG, print_r($properties, true));
|
2022-02-23 10:23:16 +01:00
|
|
|
if (!empty($device->properties))
|
2022-02-07 16:58:42 +01:00
|
|
|
{
|
2022-02-23 10:23:16 +01:00
|
|
|
foreach($device->properties as $property => $value)
|
2022-02-07 16:58:42 +01:00
|
|
|
{
|
2022-02-23 10:23:16 +01:00
|
|
|
$device->payload[$property] = "";
|
2022-02-07 16:58:42 +01:00
|
|
|
}
|
2022-02-23 10:23:16 +01:00
|
|
|
//logger(DEBUG, print_r($device->payload, true), __FILE__ . ":" . __LINE__ );
|
|
|
|
$device->get();
|
|
|
|
}else
|
|
|
|
{
|
|
|
|
logger(DEBUG, _("no properties to get for device: " . $device->friendlyName ), __FILE__ . ":" . __LINE__ );
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function getDeviceByFriendlyname(&$device, $topic, $fn, $payloadArray, $create = false)
|
|
|
|
{
|
|
|
|
global $devices, $indexDevices, $indexFriendlyNames;
|
|
|
|
$n = explode("/", $fn);
|
|
|
|
//echo "topic => ". $topic . EOL;
|
|
|
|
$device = &$devices[$topic];
|
|
|
|
foreach($n as $value)
|
|
|
|
{
|
|
|
|
//print_r($device[$value]);
|
|
|
|
if (array_key_exists($value, $device))
|
|
|
|
{
|
|
|
|
$device = &$device[$value];
|
|
|
|
}elseif($create === true)
|
|
|
|
{
|
|
|
|
$device[$value] = array();
|
|
|
|
$device = &$device[$value];
|
|
|
|
}else
|
|
|
|
{
|
|
|
|
logger(ERROR, sprintf(_(" device with friendlyname %s not found"), $fn), __FILE__ . ":" . __LINE__);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
if (! array_key_exists("device", $device))
|
|
|
|
{
|
|
|
|
if ($create === true)
|
|
|
|
{
|
|
|
|
logger(WARNING, _("init of ") . $fn, __FILE__ . ":" . __LINE__);
|
|
|
|
$device["device"] = new device;
|
|
|
|
$device["device"]->type = $payloadArray->type;
|
|
|
|
$device["device"]->ieeeAddress = $payloadArray->ieeeAddress;
|
|
|
|
$device["device"]->friendlyname = $fn;
|
|
|
|
$indexDevices[$device["device"]->ieeeAddress] = & $device["device"];
|
|
|
|
$indexFriendlyNames[$fn] = & $device["device"];
|
|
|
|
}
|
|
|
|
}else
|
|
|
|
{
|
|
|
|
logger(INFO, sprintf(_(" device with friendlyname %s exists"), $fn), __FILE__ . ":" . __LINE__);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
function changeValue(&$oldValue, $value, &$parentDevice, $propertyTree, $key)
|
|
|
|
{
|
|
|
|
global $mohaDB;
|
|
|
|
$object = $parentDevice->properties[$key];
|
|
|
|
//$changed[$fn]["key"] = $key;
|
|
|
|
//$changed[$fn]["value"] = $value;
|
|
|
|
logger(INFO, sprintf(_("Logging Device %s property %s, %s"), $parentDevice->friendlyName, $propertyTree . $key, bool2string($value)), __FILE__ . ":" . __LINE__);
|
|
|
|
$mohaDB->logProperty($parentDevice, $key, $value, $oldValue);
|
|
|
|
$oldvalue = $value;
|
|
|
|
if (!empty($object["functions"]))
|
|
|
|
{
|
|
|
|
logger(DEBUG,_("executing notifications functions"), __FILE__ . ":" . __LINE__);
|
|
|
|
foreach($object["functions"] as $function)
|
|
|
|
{
|
|
|
|
$function($parentDevice, $key, $value);
|
2022-02-07 16:58:42 +01:00
|
|
|
}
|
|
|
|
}
|
2022-01-06 13:03:26 +01:00
|
|
|
}
|
2021-12-30 16:18:32 +01:00
|
|
|
|
|
|
|
?>
|