Ejemplo n.º 1
0
  protected function RegisterTimer($ident, $interval, $script) {
    $id = @IPS_GetObjectIDByIdent($ident, $this->InstanceID);

    if ($id && IPS_GetEvent($id)['EventType'] <> 1) {
      IPS_DeleteEvent($id);
      $id = 0;
    }

    if (!$id) {
      $id = IPS_CreateEvent(1);
      IPS_SetParent($id, $this->InstanceID);
      IPS_SetIdent($id, $ident);
    }

    IPS_SetName($id, $ident);
    IPS_SetHidden($id, true);
    IPS_SetEventScript($id, "\$id = \$_IPS['TARGET'];\n$script;");

    if (!IPS_EventExists($id)) throw new Exception("Ident with name $ident is used for wrong object type");

    if (!($interval > 0)) {
      IPS_SetEventCyclic($id, 0, 0, 0, 0, 1, 1);
      IPS_SetEventActive($id, false);
    } else {
      IPS_SetEventCyclic($id, 0, 0, 0, 0, 1, $interval);
      IPS_SetEventActive($id, true);
    }
  }
Ejemplo n.º 2
0
 protected function UnregisterTimer($Name)
 {
     $id = @IPS_GetObjectIDByIdent($Name, $this->InstanceID);
     if ($id > 0) {
         if (!IPS_EventExists($id)) {
             throw new Exception('Timer not present');
         }
         IPS_DeleteEvent($id);
     }
 }
 /**
  * delete
  * deletes this event
  *
  * @access public
  */
 public function delete()
 {
     return IPS_DeleteEvent($this->id);
 }
 /**
  * overloaded function to maintain variables and timer
  */
 protected function SetStatusVariables()
 {
     parent::SetStatusVariables();
     $caps = $this->GetCaps();
     if (count($caps) < 1) {
         return;
     }
     if (!isset($caps['Timer'])) {
         $tid = @IPS_GetEventIDByName("DeviceTimer", $this->InstanceID);
         if ($tid > 0) {
             IPS_LogMessage(__CLASS__, __FUNCTION__ . "Drop DeviceTimer ({$tid})");
             IPS_DeleteEvent($tid);
         }
     }
 }
Ejemplo n.º 5
0
 private function Registerevent121($var5_id, $TargetID)
 {
     if (!isset($_IPS)) {
         global $_IPS;
     }
     $EreignisID = @IPS_GetEventIDByName("E_TW", $TargetID);
     if ($EreignisID == true) {
         if (IPS_EventExists(IPS_GetEventIDByName("E_TW", $TargetID))) {
             IPS_DeleteEvent(IPS_GetEventIDByName("E_TW", $TargetID));
         }
     }
     $eid = IPS_CreateEvent(0);
     //Ausgelöstes Ereignis
     IPS_SetName($eid, "E_TW");
     IPS_SetEventTrigger($eid, 0, $var5_id);
     //Bei Änderung von Variable Wandtemp
     IPS_SetParent($eid, $TargetID);
     //Ereignis zuordnen
     IPS_SetEventScript($eid, 'SetValue($_IPS[\'TARGET\'], $_IPS[\'VALUE\']);');
     IPS_SetEventActive($eid, true);
     //Ereignis aktivieren
 }
Ejemplo n.º 6
0
 /**
  * ModBusMaster_WriteCoil
  * @param boolean $Value
  * @return boolean
  */
 public function WriteCoil($Value)
 {
     if ($this->ReadPropertyBoolean("ReadOnly")) {
         trigger_error("Address is marked as read-only!", E_USER_WARNING);
         return;
     }
     if ($this->ReadPropertyInteger("DataType") === 0) {
         $resultat = $this->SendDataToParent(json_encode(array("DataID" => "{A3419A88-C83B-49D7-8706-D3AFD596DFBB}", "FC" => "5", "Address" => $this->ReadPropertyInteger("Address"), "Data" => $Value)));
         if ($this->ReadPropertyInteger("SwitchDuration") > 0 and $Value) {
             $eid = @IPS_GetObjectIDByIdent("SwitchDuration", $this->InstanceID);
             if ($eid === false) {
                 $eid = 0;
             } else {
                 if (IPS_GetEvent($eid)['EventType'] != 1) {
                     IPS_DeleteEvent($eid);
                     $eid = 0;
                 }
             }
             if ($eid == 0) {
                 $eid = IPS_CreateEvent(1);
                 IPS_SetParent($eid, $this->InstanceID);
                 IPS_SetIdent($eid, "SwitchDuration");
                 IPS_SetName($eid, "SwitchDuration");
                 IPS_SetHidden($eid, true);
                 IPS_SetEventScript($eid, "ModBusMaster_WriteCoil(\$_IPS['TARGET'], false);IPS_SetEventActive(\$_IPS['EVENT'],false);");
             }
             IPS_SetEventCyclicTimeFrom($eid, date("H"), date("i"), date("s"));
             IPS_SetEventCyclic($eid, 0, 0, 0, 0, 1, $this->ReadPropertyInteger("SwitchDuration"));
             IPS_SetEventActive($eid, true);
         }
         return $resultat;
     } else {
         trigger_error("Invalid DataType!", E_USER_WARNING);
     }
 }
