1
0

- indexFriendlyName modified\n- debugging

This commit is contained in:
2022-02-24 21:46:10 +01:00
parent 34dca81ba5
commit f6b7b9e664
7 changed files with 41 additions and 145 deletions

View File

@ -21,8 +21,7 @@ $topics["linky2mqtt"]->callback = function($topic, $message)
$device["device"]->ieeeAddress = $payloadArray["ieeeAddress"];
$device["device"]->type = $payloadArray["type"];
$indexDevices[$device["device"]->ieeeAddress] = & $device["device"];
$indexFriendlyNames[$fn] = & $device["device"];
$indexFriendlyNames[$topicName][$fn] = & $device["device"];
}else
{
$device = &$device[$fn];

View File

@ -22,7 +22,7 @@ $topics["pws2mqtt"]->callback = function($topic, $message)
$device["device"]->type = $payloadArray["type"];
$device["device"]->topic = $topicName;
$indexDevices[$device["device"]->ieeeAddress] = & $device["device"];
$indexFriendlyNames[$fn] = & $device["device"];
$indexFriendlyNames[$topicName][$fn] = & $device["device"];
}else
{

View File

@ -5,7 +5,7 @@ $devices["zigbee2mqtt"] = array();
$topics["zigbee2mqtt"]->callback = function($topic, $message)
{
global $topics, $devices, $included, $logFh;
global $topics, $devices, $included, $logFh, $indexFriendlyNames;
if ($topic[1] == "bridge")
{
@ -46,7 +46,7 @@ $topics["zigbee2mqtt"]->callback = function($topic, $message)
$topic = explode ("/", $message->topic, 2); // get topic name
$topicName = $topic[0];
$fn = $topic[1];
$device = null;
$device = new device;
$fnTree = explode ("/" , $topic[1]); // get friendlyname
echo $topicName . " => " . $fn . EOL;
@ -64,25 +64,24 @@ $topics["zigbee2mqtt"]->callback = function($topic, $message)
$fn = implode("/", $fnTree);
$fn = implode("/", $fnTree);
$payloadArray = array($fnTreeEnd => $message->payload);
//TODO payl
$payloadArray = array($fnTreeEnd => $message->payload);
//TODO payload can be a json object
break;
default:
$payloadArray = json_decode($message->payload,true);
}
logger(DEBUG, _("friendlyname = ") . $fn, __FILE__ . ":" . __LINE__);
if ((getDeviceByFriendlyname($device, $topicName, $fn, $payloadArray, true)) === false)
if (!array_key_exists($fn, $indexFriendlyNames[$topicName]))
{
logger(ERROR, sprintf(_("device with friendlyname %s not found"), $fn), __FILE__ . ":" . __LINE__);
}else
{
changeDevice($topicName, $fn, $indexFriendlyNames[$topicName][$fn], $payloadArray);
}
print_r($device);
changeDevice($topicName, $fn, $device["device"], $payloadArray);
}else
{
logger(DEBUG, _("Zigbee2mqtt doing nothing !?"));
}
};