diff --git a/HauptManager/module.php b/HauptManager/module.php index 5e0284d..81d9576 100644 --- a/HauptManager/module.php +++ b/HauptManager/module.php @@ -2,8 +2,6 @@ class HauptManager extends IPSModule { - private $clients = []; - public function Create() { parent::Create(); @@ -13,6 +11,7 @@ class HauptManager extends IPSModule $this->RegisterPropertyInteger("Ueberschussleistung", 0); $this->RegisterPropertyInteger("Netzbezug", 0); // Initialisierung mit 0 $this->RegisterPropertyString("Verbraucher_Liste", "[]"); + $this->RegisterVariableString("Clients", "Clients", "", 0); // Timer registrieren $this->RegisterTimer("Timer_DistributeEnergy", 5000, "IPS_RequestAction(" .$this->InstanceID .', "DistributeEnergy", "");'); @@ -86,25 +85,38 @@ class HauptManager extends IPSModule public function AddClient($conn) { - $this->clients[] = $conn; + $clients = json_decode($this->GetValue("Clients"), true); + if ($clients === null) { + $clients = []; + } + $clients[] = (string)$conn->resourceId; + $this->SetValue("Clients", json_encode($clients)); $this->UpdateClientList(); } public function RemoveClient($conn) { - $index = array_search($conn, $this->clients); - if ($index !== false) { - unset($this->clients[$index]); - $this->clients = array_values($this->clients); // Reindizieren des Arrays - $this->UpdateClientList(); + $clients = json_decode($this->GetValue("Clients"), true); + if ($clients !== null) { + $index = array_search((string)$conn->resourceId, $clients); + if ($index !== false) { + unset($clients[$index]); + $clients = array_values($clients); // Reindizieren des Arrays + $this->SetValue("Clients", json_encode($clients)); + $this->UpdateClientList(); + } } } private function UpdateClientList() { + $clients = json_decode($this->GetValue("Clients"), true); + if ($clients === null) { + $clients = []; + } $clientList = []; - foreach ($this->clients as $client) { - $clientList[] = ['Client' => (string)$client->resourceId]; + foreach ($clients as $client) { + $clientList[] = ['Client' => $client]; } $this->UpdateFormField('ClientList', 'values', json_encode($clientList)); } diff --git a/library.json b/library.json index fe54c66..edf90d6 100644 --- a/library.json +++ b/library.json @@ -6,7 +6,7 @@ "compatibility": { "version": "7.1" }, - "version": "1.101", + "version": "1.102", "build": 0, "date": 0 } \ No newline at end of file