clients in varibale genommen
This commit is contained in:
+22
-10
@@ -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
@@ -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
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user