no message

This commit is contained in:
belevo\mh
2025-11-19 13:28:23 +01:00
parent f143676798
commit 7d90eae481
+64 -4
View File
@@ -152,13 +152,28 @@ class VGT_Sub extends IPSModule
* ------------------------------------------*/
public function ReceiveData($JSONString)
{
$data = json_decode($JSONString, true);
if (!is_array($data)) {
// äußere Hülle vom MQTT-Client
$data = json_decode($JSONString);
if ($data === null) {
$this->SendDebug('MQTT', 'Ungültiges JSON: ' . $JSONString, 0);
return;
}
$topic = $data['Topic'] ?? '';
$payload = $data['Payload'] ?? '';
// aktuelles MQTT-Client-Format: Topic/Payload stecken in Buffer
if (isset($data->Buffer)) {
$buffer = json_decode($data->Buffer, true);
} else {
// Fallback auf direkte Struktur
$buffer = json_decode($JSONString, true);
}
if (!is_array($buffer)) {
$this->SendDebug('MQTT', 'Buffer ist kein Array: ' . print_r($buffer, true), 0);
return;
}
$topic = $buffer['Topic'] ?? '';
$payload = $buffer['Payload'] ?? '';
$this->SendDebug('MQTT', 'Receive: Topic=' . $topic . ' Payload=' . $payload, 0);
@@ -167,6 +182,51 @@ class VGT_Sub extends IPSModule
return;
}
// 1) feedback-request/<device>
if ($topic === "feedback-request/$device") {
$this->SetValue('FeedbackRequestPayload', $payload);
$json = json_decode($payload, true);
if (!is_array($json)) {
$json = [];
}
$response = array_merge($json, [
"power_production" => $this->GetValue('PowerProduction'),
"is_ready" => $this->GetValue('IsReady'),
"is_running" => $this->GetValue('IsRunning'),
"state_of_charge" => $this->GetValue('StateOfCharge'),
"min_soc" => $this->GetValue('MinSOC'),
"max_soc" => $this->GetValue('MaxSOC')
]);
$this->Publish("feedback-response/$device", json_encode($response));
return;
}
// 2) remote-control-request/<device>
if ($topic === "remote-control-request/$device") {
$this->SetValue('RemoteControlPayload', $payload);
$json = json_decode($payload, true);
if (is_array($json)) {
if (array_key_exists('power_setpoint', $json)) {
$this->SetValue('PowerSetpoint', (int)$json['power_setpoint']);
}
if (array_key_exists('strategy', $json)) {
$this->SetValue('Strategy', (string)$json['strategy']);
}
}
$this->Publish("remote-control-response/$device", $payload);
return;
}
}
/** -------------------------------------------
* 1️⃣ FEEDBACK REQUEST
* ------------------------------------------*/