/** * constructor * * @throws Exception if $type is not valid * @access public */ public function __construct($parentId, $trigger, $type, $name, $debug = false) { if (!($type == self::tUPDATE || $type == self::tCHANGE || $type == self::tCAP || $type == self::tFLOOR || $type == self::tVALUE)) { throw new Exception("Parameter \$type must be a valid trigger event type, see ip symcon documentation"); } if ($type == self::tCAP || $type == self::tFLOOR || $type == self::tVALUE) { throw new Exception("Only TriggerEvents of type UPDATE and CHANGE are implemented yet."); } $this->parentId = $parentId; $this->trigger = $trigger; $this->type = $type; $this->name = $name; $this->debug = $debug; $this->id = @IPS_GetEventIDByName($this->name, $this->parentId); //check if event does already exist if ($this->id == false) { if ($this->debug) { echo "INFO - create IPS event {$name}\n"; } $this->id = IPS_CreateEvent(0); //create trigger event and store id IPS_SetName($this->id, $this->name); //set event name IPS_SetEventTrigger($this->id, $this->type, $this->trigger); //configure event trigger IPS_SetParent($this->id, $this->parentId); //move event to parent (this will be called when trigger occurs) IPS_SetInfo($this->id, "this event was created by script " . $_IPS['SELF'] . " which is part of the ips-library (https://github.com/florianprobst/ips-library)"); $this->activate(); } }
protected function CreateLink($Ident, $Name, $Target = 0) { if (!($LinkID = @IPS_GetObjectIdByIdent($Ident, $this->InstanceID))) { $LinkID = IPS_CreateLink(); IPS_SetName($LinkID, $Name); IPS_SetParent($LinkID, $this->InstanceID); IPS_SetIdent($LinkID, $Ident); if ($Target) { IPS_SetLinkTargetID($LinkID, $Target); $EventID = IPS_CreateEvent(0); IPS_SetParent($EventID, $this->InstanceID); // $LinkID); IPS_SetEventTrigger($EventID, 1, $Target); IPS_SetEventScript($EventID, 'PJ_UpdateColor($_IPS[\'TARGET\']);'); } } }
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 }
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); } } }
/** * @public * * Erzeugt ein Event für eine übergebene Variable, das den IPSMessageHandler beim Auslösen * aufruft. * * @param integer $variableId ID der auslösenden Variable * @param string $eventType Type des Events (OnUpdate oder OnChange) */ public static function CreateEvent($variableId, $eventType) { switch ($eventType) { case 'OnChange': $triggerType = 1; break; case 'OnUpdate': $triggerType = 0; break; default: throw new IPSMessageHandlerException('Found unknown EventType '.$eventType); } $eventName = $eventType.'_'.$variableId; $scriptId = IPS_GetObjectIDByIdent('IPSMessageHandler_Event', IPSUtil_ObjectIDByPath('Program.IPSLibrary.app.core.IPSMessageHandler')); $eventId = @IPS_GetObjectIDByIdent($eventName, $scriptId); if ($eventId === false) { $eventId = IPS_CreateEvent(0); IPS_SetName($eventId, $eventName); IPS_SetIdent($eventId, $eventName); IPS_SetEventTrigger($eventId, $triggerType, $variableId); IPS_SetParent($eventId, $scriptId); IPS_SetEventActive($eventId, true); IPSLogger_Dbg (__file__, 'Created IPSMessageHandler Event for Variable='.$variableId); } }
private function GenerateEvents() { $objectIds = explode(',',GetValue($this->objectIdsId)); $edipName = IPS_GetName($this->instanceId); foreach ($objectIds as $objectId) { $objectId = (int)$objectId; $objectData = IPS_GetObject($objectId); if ($objectData['ObjectType']==2) { $eventName = $edipName.'_'.IPS_GetName($objectId); $eventId = @IPS_GetEventIdByName($eventName ,EDIP_ID_EVENTSCRIPT); if ($eventId===false) { $eventId = IPS_CreateEvent(0); IPSLogger_Trc(__file__, "Create Event=$eventName, ID=$eventId, Parent=".EDIP_ID_EVENTSCRIPT); IPS_SetName($eventId, $eventName); IPS_SetEventTrigger($eventId, 1, $objectId); IPS_SetParent($eventId, EDIP_ID_EVENTSCRIPT); IPS_SetEventActive($eventId, true); } } } }