Ejemplo n.º 7
0
 protected function ManageCyclicEvent($ident, $interval, $script, $toggle)
 {
     $targetVariableId = @$this->GetIDForIdent($ident);
     if (!$toggle && $targetVariableId) {
         $deleteResult = IPS_DeleteEvent($targetVariableId);
         if ($deleteResult) {
             echo "Timer has been deleted. Ident/VariableId was: " . $ident . "/" . $targetVariableId;
         } else {
             echo "Could not delete Timer. Ident/VariableId was: " . $ident . "/" . $targetVariableId;
         }
     } elseif ($toggle && !$targetVariableId) {
         $this->RegisterTimer($ident, $interval, $script);
     } elseif (!$toggle && !$targetVariableId) {
         IPS_LogMessage("NzbGetModule", "Boolean was set to false and Timer Event did not exist yet.");
     } else {
         IPS_LogMessage("NzbGetModule", "Timer already exists ID/Ident: " . $targetVariableId . " / " . $ident);
     }
 }
 protected function RegisterEvent($Name, $Source, $Script)
 {
     $id = @IPS_GetObjectIDByIdent($Name, $this->InstanceID);
     if ($id === false) {
         $id = 0;
     }
     if ($id > 0) {
         if (!IPS_EventExists($id)) {
             throw new Exception("Ident with name " . $Name . " is used for wrong object type", E_USER_WARNING);
         }
         if (IPS_GetEvent($id)['EventType'] != 0) {
             IPS_DeleteEvent($id);
             $id = 0;
         }
     }
     if ($id == 0) {
         $id = IPS_CreateEvent(0);
         IPS_SetParent($id, $this->InstanceID);
         IPS_SetIdent($id, $Name);
     }
     IPS_SetName($id, $Name);
     IPS_SetHidden($id, true);
     IPS_SetEventScript($id, $Script);
     if ($Source > 0) {
         IPS_SetEventTrigger($id, 0, $Source);
         if (!IPS_GetEvent($id)['EventActive']) {
             IPS_SetEventActive($id, true);
         }
     } else {
         IPS_SetEventTrigger($id, 0, 0);
         if (IPS_GetEvent($id)['EventActive']) {
             IPS_SetEventActive($id, false);
         }
     }
 }
Ejemplo n.º 9
0
	function CreateTimer($date, $function, $scriptId_Refresh) {
		if (function_exists($function)) {
			IPSLogger_Dbg(__file__, 'Create Callback Timer '.$function.' for with ScriptId='.$scriptId_Refresh);
			if (@IPS_GetObjectIDByIdent($function, $scriptId_Refresh)!==false) {
			   IPS_DeleteEvent(IPS_GetObjectIDByIdent($function, $scriptId_Refresh));
			}
			CreateTimer_OnceADay ($function, $scriptId_Refresh, (int)date("H", $date), (int)date("i", $date));
		}
	}
Ejemplo n.º 10
0
		private function DropEvents() {
			$objectIds = explode(',',GetValue($this->objectIdsId));
			$edipName  = IPS_GetName($this->instanceId);
			foreach ($objectIds as $objectId) {
			   $objectId = (int)$objectId;
			   $eventName = $edipName.'_'.IPS_GetName($objectId);
				$eventId   = @IPS_GetEventIdByName($eventName ,EDIP_ID_EVENTSCRIPT);
				if ($eventId!==false) {
				   IPSLogger_Trc(__file__, "Drop Event=$eventName, ID=$eventId");
				   IPS_DeleteEvent($eventId);
				}
			}
		}
 /**
  * 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");
 }