OKich habe das jetzt mal umgeschrieben und eine ID mitgegeben, bekomme aber weiterhin die Meldung. Die Hooks der nicht gelöschten Instanzen bleiben aber wie gewünscht erhalten
Register Hook
PHP-Code:
private function RegisterHook($WebHook) {
$ids = IPS_GetInstanceListByModuleID("{015A6EB8-D6E5-4B93-B496-0D3F77AE9FE1}");
if(sizeof($ids) > 0) {
$hooks = json_decode(IPS_GetProperty($ids[0], "Hooks"), true);
$found = false;
foreach($hooks as $index => $hook) {
if($hook['Hook'] == $WebHook) {
if($hook['TargetID'] == $this->InstanceID)
return;
$hooks[$index]['TargetID'] = $this->InstanceID;
$found = true;
}
}
if(!$found) {
$hooks[] = Array("Hook" => $WebHook, "TargetID" => $this->InstanceID);
}
IPS_SetProperty($ids[0], "Hooks", json_encode($hooks));
IPS_ApplyChanges($ids[0]);
}
}
Aufruf mit
PHP-Code:
public function ApplyChanges() {
//Never delete this line!
parent::ApplyChanges();
if(IPS_GetKernelRunlevel() == KR_READY) {
$this->RegisterHook("/hook/waffi_" . $this->InstanceID);
}
}
UnRegister Hook (von Dir abgeguckt Nall Chan)
PHP-Code:
protected function UnregisterHook($WebHook) {
$ids = IPS_GetInstanceListByModuleID("{015A6EB8-D6E5-4B93-B496-0D3F77AE9FE1}");
if (sizeof($ids) > 0) {
$hooks = json_decode(IPS_GetProperty($ids[0], "Hooks"), true);
$found = false;
foreach ($hooks as $index => $hook) {
if ($hook['Hook'] == $WebHook) {
$found = $index;
break;
}
}
if ($found !== false) {
array_splice($hooks, $index, 1);
IPS_SetProperty($ids[0], "Hooks", json_encode($hooks));
IPS_ApplyChanges($ids[0]);
}
}
}
Hier im Destroy
PHP-Code:
public function Destroy() {
if (!IPS_InstanceExists($this->InstanceID)) {
$this->UnregisterHook("/hook/waffi_" . $this->InstanceID);
}
parent::Destroy();
}