/** * Startet den Timer bis zum Alarm * * @access private */ private function StartTimer() { if (IPS_GetKernelRunlevel() != KR_READY) { return; } $this->ActiveVarID = 0; $NowTime = time(); $LastTime = $NowTime + 98765; //init wert damit lasttime immer größer als aktuelle zeit $TriggerVarList = $this->NoTriggerVarList; foreach ($TriggerVarList->Items as $i => $IPSVars) { if (!IPS_VariableExists($IPSVars->VarId)) { continue; } if ($IPSVars->Alert === true) { continue; } $Variable = IPS_GetVariable($IPSVars->VarId); $TestTime = $Variable['VariableUpdated']; if ($TestTime + $this->ReadPropertyInteger('Timer') < $NowTime) { $TriggerVarList->Items[$i]->Alert = true; $this->Alerts++; if ($this->Alerts == 1) { $this->SetStateVar(true, $IPSVars->VarId); $this->DoScript($IPSVars->VarId, true, false); } else { if ($this->ReadPropertyBoolean('MultipleAlert')) { $this->DoScript($IPSVars->VarId, true, false); } } continue; } else { if ($TestTime < $LastTime) { $LastTime = $TestTime; $this->ActiveVarID = $IPSVars->VarId; } } } $this->NoTriggerVarList = $TriggerVarList; if ($this->ActiveVarID == 0) { IPS_LogMessage('NoTrigger', 'Keine Var mehr in Ruhe. Überwachung pausiert'); $this->StopTimer(); } else { $TargetTime = $LastTime + $this->ReadPropertyInteger('Timer'); $DiffTime = $TargetTime - $NowTime; $this->SetTimerInterval('NoTrigger', $DiffTime * 1000); } }
protected function UnregisterVariable($Name) { $id = @IPS_GetObjectIDByIdent($Name, $this->InstanceID); if ($id > 0) { if (!IPS_VariableExists($id)) { throw new Exception('Variable not present', E_USER_NOTICE); } IPS_DeleteVariable($id); } }
/** * RegisterVariableByParent * @param integer $ParentID * @param string $Ident * @param string $Name * @param integer $Type * @param string $Profile * @param integer $Position * @return integer */ private function RegisterVariableByParent($ParentID, $Ident, $Name, $Type, $Profile = "", $Position = 0) { if ($Profile !== "") { //prefer system profiles if (IPS_VariableProfileExists("~" . $Profile)) { $Profile = "~" . $Profile; } if (!IPS_VariableProfileExists($Profile)) { throw new Exception("Profile with name " . $Profile . " does not exist"); } } //search for already available variables with proper ident $vid = @IPS_GetObjectIDByIdent($Ident, $ParentID); //properly update variableID if ($vid === false) { $vid = 0; } //we have a variable with the proper ident. check if it fits if ($vid > 0) { //check if we really have a variable if (!IPS_VariableExists($vid)) { throw new Exception("Ident with name " . $Ident . " is used for wrong object type"); } //bail out //check for type mismatch if (IPS_GetVariable($vid)["VariableType"] != $Type) { //mismatch detected. delete this one. we will create a new below IPS_DeleteVariable($vid); //this will ensure, that a new one is created $vid = 0; } } //we need to create one if ($vid === 0) { $vid = IPS_CreateVariable($Type); //configure it IPS_SetParent($vid, $ParentID); IPS_SetIdent($vid, $Ident); IPS_SetName($vid, $Name); IPS_SetPosition($vid, $Position); //IPS_SetReadOnly($vid, true); } //update variable profile. profiles may be changed in module development. //this update does not affect any custom profile choices IPS_SetVariableCustomProfile($vid, $Profile); return $vid; }
/** * Startet den Timer bis zum Alarm * * @access private */ private function StartTimer() { if (IPS_GetKernelRunlevel() != KR_READY) { return; } $NowTime = time(); if (!IPS_VariableExists($this->ReadPropertyInteger('VarID'))) { IPS_SetProperty($this->InstanceID, 'VarID', 0); IPS_ApplyChanges($this->InstanceID); return; } $Variable = IPS_GetVariable($this->ReadPropertyInteger('VarID')); $LastTime = $Variable['VariableUpdated']; $TargetTime = $LastTime + $this->ReadPropertyInteger('Timer'); $DiffTime = $TargetTime - $NowTime; if ($TargetTime < $NowTime) { $this->SetStateVar(true); $this->DoScript($this->ReadPropertyInteger('VarID'), true, $this->State); $this->State = true; if ($this->ReadPropertyBoolean('MultipleAlert') == false) { $this->StopTimer(); } else { $this->SetTimerInterval('NoTrigger', $this->ReadPropertyInteger('Timer') * 1000); } // neuer Timer mit max. Zeit, ohne now zu berücksichtigen. } else { $this->SetStateVar(false); if ($this->State) { $this->DoScript($this->ReadPropertyInteger('VarID'), false, $this->State); $this->State = false; } $this->SetTimerInterval('NoTrigger', $DiffTime * 1000); } }
/** * Setzt die Status-Variable. * * @access protected * @param bool $NewState Der neue Wert der Statusvariable */ protected function SetStateVar(boole $NewState) { if ($this->ReadPropertyBoolean('HasState')) { if (!IPS_VariableExists(@$this->GetIDForIdent('STATE'))) { $this->MaintainVariable('STATE', 'STATE', vtBoolean, '~Alert', 0, true); } SetValueBoolean($this->GetIDForIdent('STATE'), $NewState); } }
/** * Delete a Variable by name if exists and assigned events * @param String $ident */ protected function drop_var($ident) { //use logmessages instead of debug because this isnt available in early stage //IPS_LogMessage($this->name, __FUNCTION__ . "(#".$this->InstanceID.") Drop Var $ident"); $vid = @$this->GetIDForIdent($ident); if ($vid > 0 && IPS_VariableExists($vid)) { $events = IPS_GetVariableEventList($vid); foreach ($events as $ev) { @IPS_DeleteEvent($ev); } @IPS_DeleteVariable($vid); return; } IPS_LogMessage($this->name, __FUNCTION__ . "(#" . $this->InstanceID . ") Error Variable {$ident} not found"); }