clients in varibale genommen

This commit is contained in:
dh
2025-02-28 07:27:16 +01:00
parent f0a6348e79
commit fc25b89c77
2 changed files with 23 additions and 11 deletions
+22 -10
View File
@@ -2,8 +2,6 @@
class HauptManager extends IPSModule class HauptManager extends IPSModule
{ {
private $clients = [];
public function Create() public function Create()
{ {
parent::Create(); parent::Create();
@@ -13,6 +11,7 @@ class HauptManager extends IPSModule
$this->RegisterPropertyInteger("Ueberschussleistung", 0); $this->RegisterPropertyInteger("Ueberschussleistung", 0);
$this->RegisterPropertyInteger("Netzbezug", 0); // Initialisierung mit 0 $this->RegisterPropertyInteger("Netzbezug", 0); // Initialisierung mit 0
$this->RegisterPropertyString("Verbraucher_Liste", "[]"); $this->RegisterPropertyString("Verbraucher_Liste", "[]");
$this->RegisterVariableString("Clients", "Clients", "", 0);
// Timer registrieren // Timer registrieren
$this->RegisterTimer("Timer_DistributeEnergy", 5000, "IPS_RequestAction(" .$this->InstanceID .', "DistributeEnergy", "");'); $this->RegisterTimer("Timer_DistributeEnergy", 5000, "IPS_RequestAction(" .$this->InstanceID .', "DistributeEnergy", "");');
@@ -86,25 +85,38 @@ class HauptManager extends IPSModule
public function AddClient($conn) 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(); $this->UpdateClientList();
} }
public function RemoveClient($conn) public function RemoveClient($conn)
{ {
$index = array_search($conn, $this->clients); $clients = json_decode($this->GetValue("Clients"), true);
if ($index !== false) { if ($clients !== null) {
unset($this->clients[$index]); $index = array_search((string)$conn->resourceId, $clients);
$this->clients = array_values($this->clients); // Reindizieren des Arrays if ($index !== false) {
$this->UpdateClientList(); unset($clients[$index]);
$clients = array_values($clients); // Reindizieren des Arrays
$this->SetValue("Clients", json_encode($clients));
$this->UpdateClientList();
}
} }
} }
private function UpdateClientList() private function UpdateClientList()
{ {
$clients = json_decode($this->GetValue("Clients"), true);
if ($clients === null) {
$clients = [];
}
$clientList = []; $clientList = [];
foreach ($this->clients as $client) { foreach ($clients as $client) {
$clientList[] = ['Client' => (string)$client->resourceId]; $clientList[] = ['Client' => $client];
} }
$this->UpdateFormField('ClientList', 'values', json_encode($clientList)); $this->UpdateFormField('ClientList', 'values', json_encode($clientList));
} }
+1 -1
View File
@@ -6,7 +6,7 @@
"compatibility": { "compatibility": {
"version": "7.1" "version": "7.1"
}, },
"version": "1.101", "version": "1.102",
"build": 0, "build": 0,
"date": 0 "date": 0
} }