/** * 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; }
public function ProcessData() { $error = false; $Content = ""; //CommandList processing $CommandListString = ""; if ($this->Debug) { echo "working on CommandList..."; } foreach ($this->CommandList as $key => $value) { $temp = implode("#=#", $value); if (strlen($CommandListString) > 0) { $CommandListString = $CommandListString . "#+#" . $key . "#-#" . $temp; } else { $CommandListString = $key . "#-#" . $temp; } if (!isset($this->FeedbackList[$key])) { echo "Error, missing Feedback entry for Command '" . $key . "'\n"; $error = true; } if (!isset($this->ExampleList[$key])) { echo "Error, missing Example entry for Command '" . $key . "'\n"; $error = true; } } //echo "CommandListString:".$CommandListString."\n"; if ($this->Debug) { echo "processed!\n"; } //FeedbackList processiong $FeedbackListString = ""; if ($this->Debug) { echo "working on FeedbackList..."; } foreach ($this->FeedbackList as $key => $value) { if (strlen($FeedbackListString) > 0) { $FeedbackListString = $FeedbackListString . "#+#" . $key . "#-#" . $value; } else { $FeedbackListString = $key . "#-#" . $value; } } if ($this->Debug) { echo "...processed!\n"; } //ExampleList processiong $ExampleListString = ""; if ($this->Debug) { echo "working on ExampleListString..."; } foreach ($this->ExampleList as $key => $value) { if (strlen($ExampleListString) > 0) { $ExampleListString = $ExampleListString . "#+#" . $key . "#-#" . $value; } else { $ExampleListString = $key . "#-#" . $value; } } if ($this->Debug) { echo "processed!\n"; } //PhraseList processing $PhraseListString = ""; if ($this->Debug) { echo "working on PhraseList..."; } foreach ($this->PhraseList as $key => $value) { $temp = implode("#=#", $value); if (strlen($PhraseListString) > 0) { $PhraseListString = $PhraseListString . "#+#" . $key . "#-#" . $temp; } else { $PhraseListString = $key . "#-#" . $temp; } } if ($this->Debug) { echo "processed!\n"; } if ($error) { SetValueString($this->id, ""); echo "Error while processing data - nothing written!\n"; } else { $Content = $CommandListString . "#*#" . $FeedbackListString . "#*#" . $ExampleListString . "#*#" . $PhraseListString; $Content = $this->convertForOutput($Content); SetValueString($this->InstanceID, $Content); echo "Data successful written\n"; if (IPS_ModuleExists("{44D8BE09-743E-484F-A64D-154C4235BE94}")) { ips4WNS_sendRawNotification(0, null, "ips4Windows#CortanaRefresh"); } } }
/** * 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; }
/** * 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; }