1
0

Merge branch 'master' of git.labolyon.fr:DTux/moha

This commit is contained in:
2022-07-30 22:08:21 +02:00
14 changed files with 182 additions and 66 deletions

View File

@ -5,8 +5,11 @@ class notificationFreemobile
private $name = "freemobile";
public $active = true;
public $level;
private $dest = array(
"daniel" => "32886706&pass=JTGUY6l5OG73zX",
public $curlErr;
public $lastTry;
public $lastTryTimeout = 5;
protected $dest = array(
"daniel" => "15480189&pass=yVpPmCWmUl2HGp",
);
function __construct()
@ -16,37 +19,50 @@ class notificationFreemobile
function send($message, $destinataire=NOTIF_DEFAULT_DEST)
{
global $curlErr;
$result = false;
$error = false;
if ($this->active === true)
{
$ch = curl_init();
// set url
curl_setopt($ch, CURLOPT_URL, $this->url . $this->dest[$destinataire] . "&msg=" . urlencode(trim($message)));
echo $this->url . urlencode(trim($message)) . EOL;
//return the transfer as a string
//curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// $result contains the output string
if ($curlErr <= 10)
if ($this->curlErr <= 5)
{
$result = curl_exec($ch);
if ($result === false)
logger(DEBUG, _("Curl sending message"), false, __FILE__ . ":" . __LINE__);
echo $this->url . urlencode(trim($message)) . EOL;
curl_exec($ch);
if (curl_errno($ch) != 0)
{
$curlErr += 1;
$this->curlErr += 1;
$this->lastTry = time();
logger(ERROR, sprintf( _("Curl return error %d: %s when sending notification"), curl_errno($ch), curl_error($ch)), false, __FILE__ . ":" . __LINE__);
$error = true;
}else
{
logger(DEBUG, sprintf(_("Curl return: %s when sending notification"), $result), false);
logger(DEBUG, sprintf(_("Curl return: %s when sending notification"), $result), false, __FILE__ . ":" . __LINE__);
$this->curlErr = 0;
}
} //TODO managing curl errors
}else
{
if ((time() - $this->lastTry) > ($this->lastTryTimeout*60))
{
$this->curlErr -= 1;
}
$error = true;
}
//TODO managing curl errors
// close curl resource to free up system resources
curl_close($ch);
return true;
}
return false;
return $error;
}
}
$notificationMethods["freemobile"] = new notificationFreemobile();
?>

View File

@ -1,4 +1,6 @@
<?php
require_once "events.php";
class alerte_intrusion extends hook
{
public $hookName = "alerte_intrusion";
@ -27,24 +29,30 @@ class alerte_intrusion extends hook
}
}
public function test()
public function testPortes()
{
global $indexDevices;
logger(DEBUG, _("Function alerte_intrusion->testPorte"), __FILE__ . ":" . __LINE__);
$msg = "";
foreach ($this->devicelist as $device => $property)
{
if($indexDevices[$device]->properties[$property] != false)
{
$msg .= $indexDevices->friendlyName . " is open" . EOL;
$msg .= $indexDevices[$device]->friendlyName . " is open" . EOL;
}
}
if ($msg != "")
if (!empty($msg))
{
logger(ALERT, $msg, __FILE__ . ":" . __LINE__);
}
return nl2br($msg);
}
}
$hooks["alerte_intrusion"] = new alerte_intrusion();
logger(DEBUG, _("Initializing event"), __FILE__ . ":" . __LINE__);
$function = array($hooks["alerte_intrusion"], "testPortes");
setRecurrentEvent($function, 0, 0, 0, 0, 0, 0, 21, 0, 0, 1, 0, 0, 0);
?>

View File

@ -237,7 +237,7 @@ class rdc_store extends hook
}
}
private function send($level)
private function send($level, $method)
{
global $indexDevices;
$deviceObject = $indexDevices[RDC_STORE];

View File

@ -31,16 +31,16 @@ class rdc_wc_eclairage extends hook
if ($targetDevice->properties["state_l2"]["method"] == IDLE)
{
$targetDevice->properties["state_l2"]["method"] = MANUAL;
setDelay($device, $this->delayManual, $this->timeUnit, "state_l2", "OFF", true);
setDelay($targetDevice, $this->delayManual, $this->timeUnit, "state_l2", "OFF", true);
}
}elseif ($value == "OFF")
{
$targetDevice->properties["state_l2"]["method"] = IDLE;
removeEvent($device, "state_l2", "OFF");
removeEvent($targetDevice, "state_l2", "OFF");
}
break;
case "occupancy":
logger(DEBUG, "CASE: occupancy", __FILE__ . ":" . __LINE__);
logger(DEBUG, "CASE: WC occupancy", __FILE__ . ":" . __LINE__);
logger(DEBUG, "method =" . $targetDevice->properties["state_l2"]["method"], __FILE__ . ":" . __LINE__);
if ($value === true and $targetDevice->properties["state_l2"]["method"] == IDLE)
{
@ -50,7 +50,7 @@ class rdc_wc_eclairage extends hook
{
//$targetDevice->properties["state_l2"]["method"] = IDLE;
//$this->send($targetDevice, "OFF");
setDelay($device, $this->delay, $this->timeUnit, "state_l2", "OFF", true, IDLE);
setDelay($targetDevice, $this->delay, $this->timeUnit, "state_l2", "OFF", true, IDLE);
}
}
logger (INFO, sprintf(_("%s: notification received from MQTT from %s => parameter: %s value: %s"), $this->hookName, $device->friendlyName, $property, bool2string($value)), __FILE__ . ":" . __LINE__);