/**
  * 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;
 }
Пример #2
0
function GetOrCreateHMDevice($Parent, $Name, $Address, $Protocol, $HMParent)
{
    $ObjID = IPS_CreateInstance("{EE4A81C6-5C90-4DB7-AD2F-F6BBD521412E}");
    if (IPS_GetInstance($ObjID)['ConnectionID'] != $HMParent) {
        IPS_DisconnectInstance($ObjID);
        IPS_ConnectInstance($ObjID, $HMParent);
    }
    IPS_SetParent($ObjID, $Parent);
    IPS_SetName($ObjID, $Name);
    IPS_SetProperty($ObjID, 'Address', $Address);
    IPS_SetProperty($ObjID, 'Protocol', $Protocol);
    IPS_SetProperty($ObjID, 'EmulateStatus', false);
    usleep(50000);
    @IPS_ApplyChanges($ObjID);
    /* 	 {
         echo "Error beim Erzeugen von Gerät ".$Address.PHP_EOL;
         //	 echo "  Gerät mit Namen ".$Name." wird wieder gelöscht.".PHP_EOL;
         //	 IPS_DeleteInstance($ObjID);
         //	 return false;
         } */
    return $ObjID;
}
 /**
  * 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;
 }
Пример #4
0
 protected function RequireParent($ModuleID, $Name = '')
 {
     $instance = IPS_GetInstance($this->InstanceID);
     if ($instance['ConnectionID'] == 0) {
         $parentID = IPS_CreateInstance($ModuleID);
         $instance = IPS_GetInstance($parentID);
         if ($Name == '') {
             IPS_SetName($parentID, $instance['ModuleInfo']['ModuleName']);
         } else {
             IPS_SetName($parentID, $Name);
         }
         IPS_ConnectInstance($this->InstanceID, $parentID);
     }
 }
 /**
  * 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;
 }
Пример #6
0
  public function SyncDevices() {
    $lightsCategoryId = $this->GetLightsCategory();

    $lights = $this->Request('/lights');
    foreach ($lights as $lightId => $light) {
      $name = utf8_decode((string)$light->name);
      $uniqueId = (string)$light->uniqueid;
      echo "$lightId. $name ($uniqueId)\n";

      $deviceId = $this->GetDeviceByUniqueId($uniqueId);

      if ($deviceId == 0) {
        $deviceId = IPS_CreateInstance($this->DeviceGuid());
        IPS_SetProperty($deviceId, 'UniqueId', $uniqueId);
      }

      IPS_SetParent($deviceId, $lightsCategoryId);
      IPS_SetProperty($deviceId, 'LightId', (integer)$lightId);
      IPS_SetName($deviceId, $name);

      // Verbinde Light mit Bridge
      if (IPS_GetInstance($deviceId)['ConnectionID'] <> $this->InstanceID) {
        @IPS_DisconnectInstance($deviceId);
        IPS_ConnectInstance($deviceId, $this->InstanceID);
      }

      IPS_ApplyChanges($deviceId);
      HUE_RequestData($deviceId);
    }
  }
 /**
  * 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;
 }