1
0
moha/hooks/scripts/rdc_portes_ouvertes.php

93 lines
2.6 KiB
PHP
Raw Permalink Normal View History

2022-01-06 13:03:26 +01:00
<?php
require_once "events.php";
2022-01-17 00:18:50 +01:00
class alerte_intrusion extends hook
2022-01-06 13:03:26 +01:00
{
public $hookName = "alerte_intrusion";
public $active = true;
2022-01-17 00:18:50 +01:00
protected $devicelist = array(
ENTREE_PORTE => "contact",
GARAGE_PORTE => "contact",
RDC_CHAMBRE_BAIE => "contact",
2022-07-30 22:08:02 +02:00
RDC_SALON_BAIE => "contact",
GARAGE_PORTAIL => "contact",
ETAGE_SALON_FENETRE => "contact",
ETAGE_CUISINE_FENETRE => "contact",
ETAGE_PORTE_FENETRE => "contact"
);
2022-01-06 13:03:26 +01:00
function installHooks(&$indexDevices)
{
return $this->installHooksFunction($indexDevices);
}
2022-01-06 13:03:26 +01:00
// callback fonction. Is called with these 4 parameters
public function callBack($device, $property, $value)
2022-01-06 13:03:26 +01:00
{
logger(DEBUG, sprintf(_("property=%s, value=%s"), $property, $value), __FILE__ . ":" . __LINE__);
switch($property)
2022-01-06 13:03:26 +01:00
{
case "contact":
2022-09-01 17:02:28 +02:00
if (isPresent() === false)
2022-01-06 13:03:26 +01:00
{
2022-09-01 17:02:28 +02:00
if ($value == false and isPresent() === false)
{
2022-09-05 13:47:41 +02:00
logger(ALERT, sprintf(_("%s vient de s'ouvrir alors que personne n'est présent"), $device->friendlyName), __FILE__ . ":" . __LINE__, $device);
2022-09-01 17:02:28 +02:00
}else
{
2022-09-05 13:47:41 +02:00
logger(ALERT, sprintf(_("%s vient de se fermer alors que personne n'est présent"), $device->friendlyName), __FILE__ . ":" . __LINE__, $device);
2022-09-01 17:02:28 +02:00
}
2022-01-06 13:03:26 +01:00
}
break;
2022-01-06 13:03:26 +01:00
}
}
2022-07-10 13:57:38 +02:00
2022-09-02 17:59:33 +02:00
/* public function testPortes($deviceList=false, $send=true, $opened=true) :array
2022-07-10 13:57:38 +02:00
{
global $indexDevices;
2022-08-27 00:02:24 +02:00
$portes = array();
2022-08-28 23:44:21 +02:00
logger(DEBUG, _("Function alerte_intrusion->testPorte"), __FILE__ . ":" . __LINE__);
2022-08-28 23:44:21 +02:00
if ($deviceList === false) $deviceList = $this->deviceList;
2022-07-10 13:57:38 +02:00
$msg = "";
2022-08-28 23:44:21 +02:00
foreach ($deviceList as $device => $property)
2022-07-10 13:57:38 +02:00
{
2022-08-28 23:44:21 +02:00
//echo "device: " . $device . "\n";
//echo "opened = " . bool2string($opened);
//echo " value = " . var_dump($indexDevices[$device]->properties[$property]);
if ($opened)
2022-07-10 13:57:38 +02:00
{
2022-08-28 23:44:21 +02:00
if($indexDevices[$device]->properties[$property]["value"] === false)
{
2022-08-28 23:44:21 +02:00
//echo "porte opened";
$portes[] = $indexDevices[$device]->friendlyName;
$msg .= $indexDevices[$device]->friendlyName . "\n";
}
}else
{
2022-08-28 23:44:21 +02:00
if($indexDevices[$device]->properties[$property]["value"] === true)
{
2022-08-28 23:44:21 +02:00
//echo "porte closed";
$portes[] = $indexDevices[$device]->friendlyName;
$msg .= $indexDevices[$device]->friendlyName . "\n";
}
2022-07-10 13:57:38 +02:00
}
}
2022-08-27 00:02:24 +02:00
if ($send)
2022-07-10 13:57:38 +02:00
{
2022-08-27 00:02:24 +02:00
logger(ALERT, _("doors opened :") . $msg, null ,$device);
2022-07-10 13:57:38 +02:00
}
2022-08-27 00:02:24 +02:00
return $portes;
2022-09-02 17:59:33 +02:00
}*/
2022-01-06 13:03:26 +01:00
}
$hooks["alerte_intrusion"] = new alerte_intrusion();
logger(DEBUG, _("Initializing event"), __FILE__ . ":" . __LINE__);
2022-09-02 17:59:33 +02:00
//$function = array($hooks["testPortes"], "testPortes");
2022-09-01 17:02:28 +02:00
//setRecurrentEvent("alerte_intrusion", $function, "", "", 0, -1, "", "", false, 21);
2022-01-06 13:03:26 +01:00
?>