예제 #1
0
     foreach ($Mapping['forceDP'] as $ident => $VarTyp) {
         if (@IPS_GetObjectIDByIdent($ident, $HMDevice) === false) {
             $VarId = IPS_CreateVariable($VarTyp);
             IPS_SetParent($VarId, $HMDevice);
             IPS_SetName($VarId, $ident);
             IPS_SetIdent($VarId, $ident);
         }
         HM_RequestStatus($HMDevice, $ident);
     }
 }
 $Childs = IPS_GetChildrenIDs($HMDevice);
 if (count($Childs) == 0) {
     echo "Gerät mit der Addresse " . (string) $Channel['Address'] . " hat keine Datenpunkte." . PHP_EOL;
     echo "  Gerät mit Namen '" . utf8_decode((string) $Channel['Name']) . "' wird wieder gelöscht." . PHP_EOL;
     echo "--------------------------------------------------------------------" . PHP_EOL;
     IPS_DeleteInstance($HMDevice);
     continue;
 }
 $DeviceHidden = true;
 foreach ($Childs as $Var) {
     $Obj = IPS_GetObject($Var);
     if (array_key_exists($Obj['ObjectIdent'], $Mapping)) {
         $Name = sprintf($Mapping[$Obj['ObjectIdent']]['Name Raum'], utf8_decode((string) $Channel['Name']), utf8_decode((string) $Channel->Room[0]['Name']));
         //				    $Name = 		$NameMappingRoom[$Obj['ObjectIdent']];
         IPS_SetName($Var, $Name);
         // Profil ändern, wenn nicht leer im Mapping
         if ($Mapping[$Obj['ObjectIdent']]['Profil'] != '') {
             if (!@IPS_SetVariableCustomProfile($Var, $Mapping[$Obj['ObjectIdent']]['Profil'])) {
                 echo "Fehler bei Gerät mit der Addresse " . (string) $Channel['Address'] . " und Datenpunkt " . $Obj['ObjectIdent'] . PHP_EOL;
                 echo "  Profil '" . $Mapping[$Obj['ObjectIdent']]['Profil'] . "' konnte nicht zugewiesen werden." . PHP_EOL;
                 echo "--------------------------------------------------------------------" . PHP_EOL;
 /**
  * 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;
 }
예제 #3
0
 protected function DeleteInstance($InsID)
 {
     //Prüfen ob Instanz existiert
     $InstanzID = @IPS_GetInstance($InsID);
     if ($InstanzID === false) {
         //echo "Instanz nicht gefunden!";
         //Instanz muss nicht gelöscht werden, existiert nicht.
         return $InsID;
     } else {
         //echo "Die Instanz-ID wurde gelöscht: ". $InstanzID;
         IPS_DeleteInstance($InsID);
         return $InstanzID;
     }
 }
 /**
  * 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;
 }