no message
This commit is contained in:
@@ -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"]);
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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}"
|
||||
]
|
||||
|
||||
@@ -4,9 +4,7 @@
|
||||
"type": 3,
|
||||
"vendor": "Belevo AG",
|
||||
"aliases": [],
|
||||
"parentRequirements": [
|
||||
"{BC4E9B83-9C9B-44C3-A902-5CEB45B0E5B1}"
|
||||
],
|
||||
"parentRequirements": [],
|
||||
"childRequirements": [],
|
||||
"implemented": [
|
||||
"{A8EF2E37-6B35-4E92-A7D1-4F8172790BA2}"
|
||||
|
||||
+110
-40
@@ -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)) {
|
||||
|
||||
Reference in New Issue
Block a user