1
0
moha/hooks/scripts/rdc_portes_ouvertes.php

85 lines
2.2 KiB
PHP

<?php
require_once "events.php";
class alerte_intrusion extends hook
{
public $hookName = "alerte_intrusion";
public $active = true;
protected $devicelist = array(
ENTREE_PORTE => "contact",
GARAGE_PORTE => "contact",
RDC_CHAMBRE_BAIE => "contact",
RDC_SALON_BAIE => "contact",
GARAGE_PORTAIL => "contact",
ETAGE_SALON_FENETRE => "contact",
ETAGE_CUISINE_FENETRE => "contact",
ETAGE_PORTE_FENETRE => "contact"
);
function installHooks(&$indexDevices)
{
return $this->installHooksFunction($indexDevices);
}
// callback fonction. Is called with these 4 parameters
public function callBack($device, $property, $value)
{
logger(DEBUG, sprintf(_("property=%s, value=%s"), $property, $value), __FILE__ . ":" . __LINE__);
switch($property)
{
case "contact":
if ($value == false)
{
logger(ALERT, sprintf(_("%s vient de s'ouvrir alors que personne n'est présent"), $device->friendlyName), __FILE__ . ":" . __LINE__);
}else
{
logger(ALERT, sprintf(_("%s vient de se fermer alors que personne n'est présent"), $device->friendlyName), __FILE__ . ":" . __LINE__);
}
break;
}
}
public function testPortes($send=true, $opened=true) :array
{
global $indexDevices;
$portes = array();
logger(DEBUG, _("Function alerte_intrusion->testPorte"), __FILE__ . ":" . __LINE__);
$msg = "";
foreach ($this->devicelist as $device => $property)
{
if (!$opened)
{
if($indexDevices[$device]->properties[$property] == false)
{
$portes[] = $indexDevices[$device]->friendlyName;
$msg .= $indexDevices[$device]->friendlyName . "\n";
}
}else
{
if($indexDevices[$device]->properties[$property] == true)
{
$portes[] = $indexDevices[$device]->friendlyName;
$msg .= $indexDevices[$device]->friendlyName . "\n";
}
}
}
if ($send)
{
logger(ALERT, _("doors opened :") . $msg, null ,$device);
}
return $portes;
}
}
$hooks["alerte_intrusion"] = new alerte_intrusion();
logger(DEBUG, _("Initializing event"), __FILE__ . ":" . __LINE__);
$function = array($hooks["alerte_intrusion"], "testPortes");
setRecurrentEvent($function, 0, 0, 0, false, 0, 0, 21, 0, 0, 0, 0, 0, 0);
?>