1
0
moha/topics_callbacks/linky2mqtt.php

38 lines
1.2 KiB
PHP
Raw Normal View History

2022-01-17 00:18:50 +01:00
<?php
//TODO to test and debug
$topics["linky2mqtt"] = new topic;
2022-02-23 10:23:16 +01:00
$devices["linky2mqtt"] = array();
2022-01-17 00:18:50 +01:00
$topics["linky2mqtt"]->callback = function($topic, $message)
{
global $topics, $logFh, $devices, $included;
$topicName = $topic[0];
$friendlyName = $topic[1]; // get friendlyName
2022-02-23 10:23:16 +01:00
logger(INFO, sprintf(_("Incoming notification of device %s"), $topicName, $fn), __FILE__ . ":" . __LINE__);
$payloadArray = json_decode($message->payload, true);
if (!array_key_exists($fn, $device))
2022-01-17 00:18:50 +01:00
{
2022-02-23 10:23:16 +01:00
echo "initializing $fn";
$device[$fn] = array("device" => new device);
$device = &$device[$fn];
$device["device"]->friendlyName = $payloadArray["friendly_name"];
$device["device"]->ieeeAddress = $payloadArray["ieeeAddress"];
$device["device"]->type = $payloadArray["type"];
$indexDevices[$device["device"]->ieeeAddress] = & $device["device"];
$indexFriendlyNames[$topicName][$fn] = & $device["device"];
2022-02-23 10:23:16 +01:00
}else
{
$device = &$device[$fn];
2022-01-17 00:18:50 +01:00
}
2022-02-23 10:23:16 +01:00
unset($payloadArray["friendly_name"]);
unset($payloadArray["ieeeAddress"]);
unset($payloadArray["type"]);
//$device = getDeviceByFriendlyname($topicName, $fn, $payloadArray, true);
2022-01-17 00:18:50 +01:00
changeDevice($topicName, $friendlyName, $device["device"], $payloadArray);
2022-01-19 00:22:34 +01:00
//print_r($device["device"]);
2022-01-17 00:18:50 +01:00
}
?>