From 6354fac434ae5315e3605370e1f61ba9923888dc Mon Sep 17 00:00:00 2001 From: DanielHaefliger Date: Thu, 6 Aug 2026 08:49:17 +0200 Subject: [PATCH] no message --- EaseeGateway/module.php | 7 +- Ladestation_v2/README.md | 5 +- Ladestation_v2/form.json | 2 + Ladestation_v2/module.json | 4 +- Ladestation_v2/module.php | 150 +++++++++++++++++++++++++++---------- 5 files changed, 122 insertions(+), 46 deletions(-) diff --git a/EaseeGateway/module.php b/EaseeGateway/module.php index cf03d59..c34ef20 100644 --- a/EaseeGateway/module.php +++ b/EaseeGateway/module.php @@ -178,7 +178,12 @@ class EaseeGateway extends IPSModule return json_encode(["success" => false, "error" => "Ungültiges Datenpaket"]); } - $request = json_decode($packet["Buffer"], true); + return $this->ProcessStationRequest($packet["Buffer"]); + } + + public function ProcessStationRequest($JSONString) + { + $request = json_decode($JSONString, true); if (!is_array($request) || !isset($request["action"])) { return json_encode(["success" => false, "error" => "Ungültige Gateway-Anfrage"]); } diff --git a/Ladestation_v2/README.md b/Ladestation_v2/README.md index 7912c2e..907eee4 100644 --- a/Ladestation_v2/README.md +++ b/Ladestation_v2/README.md @@ -4,8 +4,9 @@ Das Modul steuert verschiedene Ladestationstypen. ## Easee -Die Ladestationstypen 5 und 6 verwenden das übergeordnete -`Easee SignalR Gateway`. +Die Ladestationstypen 5 und 6 verwenden das ausgewählte +`Easee SignalR Gateway`. Bei den Typen 1 bis 4 wird die Gateway-Auswahl +ausgeblendet und keine Gateway-Verbindung verwendet. - Typ 5: Easee mit zusätzlicher eCarUp-Benutzerprüfung für Solarladen - Typ 6: Easee ohne eCarUp-Benutzerprüfung diff --git a/Ladestation_v2/form.json b/Ladestation_v2/form.json index 87ee376..ba25775 100644 --- a/Ladestation_v2/form.json +++ b/Ladestation_v2/form.json @@ -4,6 +4,7 @@ "type": "Select", "name": "Ladestation", "caption": "Ladestation", + "onChange": "IPS_RequestAction($id, \"UpdateEaseeGatewayVisibility\", $Ladestation);", "options": [ { "caption": "Go-E Wallbox (Alte Version)", @@ -102,6 +103,7 @@ "type": "SelectInstance", "name": "EaseeGatewayID", "caption": "Easee SignalR Gateway", + "visible": false, "validModules": [ "{7A1F1D4B-3E7D-4A3B-9E54-61C8C3B7F201}" ] diff --git a/Ladestation_v2/module.json b/Ladestation_v2/module.json index 0dba1f7..6cc721e 100644 --- a/Ladestation_v2/module.json +++ b/Ladestation_v2/module.json @@ -4,9 +4,7 @@ "type": 3, "vendor": "Belevo AG", "aliases": [], - "parentRequirements": [ - "{BC4E9B83-9C9B-44C3-A902-5CEB45B0E5B1}" - ], + "parentRequirements": [], "childRequirements": [], "implemented": [ "{A8EF2E37-6B35-4E92-A7D1-4F8172790BA2}" diff --git a/Ladestation_v2/module.php b/Ladestation_v2/module.php index 6394679..bff8d5b 100644 --- a/Ladestation_v2/module.php +++ b/Ladestation_v2/module.php @@ -115,12 +115,73 @@ class Ladestation_v2 extends IPSModule } + public function Migrate($JSONData) + { + parent::Migrate($JSONData); + + $data = json_decode($JSONData, true); + if (!is_array($data)) { + return ""; + } + + if (!isset($data["configuration"]) || !is_array($data["configuration"])) { + $data["configuration"] = []; + } + + $changed = !array_key_exists("EaseeGatewayID", $data["configuration"]); + $gatewayID = (int)($data["configuration"]["EaseeGatewayID"] ?? 0); + + // Vorhandene Gateway-Verbindung aus Version 1.1 uebernehmen. + if ($gatewayID <= 0) { + $instance = IPS_GetInstance($this->InstanceID); + $connectionID = (int)$instance["ConnectionID"]; + if ($connectionID > 0 && IPS_InstanceExists($connectionID)) { + $parent = IPS_GetInstance($connectionID); + if ($parent["ModuleInfo"]["ModuleID"] === self::EASEE_GATEWAY_MODULE_ID) { + $gatewayID = $connectionID; + $changed = true; + } + } + } + + if (!$changed) { + return ""; + } + + $data["configuration"]["EaseeGatewayID"] = $gatewayID; + return json_encode($data); + } + + public function GetConfigurationForm() + { + $form = json_decode(file_get_contents(__DIR__ . "/form.json"), true); + $showGateway = $this->UsesEaseeGateway($this->ReadPropertyInteger("Ladestation")); + + foreach ($form["elements"] as &$element) { + if (($element["name"] ?? "") === "EaseeGatewayID") { + $element["visible"] = $showGateway; + break; + } + } + unset($element); + + return json_encode($form); + } + public function ApplyChanges() { parent::ApplyChanges(); + // Bei aktualisierten Bestandsinstanzen die in Version 1.1 neue Variable + // sofort anlegen; RegisterVariableBoolean ist idempotent. + $this->RegisterVariableBoolean( + "Easee_Gateway_Connected", + "Easee Gateway verbunden", + "~Switch", + false + ); $this->SetTimerInterval("Timer_Do_UserCalc_EVC",$this->ReadPropertyInteger("Interval")*1000); $stationType = $this->ReadPropertyInteger("Ladestation"); - $usesEaseeGateway = $stationType === 5 || $stationType === 6; + $usesEaseeGateway = $this->UsesEaseeGateway($stationType); IPS_SetHidden( $this->GetIDForIdent("Easee_Gateway_Connected"), !$usesEaseeGateway @@ -129,43 +190,18 @@ class Ladestation_v2 extends IPSModule $instance = IPS_GetInstance($this->InstanceID); $parentID = (int)$instance["ConnectionID"]; - if ($usesEaseeGateway) { - $gatewayID = $this->ReadPropertyInteger("EaseeGatewayID"); - - if ($gatewayID > 0 && IPS_InstanceExists($gatewayID)) { - $gateway = IPS_GetInstance($gatewayID); - if ($gateway["ModuleInfo"]["ModuleID"] !== self::EASEE_GATEWAY_MODULE_ID) { - IPS_LogMessage("Ladestation_v2", "Ausgewählte Instanz ist kein Easee Gateway"); - $gatewayID = 0; - } - } else { - $gatewayID = 0; - } - - if ($gatewayID > 0 && $parentID !== $gatewayID) { - if ($parentID > 0) { - IPS_DisconnectInstance($this->InstanceID); - } - IPS_ConnectInstance($this->InstanceID, $gatewayID); - $parentID = $gatewayID; - } elseif ($gatewayID === 0 && $parentID > 0) { - $parent = IPS_GetInstance($parentID); - if ($parent["ModuleInfo"]["ModuleID"] === self::EASEE_GATEWAY_MODULE_ID) { - IPS_DisconnectInstance($this->InstanceID); - $parentID = 0; - } - } - - if ($parentID > 0) { - $this->SubscribeToEaseeGateway(); - } else { - $this->SetValue("Easee_Gateway_Connected", false); - } - } elseif ($parentID > 0) { + // Alte Parent-Verbindungen aus Version 1.1 entfernen. Ab Version 1.2 + // wird das Gateway optional ueber EaseeGatewayID angesprochen. + if ($parentID > 0) { $parent = IPS_GetInstance($parentID); if ($parent["ModuleInfo"]["ModuleID"] === self::EASEE_GATEWAY_MODULE_ID) { IPS_DisconnectInstance($this->InstanceID); } + } + + if ($usesEaseeGateway && $this->GetConfiguredEaseeGatewayID() > 0) { + $this->SubscribeToEaseeGateway(); + } else { $this->SetValue("Easee_Gateway_Connected", false); } @@ -178,6 +214,14 @@ class Ladestation_v2 extends IPSModule { switch ($Ident) { + case "UpdateEaseeGatewayVisibility": + $this->UpdateFormField( + "EaseeGatewayID", + "visible", + $this->UsesEaseeGateway((int)$Value) + ); + break; + case "SetAktuelle_Leistung": $this->SetValue("Power", (int)$Value); break; @@ -299,16 +343,22 @@ class Ladestation_v2 extends IPSModule private function SendEaseeGatewayRequest(array $request) { - $instance = IPS_GetInstance($this->InstanceID); - if ((int)$instance["ConnectionID"] <= 0) { + $gatewayID = $this->GetConfiguredEaseeGatewayID(); + if ($gatewayID <= 0) { $this->SetValue("Easee_Gateway_Connected", false); return null; } - $response = $this->SendDataToParent(json_encode([ - "DataID" => self::EASEE_GATEWAY_REQUEST_ID, - "Buffer" => json_encode($request), - ])); + try { + $response = EASEEGW_ProcessStationRequest( + $gatewayID, + json_encode($request) + ); + } catch (Throwable $error) { + $this->SetValue("Easee_Gateway_Connected", false); + IPS_LogMessage("Ladestation_v2", $error->getMessage()); + return null; + } if (!is_string($response) || $response === "") { return null; @@ -318,6 +368,26 @@ class Ladestation_v2 extends IPSModule return is_array($decoded) ? $decoded : null; } + private function GetConfiguredEaseeGatewayID(): int + { + $gatewayID = $this->ReadPropertyInteger("EaseeGatewayID"); + if ($gatewayID <= 0 || !IPS_InstanceExists($gatewayID)) { + return 0; + } + + $gateway = IPS_GetInstance($gatewayID); + if ($gateway["ModuleInfo"]["ModuleID"] !== self::EASEE_GATEWAY_MODULE_ID) { + return 0; + } + + return $gatewayID; + } + + private function UsesEaseeGateway(int $stationType): bool + { + return $stationType === 5 || $stationType === 6; + } + private function ApplyEaseeGatewayResponse($response) { if (!is_array($response)) {