no message

This commit is contained in:
dh
2026-08-06 08:49:17 +02:00
parent 9200e2bc51
commit 6354fac434
5 changed files with 122 additions and 46 deletions
+6 -1
View File
@@ -178,7 +178,12 @@ class EaseeGateway extends IPSModule
return json_encode(["success" => false, "error" => "Ungültiges Datenpaket"]); 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"])) { if (!is_array($request) || !isset($request["action"])) {
return json_encode(["success" => false, "error" => "Ungültige Gateway-Anfrage"]); return json_encode(["success" => false, "error" => "Ungültige Gateway-Anfrage"]);
} }
+3 -2
View File
@@ -4,8 +4,9 @@ Das Modul steuert verschiedene Ladestationstypen.
## Easee ## Easee
Die Ladestationstypen 5 und 6 verwenden das übergeordnete Die Ladestationstypen 5 und 6 verwenden das ausgewählte
`Easee SignalR Gateway`. `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 5: Easee mit zusätzlicher eCarUp-Benutzerprüfung für Solarladen
- Typ 6: Easee ohne eCarUp-Benutzerprüfung - Typ 6: Easee ohne eCarUp-Benutzerprüfung
+2
View File
@@ -4,6 +4,7 @@
"type": "Select", "type": "Select",
"name": "Ladestation", "name": "Ladestation",
"caption": "Ladestation", "caption": "Ladestation",
"onChange": "IPS_RequestAction($id, \"UpdateEaseeGatewayVisibility\", $Ladestation);",
"options": [ "options": [
{ {
"caption": "Go-E Wallbox (Alte Version)", "caption": "Go-E Wallbox (Alte Version)",
@@ -102,6 +103,7 @@
"type": "SelectInstance", "type": "SelectInstance",
"name": "EaseeGatewayID", "name": "EaseeGatewayID",
"caption": "Easee SignalR Gateway", "caption": "Easee SignalR Gateway",
"visible": false,
"validModules": [ "validModules": [
"{7A1F1D4B-3E7D-4A3B-9E54-61C8C3B7F201}" "{7A1F1D4B-3E7D-4A3B-9E54-61C8C3B7F201}"
] ]
+1 -3
View File
@@ -4,9 +4,7 @@
"type": 3, "type": 3,
"vendor": "Belevo AG", "vendor": "Belevo AG",
"aliases": [], "aliases": [],
"parentRequirements": [ "parentRequirements": [],
"{BC4E9B83-9C9B-44C3-A902-5CEB45B0E5B1}"
],
"childRequirements": [], "childRequirements": [],
"implemented": [ "implemented": [
"{A8EF2E37-6B35-4E92-A7D1-4F8172790BA2}" "{A8EF2E37-6B35-4E92-A7D1-4F8172790BA2}"
+110 -40
View File
@@ -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() public function ApplyChanges()
{ {
parent::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); $this->SetTimerInterval("Timer_Do_UserCalc_EVC",$this->ReadPropertyInteger("Interval")*1000);
$stationType = $this->ReadPropertyInteger("Ladestation"); $stationType = $this->ReadPropertyInteger("Ladestation");
$usesEaseeGateway = $stationType === 5 || $stationType === 6; $usesEaseeGateway = $this->UsesEaseeGateway($stationType);
IPS_SetHidden( IPS_SetHidden(
$this->GetIDForIdent("Easee_Gateway_Connected"), $this->GetIDForIdent("Easee_Gateway_Connected"),
!$usesEaseeGateway !$usesEaseeGateway
@@ -129,43 +190,18 @@ class Ladestation_v2 extends IPSModule
$instance = IPS_GetInstance($this->InstanceID); $instance = IPS_GetInstance($this->InstanceID);
$parentID = (int)$instance["ConnectionID"]; $parentID = (int)$instance["ConnectionID"];
if ($usesEaseeGateway) { // Alte Parent-Verbindungen aus Version 1.1 entfernen. Ab Version 1.2
$gatewayID = $this->ReadPropertyInteger("EaseeGatewayID"); // wird das Gateway optional ueber EaseeGatewayID angesprochen.
if ($parentID > 0) {
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) {
$parent = IPS_GetInstance($parentID); $parent = IPS_GetInstance($parentID);
if ($parent["ModuleInfo"]["ModuleID"] === self::EASEE_GATEWAY_MODULE_ID) { if ($parent["ModuleInfo"]["ModuleID"] === self::EASEE_GATEWAY_MODULE_ID) {
IPS_DisconnectInstance($this->InstanceID); IPS_DisconnectInstance($this->InstanceID);
} }
}
if ($usesEaseeGateway && $this->GetConfiguredEaseeGatewayID() > 0) {
$this->SubscribeToEaseeGateway();
} else {
$this->SetValue("Easee_Gateway_Connected", false); $this->SetValue("Easee_Gateway_Connected", false);
} }
@@ -178,6 +214,14 @@ class Ladestation_v2 extends IPSModule
{ {
switch ($Ident) { switch ($Ident) {
case "UpdateEaseeGatewayVisibility":
$this->UpdateFormField(
"EaseeGatewayID",
"visible",
$this->UsesEaseeGateway((int)$Value)
);
break;
case "SetAktuelle_Leistung": case "SetAktuelle_Leistung":
$this->SetValue("Power", (int)$Value); $this->SetValue("Power", (int)$Value);
break; break;
@@ -299,16 +343,22 @@ class Ladestation_v2 extends IPSModule
private function SendEaseeGatewayRequest(array $request) private function SendEaseeGatewayRequest(array $request)
{ {
$instance = IPS_GetInstance($this->InstanceID); $gatewayID = $this->GetConfiguredEaseeGatewayID();
if ((int)$instance["ConnectionID"] <= 0) { if ($gatewayID <= 0) {
$this->SetValue("Easee_Gateway_Connected", false); $this->SetValue("Easee_Gateway_Connected", false);
return null; return null;
} }
$response = $this->SendDataToParent(json_encode([ try {
"DataID" => self::EASEE_GATEWAY_REQUEST_ID, $response = EASEEGW_ProcessStationRequest(
"Buffer" => json_encode($request), $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 === "") { if (!is_string($response) || $response === "") {
return null; return null;
@@ -318,6 +368,26 @@ class Ladestation_v2 extends IPSModule
return is_array($decoded) ? $decoded : null; 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) private function ApplyEaseeGatewayResponse($response)
{ {
if (!is_array($response)) { if (!is_array($response)) {