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); } }
public function createGroupWithID($name, $id, $parentID) { $group = @IPS_GetObjectIDByIdent($id, $parentID); if (!$group) { $group = IPS_CreateCategory(); IPS_SetName($group, $name); IPS_SetParent($group, $parentID); IPS_SetIdent($group, $id); $variable = IPS_CreateVariable(0); IPS_SetParent($variable, $group); IPS_SetName($variable, "Turn on"); IPS_SetIdent($variable, "state_" . $id); SetValue($variable, true); $variable = IPS_CreateVariable(1); IPS_SetParent($variable, $group); IPS_SetName($variable, "Delay"); IPS_SetIdent($variable, "delay_" . $id); SetValue($variable, 3600); $childs = IPS_CreateCategory(); IPS_SetName($childs, "Links"); IPS_SetParent($childs, $group); IPS_SetIdent($childs, "childs_" . $id); } return $group; }
function CreateVariable($Name, $Type, $Value, $Ident = '', $ParentID = 0) { echo "CreateVariable: ( {$Name}, {$Type}, {$Value}, {$Ident}, {$ParentID} ) \n"; if ('' != $Ident) { $VarID = @IPS_GetObjectIDByIdent($Ident, $ParentID); if (false !== $VarID) { SetVariable($VarID, $Type, $Value); return; } } $VarID = @IPS_GetObjectIDByName($Name, $ParentID); if (false !== $VarID) { $Obj = IPS_GetObject($VarID); if (2 == $Obj['ObjectType']) { $Var = IPS_GetVariable($VarID); if ($Type == $Var['VariableValue']['ValueType']) { SetVariable($VarID, $Type, $Value); return; } } } $VarID = IPS_CreateVariable($Type); IPS_SetParent($VarID, $ParentID); IPS_SetName($VarID, $Name); if ('' != $Ident) { IPS_SetIdent($VarID, $Ident); } SetVariable($VarID, $Type, $Value); }
/** * @public * * Initialisierung eines IPSComponentShutter_FS20 Objektes * * @param integer $instanceId InstanceId des FS20 Devices */ public function __construct($instanceId) { $this->instanceId = IPSUtil_ObjectIDByPath($instanceId); $this->isRunningId = @IPS_GetObjectIDByIdent('isrunning', $this->instanceId); if($this->isRunningId===false) { $this->isRunningId = IPS_CreateVariable(0); IPS_SetParent($this->isRunningId, $this->instanceId); IPS_SetName($this->isRunningId, 'IsRunning'); IPS_SetIdent($this->isRunningId, 'isrunning'); IPS_SetInfo($this->isRunningId, "This Variable was created by Script IPSComponentShutter_FS20"); } }
/** * Create a new EnergyDev instance and set its properties * @param array $data parsed record * @param String $caps String semicolon seperated capabilities of this device * @return int new Instance ID */ private function CreateEnergyDevice($data, $caps) { $instID = 0; $Device = $data['Id']; $typ = $data['Typ']; $name = $data['Name']; $branch = $data['Branch']; unset($data['Branch']); if (!$name) { $name = "XS1 {$branch} {$Device}"; } $class = __CLASS__ . "-EN"; //$host = $this->GetHost(); $ModuleID = $this->module_interfaces['EnergyDev']; if (IPS_ModuleExists($ModuleID)) { //return $result; $this->debug(__FUNCTION__, 'Device:' . $Device); $instID = IPS_CreateInstance($ModuleID); if ($instID > 0) { IPS_SetProperty($instID, 'DeviceID', $Device); IPS_SetProperty($instID, 'Class', $class); IPS_SetProperty($instID, 'Typ', $typ); IPS_SetProperty($instID, 'CapList', $caps); IPS_SetProperty($instID, 'Debug', $this->isDebug()); //follow debug settings from splitter IPS_SetName($instID, "XS1 {$branch} '{$name}'"); $ident = $class . "_" . $branch . "_{$Device}"; $ident = preg_replace("/\\W/", "_", $ident); //nicht-Buchstaben/zahlen entfernen IPS_SetIdent($instID, $ident); IPS_ConnectInstance($instID, $this->InstanceID); IPS_ApplyChanges($instID); //set category $cat = $this->GetCategory() . " {$branch}" . "s"; $pcat = $this->GetParentCategory(); $ident = preg_replace("/\\W/", "_", $cat); //fix naming $catid = @IPS_GetObjectIDByIdent($ident, $pcat); if ($catid == 0) { $catid = IPS_CreateCategory(); IPS_SetName($catid, $cat); if (IPS_SetIdent($catid, $ident) && IPS_SetParent($catid, $pcat)) { IPS_LogMessage($class, "Category {$cat} Ident {$ident} ({$catid}) created"); } else { IPS_LogMessage($class, "Category {$cat} Ident {$ident} ({$catid}) FAILED"); } } $this->debug(__FUNCTION__, "Category:{$catid}"); if (!IPS_SetParent($instID, $catid)) { $this->debug(__FUNCTION__, "SetParent Instance {$instID} to Cat {$catid} failed, Dropping instance"); IPS_DeleteInstance($instID); $instID = 0; } else { $this->debug(__FUNCTION__, 'New ID:' . $instID); } //if instID } else { $this->debug(__FUNCTION__, 'Instance is not created!'); } } //module exists return $instID; }
protected function RegisterTimer($Name, $Interval, $Script) { $id = @IPS_GetObjectIDByIdent($Name, $this->InstanceID); if ($id === false) { $id = IPS_CreateEvent(1); IPS_SetParent($id, $this->InstanceID); IPS_SetIdent($id, $Name); } IPS_SetName($id, $Name); IPS_SetHidden($id, true); IPS_SetEventScript($id, $Script); if ($Interval > 0) { IPS_SetEventCyclic($id, 0, 0, 0, 0, 1, $Interval); IPS_SetEventActive($id, true); } else { IPS_SetEventCyclic($id, 0, 0, 0, 0, 1, 1); IPS_SetEventActive($id, false); } }
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\']);'); } } }
public function GenerateMediaObjectEx(string $Text, int $MediaID, string $Format, string $Codec, string $Language) { if ($MediaID == 0) { $MediaID = @IPS_GetObjectIDByIdent('Voice', $this->InstanceID); } if ($MediaID > 0) { if (IPS_MediaExists($MediaID) === false) { trigger_error('MediaObject not exists.', E_USER_NOTICE); } return false; if (IPS_GetMedia($MediaID)['MediaType'] != 2) { trigger_error('Wrong MediaType', E_USER_NOTICE); } return false; } $raw = $this->LoadTTSFile($Text, '', 0, $Format, $Codec, $Language, true); if ($raw === false) { return false; } if ($MediaID === false) { $MediaID = IPS_CreateMedia(2); IPS_SetMediaCached($MediaID, true); IPS_SetName($MediaID, 'Voice'); IPS_SetParent($MediaID, $this->InstanceID); IPS_SetIdent($MediaID, 'Voice'); } $Filename = 'media' . DIRECTORY_SEPARATOR . $MediaID . '.' . strtolower($Codec); IPS_SetMediaFile($MediaID, $Filename, False); IPS_SetMediaContent($MediaID, base64_encode($raw)); IPS_SetInfo($MediaID, $Text); return $MediaID; }
/** * 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; }
/** * 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); } }
/** * This function will be available automatically after the module is imported with the module control. * Using the custom prefix this function will be callable from PHP and JSON-RPC through: * * LJ_GenerateShutter($id, $Start, $End); * */ public function GenerateShutter($Start, $End) { $qid = @IPS_GetObjectIDByIdent("KNXQuick", 0); if($qid === false) { $qid = IPS_CreateCategory(); IPS_SetName($qid, "KNX quick"); IPS_SetIdent($qid, "KNXQuick"); } $sid = @IPS_GetObjectIDByIdent("Shutter", $qid); if($sid === false) { $sid = IPS_CreateCategory(); IPS_SetName($sid, "Shutter"); IPS_SetIdent($sid, "Shutter"); IPS_SetParent($sid, $qid); IPS_SetPosition($sid, 2); } for($i=$Start; $i<=$End; $i++) { for($j=0; $j<=9; $j++) { $iid = @IPS_GetObjectIDByIdent("Shutter".strtoupper(dechex($i).$j), $sid); if($iid === false) { $iid = IPS_CreateInstance("{24A9D68D-7B98-4D74-9BAE-3645D435A9EF}"); IPS_SetName($iid, "Shutter (Group ".strtoupper(dechex($i)).", Channel ".$j.")"); IPS_SetIdent($iid, "Shutter".strtoupper(dechex($i)).$j); IPS_SetParent($iid, $sid); IPS_SetProperty($iid, "GroupMoveAddress1", 14); IPS_SetProperty($iid, "GroupMoveAddress2", 0); IPS_SetProperty($iid, "GroupMoveAddress3", ($i*16)+$j); IPS_SetProperty($iid, "GroupStopAddress1", 14); IPS_SetProperty($iid, "GroupStopAddress2", 1); IPS_SetProperty($iid, "GroupStopAddress3", ($i*16)+$j); if($j > 0) { $mapping = Array(); $mapping[] = Array( "GroupAddress1" => 14, "GroupAddress2" => 0, "GroupAddress3" => $i*16 ); $mapping[] = Array( "GroupAddress1" => 14, "GroupAddress2" => 0, "GroupAddress3" => 240 ); $mapping[] = Array( "GroupAddress1" => 14, "GroupAddress2" => 0, "GroupAddress3" => 240+$j ); IPS_SetProperty($iid, "GroupMoveMapping", json_encode($mapping)); $mapping = Array(); $mapping[] = Array( "GroupAddress1" => 14, "GroupAddress2" => 1, "GroupAddress3" => $i*16 ); $mapping[] = Array( "GroupAddress1" => 14, "GroupAddress2" => 1, "GroupAddress3" => 240 ); $mapping[] = Array( "GroupAddress1" => 14, "GroupAddress2" => 1, "GroupAddress3" => 240+$j ); IPS_SetProperty($iid, "GroupStopMapping", json_encode($mapping)); } IPS_ApplyChanges($iid); } } } echo "Done."; }
function GetOrCreateScript($parent, $ident) { $ObjId = @IPS_GetObjectIDByIdent($ident, $parent); if ($ObjId === false) { $ObjId = IPS_CreateScript(0); IPS_SetParent($ObjId, $parent); IPS_SetIdent($ObjId, $ident); IPS_SetName($ObjId, $ident); IPS_SetScriptContent($ObjId, ScriptContent($ident)); } return $ObjId; }
protected function SetTimerByIdent_InSekunden($ident, $Sekunden) { $eid = @IPS_GetObjectIDByIdent($ident, $this->InstanceID); if ($eid === false) { $eid = IPS_CreateEvent(1); IPS_SetParent($eid, $this->InstanceID); IPS_SetName($eid, $ident); IPS_SetIdent($eid, $ident); IPS_SetEventScript($eid, 'HMON_Benachrichtigung($_IPS[\'TARGET\'], false, true);'); IPS_SetInfo($eid, "this timer was created by script #" . $_IPS['SELF']); } if ($Sekunden === false) { IPS_SetEventActive($eid, false); return $eid; } else { IPS_SetEventCyclicTimeFrom($eid, intval(date("H", time() + $Sekunden)), intval(date("i", time() + $Sekunden)), intval(date("s", time() + $Sekunden))); IPS_SetEventActive($eid, true); return $eid; } }
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); } } }
private function CreateVariableByIdent($id, $ident, $name, $type, $profile = "") { $vid = @IPS_GetObjectIDByIdent($ident, $id); if ($vid === false) { $vid = IPS_CreateVariable($type); IPS_SetParent($vid, $id); IPS_SetName($vid, $name); IPS_SetIdent($vid, $ident); if ($profile != "") { IPS_SetVariableCustomProfile($vid, $profile); } } return $vid; }
/** * Create a new EneryDev instance and set its properties * @param array $data parsed record * @param String $caps String semicolon seperated capabilities of this device * @return int new Instance ID */ private function CreateENDevice($data, $caps) { $instID = 0; $class = $data['Class']; $Device = $data['Id']; $typ = $data['Typ']; $ModuleID = $this->module_interfaces['EnergyDev']; if (IPS_ModuleExists($ModuleID)) { //return $result; $this->debug(__FUNCTION__, 'Device:' . $Device); $instID = IPS_CreateInstance($ModuleID); if ($instID > 0) { IPS_SetProperty($instID, 'DeviceID', $Device); IPS_SetProperty($instID, 'Class', $class); IPS_SetProperty($instID, 'Typ', $typ); IPS_SetProperty($instID, 'CapList', $caps); IPS_SetProperty($instID, 'Debug', $this->isDebug()); //follow debug settings from splitter IPS_SetName($instID, "{$typ} Device " . $Device); $ident = $class . "_" . $typ . "_" . $Device; $ident = preg_replace("/\\W/", "_", $ident); //nicht-Buchstaben/zahlen entfernen IPS_SetIdent($instID, $ident); IPS_ConnectInstance($instID, $this->InstanceID); IPS_ApplyChanges($instID); //set factor if (isset($data['CounterFactor'])) { IPS_SetProperty($instID, 'CounterFactor', floatval($data['CounterFactor'])); $this->debug(__FUNCTION__, 'Set Counterfactor=' . $data['CounterFactor']); } //set category $cat = $this->GetCategory(); $pcat = $this->GetParentCategory(); $ident = preg_replace("/\\W/", "_", $cat); //fix naming $catid = @IPS_GetObjectIDByIdent($ident, $pcat); if ($catid == 0) { $catid = IPS_CreateCategory(); IPS_SetName($catid, $cat); if (IPS_SetIdent($catid, $ident) && IPS_SetParent($catid, $pcat)) { IPS_LogMessage($class, "Category {$cat} Ident {$ident} ({$catid}) created"); } else { IPS_LogMessage($class, "Category {$cat} Ident {$ident} ({$catid}) FAILED"); } } $this->debug(__FUNCTION__, "Category:{$catid}"); if (!IPS_SetParent($instID, $catid)) { $this->debug(__FUNCTION__, "SetParent Instance {$instID} to Cat {$catid} failed, Dropping instance"); IPS_DeleteInstance($instID); $instID = 0; } else { $this->debug(__FUNCTION__, 'New ID:' . $instID); } //parent if (IPS_HasChanges($instID)) { IPS_ApplyChanges($instID); } } else { $this->debug(__FUNCTION__, 'Instance is not created!'); } //if instID } //module exists return $instID; }
/** * Create a new EnergyDev instance and set its properties * @param array $data parsed record * @param String $caps String semicolon seperated capabilities of this device * @return int new Instance ID */ private function CreateENDevice($data, $caps) { $instID = 0; $Device = $data['Id']; $typ = $data['Typ']; $ModuleID = $this->module_interfaces['EnergyDev']; if (IPS_ModuleExists($ModuleID)) { //return $result; $this->debug(__FUNCTION__, "Create Device {$Device},Type {$typ}"); $instID = IPS_CreateInstance($ModuleID); if ($instID > 0) { IPS_ConnectInstance($instID, $this->InstanceID); //Parents are ourself! IPS_SetProperty($instID, 'DeviceID', $Device); IPS_SetProperty($instID, 'Class', __CLASS__); IPS_SetProperty($instID, 'Typ', $typ); IPS_SetProperty($instID, 'CapList', $caps); IPS_SetProperty($instID, 'Debug', $this->isDebug()); //follow debug settings from splitter IPS_SetName($instID, "{$typ} ID {$Device}"); $ident = __CLASS__ . "_EN_{$Device}"; $ident = preg_replace("/\\W/", "_", $ident); //nicht-Buchstaben/zahlen entfernen IPS_SetIdent($instID, $ident); IPS_ApplyChanges($instID); $cat = $this->GetCategory(); $pcat = $this->GetParentCategory(); $ident = preg_replace("/\\W/", "_", $cat); //nicht-Buchstaben/zahlen entfernen $catid = @IPS_GetObjectIDByIdent($ident, $pcat); if ($catid == 0) { $catid = IPS_CreateCategory(); IPS_SetName($catid, $cat); if (IPS_SetIdent($catid, $ident) && IPS_SetParent($catid, $pcat)) { IPS_LogMessage(__CLASS__, "Category {$cat} Ident {$ident} ({$catid}) created"); } else { IPS_LogMessage(__CLASS__, "Category {$cat} Ident {$ident} ({$catid}) FAILED"); } } $this->debug(__FUNCTION__, "Category:{$catid}"); if (!IPS_SetParent($instID, $catid)) { $this->debug(__FUNCTION__, "SetParent to Cat {$catid} failed"); } $this->debug(__FUNCTION__, 'New ID:' . $instID); //if instID } else { $this->debug(__FUNCTION__, 'Instance is not created!'); } } //module exists return $instID; }
protected function RegisterTimer($Ident, $Milliseconds, $Action) { $id = @IPS_GetObjectIDByIdent($Ident, $this->InstanceID); if ($id === false) { $id = 0; } if ($id > 0) { if (!IPS_EventExists($id)) { throw new Exception("Ident with name " . $Ident . " is used for wrong object type"); } if (IPS_GetEvent($id)['EventType'] != 1) { IPS_DeleteEvent($id); $id = 0; } } if ($id == 0) { $id = IPS_CreateEvent(1); IPS_SetParent($id, $this->InstanceID); IPS_SetIdent($id, $Ident); } IPS_SetName($id, $Ident); IPS_SetHidden($id, true); IPS_SetEventScript($id, $Action); IPS_SetEventActive($id, false); }
private function CreateInstanceByIdent($id, $ident, $name, $moduleid = "{485D0419-BE97-4548-AA9C-C083EB82E61E}") { $iid = @IPS_GetObjectIDByIdent($ident, $id); if ($iid === false) { $iid = IPS_CreateInstance($moduleid); IPS_SetParent($iid, $id); IPS_SetName($iid, $name); IPS_SetIdent($iid, $ident); } return $iid; }
/** * @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); } }
protected function RegisterTimer($Name, $Interval, $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"); } if (IPS_GetEvent($id)['EventType'] != 1) { IPS_DeleteEvent($id); $id = 0; } } if ($id == 0) { $id = IPS_CreateEvent(1); IPS_SetParent($id, $this->InstanceID); IPS_SetIdent($id, $Name); } IPS_SetName($id, $Name); IPS_SetHidden($id, true); IPS_SetEventScript($id, $Script); if ($Interval > 0) { IPS_SetEventCyclic($id, 0, 0, 0, 0, 1, $Interval); IPS_SetEventActive($id, true); } else { IPS_SetEventCyclic($id, 0, 0, 0, 0, 1, 1); IPS_SetEventActive($id, false); } }
/** * Create a new WSDev instance and set its properties * @param array $data parsed record * @param String $caps String semicolon seperated capabilities of this device * @return int new Instance ID */ private function CreateWSDevice($data, $caps) { $instID = 0; $Device = $data['Id']; $typ = $data['Typ']; $ModuleID = $this->module_interfaces['WSDEV']; if (IPS_ModuleExists($ModuleID)) { //return $result; $this->debug(__FUNCTION__, "Create Device {$Device},Type {$typ}"); $instID = IPS_CreateInstance($ModuleID); if ($instID > 0) { IPS_ConnectInstance($instID, $this->InstanceID); //Parents are ourself! IPS_SetProperty($instID, 'DeviceID', $Device); IPS_SetProperty($instID, 'Class', __CLASS__); IPS_SetProperty($instID, 'Typ', $typ); IPS_SetProperty($instID, 'CapList', $caps); IPS_SetProperty($instID, 'Debug', $this->isDebug()); //follow debug settings from splitter switch ($Device) { case 0: case $Device < 8: IPS_SetName($instID, 'Sensor ' . $Device); break; case 8: IPS_SetName($instID, 'KombiSensor'); break; case 9: IPS_SetName($instID, 'InnenSensor'); break; default: IPS_SetName($instID, "unknown Sensor('" . strToHex($Device) . "')"); break; } //switch $ident = __CLASS__ . "_WS_{$Device}"; $ident = preg_replace("/\\W/", "_", $ident); //nicht-Buchstaben/zahlen entfernen IPS_SetIdent($instID, $ident); IPS_ApplyChanges($instID); $cat = $this->GetCategory(); $pcat = $this->GetParentCategory(); $ident = preg_replace("/\\W/", "_", $cat); //nicht-Buchstaben/zahlen entfernen $catid = @IPS_GetObjectIDByIdent($ident, $pcat); if ($catid == 0) { $catid = IPS_CreateCategory(); IPS_SetName($catid, $cat); if (IPS_SetIdent($catid, $ident) && IPS_SetParent($catid, $pcat)) { IPS_LogMessage(__CLASS__, "Category {$cat} Ident {$ident} ({$catid}) created"); } else { IPS_LogMessage(__CLASS__, "Category {$cat} Ident {$ident} ({$catid}) FAILED"); } } $this->debug(__FUNCTION__, "Category:{$catid}"); if (!IPS_SetParent($instID, $catid)) { $this->debug(__FUNCTION__, "SetParent to Cat {$catid} failed"); } $this->debug(__FUNCTION__, 'New ID:' . $instID); //if instID //set willi profile for forecast $vid = @IPS_GetObjectIDByIdent('Forecast', $instID); if ($vid > 0) { IPS_SetVariableCustomProfile($vid, "WS300_Willi"); } } else { $this->debug(__FUNCTION__, 'Instance is not created!'); } } //module exists return $instID; }