diff --git a/VGT_Sub/module.php b/VGT_Sub/module.php index ac40a48..bf5cd08 100644 --- a/VGT_Sub/module.php +++ b/VGT_Sub/module.php @@ -48,8 +48,6 @@ class VGT_Sub extends IPSModule * FEEDBACK REQUEST Variablen (read-only) * ------------------------------------------*/ $this->RegisterVariableString('FeedbackRequestPayload', 'Feedback Request Payload', '', 40); - - // WICHTIG: Kein ConnectParent mehr hier -> Modul ist nur Client/Device } @@ -57,9 +55,6 @@ class VGT_Sub extends IPSModule { parent::ApplyChanges(); - // Kein ConnectParent mehr -> Parent wird in der Konsole verknüpft - // (MQTT Server ODER MQTT Client Gateway) - $device = $this->ReadPropertyString('DeviceID'); if ($device === '') { return; @@ -80,10 +75,6 @@ class VGT_Sub extends IPSModule { $this->SetValue($Ident, $Value); - // Optional: Hier könntest du auch direkt publizieren, - // wenn eine Variable geändert wird. - // Beispiel (auskommentiert, nur als Vorlage): - $device = $this->ReadPropertyString('DeviceID'); if ($device !== '') { switch ($Ident) { @@ -105,7 +96,6 @@ class VGT_Sub extends IPSModule break; } } - } @@ -114,6 +104,11 @@ class VGT_Sub extends IPSModule * ------------------------------------------*/ private function Subscribe(string $topic): void { + if (!$this->HasActiveParent()) { + $this->SendDebug('MQTT', 'Subscribe ohne aktiven Parent: ' . $topic, 0); + return; + } + $packet = [ 'PacketType' => 8, // SUBSCRIBE 'QualityOfService' => 0, @@ -133,6 +128,11 @@ class VGT_Sub extends IPSModule * ------------------------------------------*/ private function Publish(string $topic, string $payload): void { + if (!$this->HasActiveParent()) { + $this->SendDebug('MQTT', 'Publish ohne aktiven Parent: ' . $topic, 0); + return; + } + $packet = [ 'PacketType' => 3, // PUBLISH 'QualityOfService' => 0, @@ -160,6 +160,8 @@ class VGT_Sub extends IPSModule $topic = $data['Topic'] ?? ''; $payload = $data['Payload'] ?? ''; + $this->SendDebug('MQTT', 'Receive: Topic=' . $topic . ' Payload=' . $payload, 0); + $device = $this->ReadPropertyString('DeviceID'); if ($device === '') { return; @@ -167,21 +169,16 @@ class VGT_Sub extends IPSModule /** ------------------------------------------- * 1️⃣ FEEDBACK REQUEST - * request: feedback-request/deviceId - * response: feedback-response/deviceId * ------------------------------------------*/ if ($topic === "feedback-request/$device") { - // 1. Payload speichern $this->SetValue('FeedbackRequestPayload', $payload); - // 2. JSON interpretieren (falls vorhanden) $json = json_decode($payload, true); if (!is_array($json)) { $json = []; } - // 3. Antwort-Mix erstellen (Payload + Status) $response = array_merge($json, [ "power_production" => $this->GetValue('PowerProduction'), "is_ready" => $this->GetValue('IsReady'), @@ -191,20 +188,15 @@ class VGT_Sub extends IPSModule "max_soc" => $this->GetValue('MaxSOC') ]); - // 4. Antwort senden $this->Publish("feedback-response/$device", json_encode($response)); return; } - /** ------------------------------------------- * 2️⃣ REMOTE CONTROL REQUEST - * request: remote-control-request/deviceId - * response: remote-control-response/deviceId * ------------------------------------------*/ if ($topic === "remote-control-request/$device") { - // 1. Payload speichern $this->SetValue('RemoteControlPayload', $payload); $json = json_decode($payload, true); @@ -219,7 +211,6 @@ class VGT_Sub extends IPSModule } } - // 2. Echo Response $this->Publish("remote-control-response/$device", $payload); return; }