/*
* This file is part of the IPSLibrary.
*
* The IPSLibrary is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* The IPSLibrary is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with the IPSLibrary. If not, see http://www.gnu.org/licenses/gpl.txt.
*/
/**@ingroup ipshomematic
* @{
*
* @file IPSHomematic_Manager.class.php
* @author Andreas Brauneis
* @version
* Version 2.50.1, 14.07.2012
*
*/
/**
* @class IPSHomematic_Manager
*
* Definiert ein IPSHomematic_Manager Objekt
*
* @author Andreas Brauneis
* @version
* Version 2.50.1, 15.07.2012
*/
class IPSHomematic_Manager {
/**
* @public
*
* Initializes the IPSHomematic_Manager
*/
public function __construct() {
}
/**
* @public
*
* Refreshed alle RSSI Variablen von der CCU
*/
public function RefreshRSSIValues() {
$instanceIdList = $this->GetMaintainanceInstanceList();
foreach ($instanceIdList as $instanceId) {
$variableId = @IPS_GetVariableIDByName('RSSI_DEVICE', $instanceId);
if ($variableId!==false) {
usleep(100000);
//set_time_limit(HM_TIMEOUT_REFRESH);
@HM_RequestStatus($instanceId, 'RSSI_DEVICE'); //bumaaas: @ ergänzt, da Fehlermeldung bei IP Geräten
}
$variableId = @IPS_GetVariableIDByName('RSSI_PEER', $instanceId);
if ($variableId!==false) {
usleep(100000);
//set_time_limit(HM_TIMEOUT_REFRESH);
IPSLogger_Dbg(__file__, 'ID ' . $instanceId . ': ' . IPS_GetLocation($instanceId)); // bma: eingefügt, da es schon mal auf dem nachfolgenden Stmt zu einer Warning kam: 'Warning: Waiting for response timed out'
@HM_RequestStatus($instanceId, 'RSSI_PEER'); //bma: @ ergänzt, da Fehlermeldung bei IP Geräten
}
}
}
/**
* @public
*
* Refreshed alle RSSI HTML Listen
*/
public function RefreshRSSIHtml() {
$instanceIdList = $this->GetMaintainanceInstanceList();
$rssiDeviceList = array();
$rssiPeerList = array();
foreach ($instanceIdList as $instanceId) {
$variableId = @IPS_GetVariableIDByName('RSSI_DEVICE', $instanceId);
if ($variableId!==false) {
$rssiValue = GetValue($variableId);
if ($rssiValue<>-65535) {
$rssiDeviceList[$instanceId] = $rssiValue;
}
}
}
arsort($rssiDeviceList, SORT_NATURAL);
foreach ($instanceIdList as $instanceId) {
$variableId = @IPS_GetVariableIDByName('RSSI_PEER', $instanceId);
if ($variableId!==false) {
$rssiValue = GetValue($variableId);
if ($rssiValue<>-65535) {
$rssiPeerList[$instanceId] = $rssiValue;
}
}
}
arsort($rssiPeerList, SORT_NATURAL);
$categoryIdHtml = IPSUtil_ObjectIDByPath('Program.IPSLibrary.data.hardware.IPSHomematic.StatusMessages');
$categoryIdSettings = IPSUtil_ObjectIDByPath('Program.IPSLibrary.data.hardware.IPSHomematic.Settings');
$variableIdRssi = IPS_GetObjectIDByIdent(HM_CONTROL_RSSI, $categoryIdHtml);
$variableIdRssiDevice = IPS_GetObjectIDByIdent(HM_CONTROL_RSSIDEVICE, $categoryIdHtml);
$variableIdRssiPeer = IPS_GetObjectIDByIdent(HM_CONTROL_RSSIPEER, $categoryIdHtml);
$str = "
";
$str .= "Gerätename | GeräteID | Empfangsstärke |
";
foreach($rssiDeviceList as $instanceId=>$value) {
$str .= "".IPS_GetName($instanceId)." | ".IPS_GetProperty($instanceId, 'Address')." | ".$value." |
";
}
$str .= "
";
SetValue($variableIdRssiDevice, $str);
$str = "";
$str .= "Gerätename | GeräteID | Empfangsstärke |
";
foreach($rssiPeerList as $instanceId=>$value) {
$str .= "".IPS_GetName($instanceId)." | ".IPS_GetProperty($instanceId, 'Address')." | ".$value." |
";
}
$str .= "
";
SetValue($variableIdRssiPeer, $str);
$str = "";
$str .= "Gerätename | GeräteID | Empfangsstärke |
";
$idx = 0;
foreach($rssiDeviceList as $instanceId=>$value) {
$idx++;
if ($idx<=10) {
$str .= "".IPS_GetName($instanceId)." | ".IPS_GetProperty($instanceId, 'Address')." | ".$value." |
";
}
}
$str .= "
";
SetValue($variableIdRssi, $str);
}
/**
* @public
*
* Refresh Variablen und HTML der Empfangsstärken
*/
public function RefreshRSSI() {
$this->RefreshRSSIValues();
$this->RefreshRSSIHtml();
}
/**
* @public
*
* Refresh aller Homematic Status Variablen (STATE und LEVEL)
*/
public function RefreshStatusVariables() {
$instanceIdList = IPS_GetInstanceListByModuleID("{EE4A81C6-5C90-4DB7-AD2F-F6BBD521412E}");
foreach ($instanceIdList as $instanceId) {
$variableId = @IPS_GetVariableIDByName('STATE', $instanceId);
if ($variableId!==false) {
//set_time_limit(HM_TIMEOUT_REFRESH);
HM_RequestStatus($instanceId, 'STATE');
}
//$variableId = @IPS_GetVariableIDByName('LEVEL', $instanceId);
//if ($variableId!==false) {
// HM_RequestStatus($instanceId, 'LEVEL');
//}
}
}
/**
* @public
*
* Refresh der Homematic Service Messages
*/
public function RefreshServiceMessages() {
$texte = Array("CONFIG_PENDING" =>"Konfigurationsdaten stehen zur Übertragung an",
"LOWBAT" =>"Batterieladezustand gering",
"STICKY_UNREACH" =>"Gerätekommunikation war gestört",
"UNREACH" =>"Gerätekommunikation aktuell gestört");
$str = ""; // Farbe anpassen oder style entfernen
$str .= "Gerätename | GeräteID | Meldung |
";
$str_log = "";
$ids = IPS_GetInstanceListByModuleID("{A151ECE9-D733-4FB9-AA15-7F7DD10C58AF}");
if(sizeof($ids) == 0) die("Keine HomeMatic Socket Instanz gefunden!");
IPSLogger_Dbg(__file__, 'ID ' . $ids[0] . ': ' . IPS_GetLocation($ids[0])); // bma: eingefügt, da es schon mal auf dem nachfolgenden Stmt zu einer Warning kam: 'Warning: Waiting for response timed out'
//set_time_limit(HM_TIMEOUT_REFRESH); // bma: eingefügt, da es zum TimeOut nach 5 sec kam.
$msgs = HM_ReadServiceMessages($ids[0]);
if($msgs === false) die("Verbindung zur CCU fehlgeschlagen");
if(sizeof($msgs) == 0) {
$str .= " Keine Servicemeldungen! |
";
$str_log .= "Keine Servicemeldungen!";
}
foreach($msgs as $msg) {
IPSLogger_Dbg(basename(__file__, '.class.php'), 'Message:'.json_encode($msg)); //bma: trace eingefügt
if(array_key_exists($msg['Message'], $texte)) {
$text = $texte[$msg['Message']];
} else {
$text = $msg['Message'];
}
$id = HM_GetInstanceIDFromHMAddress($msg['Address']);
if(IPS_InstanceExists($id)) {
//$name = IPS_GetLocation($id);
$name = IPS_GetName($id); //bma: statt Pfad und Name wird nur der Name angezeigt
} else {
$name = "Gerät nicht in IP-Symcon eingerichtet";
}
$str .= "".$name." | ".$msg['Address']." | ".$text." |
";
$str_log .= $name." - ".$msg['Address']." - ".$text."\n";
}
$str .= "
";
$categoryIdHtml = IPSUtil_ObjectIDByPath('Program.IPSLibrary.data.hardware.IPSHomematic.StatusMessages');
$categoryIdSettings = IPSUtil_ObjectIDByPath('Program.IPSLibrary.data.hardware.IPSHomematic.Settings');
$variableIdMessages = IPS_GetObjectIDByIdent(HM_CONTROL_MESSAGES, $categoryIdHtml);
$variableIdPriority = IPS_GetObjectIDByIdent(HM_CONTROL_PRIORITY, $categoryIdSettings);
if (GetValue($variableIdMessages) <> $str) {
SetValue($variableIdMessages, $str);
IPSLogger_Not(basename(__file__, '.class.php'), 'New Homematic Service Messages:'.PHP_EOL.$str_log, GetValue($variableIdPriority)); //bma: basename eingefügt
}
}
/**
* @public
*
* Reset der Homematic Service Messages
*/
public function ResetServiceMessages() {
$homematicIntanceIdList = IPS_GetInstanceListByModuleID("{A151ECE9-D733-4FB9-AA15-7F7DD10C58AF}");
if(sizeof($homematicIntanceIdList) == 0) die("Keine HomeMatic Socket Instanz gefunden!");
$CCUIPAddress = IPS_GetProperty($homematicIntanceIdList[0], 'Host');
$HM_Script = "
string itemID;
string address;
object aldp_obj;
foreach(itemID, dom.GetObject(ID_DEVICES).EnumUsedIDs())
{
address = dom.GetObject(itemID).Address();
aldp_obj = dom.GetObject('AL-' # address # ':0.STICKY_UNREACH');
if (aldp_obj)
{
if (aldp_obj.Value())
{
aldp_obj.AlReceipt();
! dom.GetObject('Kommunikationsstörung').State(dom.GetObject(itemID).Name());
}
}
}";
// Initialisieren der Socket-Verbindung
$fp = fsockopen ($CCUIPAddress, 8181, $errno, $errstr, 2);
$res = "";
if (!$fp) {
$res = "$errstr ($errno)
\n";
} else {
// Zusammenstellen des Header für HTTP-Post
fputs($fp, "POST /Test.exe HTTP/1.1\r\n");
fputs($fp, "Content-type: application/x-www-form-urlencoded\r\n");
fputs($fp, "Content-length: ". strlen($HM_Script) ."\r\n");
fputs($fp, "Connection: close\r\n\r\n");
fputs($fp, $HM_Script);
while(!feof($fp)) {
$res .= fgets($fp, 500);
}
fclose($fp);
}
return $res;
}
/**
* @public
*
* Liefert alle Homematic Maintainmance Instance IDs, die in der Konfiguration eingetragen sind
*
* @return array[int] Homematic Instance IDs
*/
public function GetMaintainanceInstanceList() {
$homematicInstanceList = IPS_GetInstanceListByModuleID("{EE4A81C6-5C90-4DB7-AD2F-F6BBD521412E}");
$homematicAddressList = array();
$homematicMaintainanceList = array();
foreach ($homematicInstanceList as $homematicInstanceId ) {
$homematicAddress = IPS_GetProperty($homematicInstanceId,'Address');
$homematicAddressList[$homematicAddress] = $homematicInstanceId;
$pos = strpos($homematicAddress, ':0');
if ($pos !== false) {
$homematicMaintainanceList[$homematicInstanceId] = $homematicInstanceId;
}
}
return $homematicMaintainanceList;
}
}
/** @}*/
?>