예제 #1
0
파일: orga.php 프로젝트: Spoosie/KH_UniFi
function CreateCategory($Name, $Ident = '', $ParentID = 0)
{
    global $RootCategoryID;
    echo "CreateCategory: ( {$Name}, {$Ident}, {$ParentID} ) \n";
    if ('' != $Ident) {
        $CatID = @IPS_GetObjectIDByIdent($Ident, $ParentID);
        if (false !== $CatID) {
            $Obj = IPS_GetObject($CatID);
            if (0 == $Obj['ObjectType']) {
                // is category?
                return $CatID;
            }
        }
    }
    $CatID = IPS_CreateCategory();
    IPS_SetName($CatID, $Name);
    IPS_SetIdent($CatID, $Ident);
    if (0 == $ParentID) {
        if (IPS_ObjectExists($RootCategoryID)) {
            $ParentID = $RootCategoryID;
        }
    }
    IPS_SetParent($CatID, $ParentID);
    return $CatID;
}
예제 #2
0
 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;
 }
예제 #3
0
 private function CreateCategoryByIdent($id, $ident, $name)
 {
     $cid = @IPS_GetObjectIDByIdent($ident, $id);
     if ($cid === false) {
         $cid = IPS_CreateCategory();
         IPS_SetParent($cid, $id);
         IPS_SetName($cid, $name);
         IPS_SetIdent($cid, $ident);
     }
     return $cid;
 }
예제 #4
0
function GetOrCreateCategoryByName($Parent, $Name)
{
    $ObjID = @IPS_GetObjectIDByName($Name, $Parent);
    if ($ObjID == 0) {
        $ObjID = IPS_CreateCategory();
        IPS_SetParent($ObjID, $Parent);
        IPS_SetName($ObjID, $Name);
    }
    return $ObjID;
}
예제 #5
0
 protected function CreateCategory($CategoryName)
 {
     $ImportCategoryID = $this->ReadPropertyInteger('ImportCategoryID');
     $CatID = IPS_CreateCategory();
     // Kategorie anlegen
     $CategoryName = (string) $CategoryName;
     IPS_SetName($CatID, $CategoryName);
     // Kategorie benennen
     IPS_SetParent($CatID, $ImportCategoryID);
     // Kategorie einsortieren unter dem Objekt mit der ID "$ImportCategoryID"
     return $CatID;
 }
 /**
  * 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;
 }
 /**
  * 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;
 }
 /**
  * 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;
 }
예제 #9
0
 protected function CreateCategoryIfNotAvailable($categoryName, $parent, $ident)
 {
     if (!@IPS_GetObjectIDByIdent($ident, $parent)) {
         $catId = IPS_CreateCategory();
         IPS_SetName($catId, $categoryName);
         IPS_SetParent($catId, $parent);
         IPS_SetIdent($catId, $ident);
         return $catId;
     } else {
         return IPS_GetObjectIDByIdent($ident, $parent);
     }
 }
 /**
  * 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;
 }
예제 #11
0
파일: module.php 프로젝트: symcon/SymconLJ
		/**
		* 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.";
			
		}		
예제 #12
0
function Kategorie_GetOrSet($Kategorie_Name, $ParentID)
{
    $Kategorie_ID = @IPS_GetCategoryIDByName($Kategorie_Name, $ParentID);
    if ($Kategorie_ID === false) {
        $Kategorie_ID = IPS_CreateCategory();
        IPS_SetName($Kategorie_ID, $Kategorie_Name);
        IPS_SetParent($Kategorie_ID, $ParentID);
    }
    return $Kategorie_ID;
}
예제 #13
0
 private function CreateKategorie($Name, $Parent)
 {
     if ($Parent == 0 or $Parent == false) {
         return false;
     }
     $id = @IPS_GetCategoryIDByName($Name, $Parent);
     if ($id === false) {
     } else {
         return $id;
     }
     $id = IPS_CreateCategory();
     if ($id === false) {
         return false;
     }
     IPS_SetParent($id, $Parent);
     IPS_SetName($id, $Name);
     return $id;
 }